@abacus-ai/cli 1.106.25007 → 2.0.0-canary.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/.oxlintrc.json +8 -0
- package/dist/index.mjs +12603 -0
- package/package.json +7 -39
- package/resources/abacus.ico +0 -0
- package/resources/entitlements.plist +9 -0
- package/src/__e2e__/README.md +196 -0
- package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
- package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
- package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
- package/src/__e2e__/conversation.e2e.test.tsx +56 -0
- package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
- package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
- package/src/__e2e__/helpers/test-helpers.ts +450 -0
- package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
- package/src/__e2e__/llm-models.e2e.test.ts +402 -0
- package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
- package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
- package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
- package/src/__e2e__/repl.e2e.test.tsx +78 -0
- package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
- package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
- package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
- package/src/args.ts +22 -0
- package/src/components/__tests__/react-compiler.test.tsx +78 -0
- package/src/components/__tests__/status-indicator.test.tsx +403 -0
- package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
- package/src/components/composer/agent-mode-indicator.tsx +63 -0
- package/src/components/composer/bash-runner.tsx +54 -0
- package/src/components/composer/commands/default-commands.tsx +615 -0
- package/src/components/composer/commands/handler.tsx +59 -0
- package/src/components/composer/commands/picker.tsx +273 -0
- package/src/components/composer/commands/registry.ts +233 -0
- package/src/components/composer/commands/types.ts +33 -0
- package/src/components/composer/context.tsx +88 -0
- package/src/components/composer/file-mention-picker.tsx +83 -0
- package/src/components/composer/help.tsx +44 -0
- package/src/components/composer/index.tsx +1006 -0
- package/src/components/composer/mentions.ts +57 -0
- package/src/components/composer/message-queue.tsx +70 -0
- package/src/components/composer/mode-panel.tsx +35 -0
- package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
- package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
- package/src/components/composer/modes/bash-handler.tsx +132 -0
- package/src/components/composer/modes/bash-renderer.tsx +175 -0
- package/src/components/composer/modes/default-handlers.tsx +33 -0
- package/src/components/composer/modes/index.ts +41 -0
- package/src/components/composer/modes/types.ts +21 -0
- package/src/components/composer/persistent-shell.ts +283 -0
- package/src/components/composer/process.ts +65 -0
- package/src/components/composer/types.ts +9 -0
- package/src/components/composer/use-mention-search.ts +68 -0
- package/src/components/error-boundry.tsx +60 -0
- package/src/components/exit-message.tsx +29 -0
- package/src/components/expanded-view.tsx +74 -0
- package/src/components/file-completion.tsx +127 -0
- package/src/components/header.tsx +47 -0
- package/src/components/logo.tsx +37 -0
- package/src/components/segments.tsx +356 -0
- package/src/components/status-indicator.tsx +306 -0
- package/src/components/tool-group-summary.tsx +263 -0
- package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +312 -0
- package/src/components/tool-permissions/diff-preview.tsx +355 -0
- package/src/components/tool-permissions/index.ts +5 -0
- package/src/components/tool-permissions/permission-options.tsx +375 -0
- package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
- package/src/components/tool-permissions/tool-permission-ui.tsx +398 -0
- package/src/components/tools/agent/ask-user-question.tsx +101 -0
- package/src/components/tools/agent/enter-plan-mode.tsx +49 -0
- package/src/components/tools/agent/exit-plan-mode.tsx +75 -0
- package/src/components/tools/agent/handoff-to-main.tsx +27 -0
- package/src/components/tools/agent/subagent.tsx +37 -0
- package/src/components/tools/agent/todo-write.tsx +104 -0
- package/src/components/tools/browser/close-tab.tsx +58 -0
- package/src/components/tools/browser/computer.tsx +70 -0
- package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
- package/src/components/tools/browser/get-tab-content.tsx +51 -0
- package/src/components/tools/browser/navigate-to.tsx +59 -0
- package/src/components/tools/browser/new-tab.tsx +60 -0
- package/src/components/tools/browser/perform-action.tsx +63 -0
- package/src/components/tools/browser/refresh-tab.tsx +43 -0
- package/src/components/tools/browser/switch-tab.tsx +58 -0
- package/src/components/tools/filesystem/delete-file.tsx +104 -0
- package/src/components/tools/filesystem/edit.tsx +220 -0
- package/src/components/tools/filesystem/list-dir.tsx +78 -0
- package/src/components/tools/filesystem/read-file.tsx +180 -0
- package/src/components/tools/filesystem/upload-image.tsx +76 -0
- package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
- package/src/components/tools/index.ts +91 -0
- package/src/components/tools/mcp/mcp-tool.tsx +158 -0
- package/src/components/tools/search/fetch-url.tsx +73 -0
- package/src/components/tools/search/file-search.tsx +78 -0
- package/src/components/tools/search/grep.tsx +90 -0
- package/src/components/tools/search/semantic-search.tsx +66 -0
- package/src/components/tools/search/web-search.tsx +71 -0
- package/src/components/tools/shared/index.tsx +48 -0
- package/src/components/tools/shared/zod-coercion.ts +35 -0
- package/src/components/tools/terminal/bash-tool-output.tsx +174 -0
- package/src/components/tools/terminal/get-terminal-output.tsx +85 -0
- package/src/components/tools/terminal/run-in-terminal.tsx +106 -0
- package/src/components/tools/types.ts +16 -0
- package/src/components/tools.tsx +66 -0
- package/src/components/ui/__tests__/divider.test.tsx +61 -0
- package/src/components/ui/__tests__/gradient.test.tsx +125 -0
- package/src/components/ui/__tests__/input.test.tsx +166 -0
- package/src/components/ui/__tests__/select.test.tsx +273 -0
- package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
- package/src/components/ui/blinking-indicator.tsx +25 -0
- package/src/components/ui/divider.tsx +162 -0
- package/src/components/ui/gradient.tsx +56 -0
- package/src/components/ui/input.tsx +228 -0
- package/src/components/ui/select.tsx +151 -0
- package/src/components/ui/shimmer.tsx +84 -0
- package/src/context/agent-mode.tsx +95 -0
- package/src/context/extension-file.tsx +136 -0
- package/src/context/network-activity.tsx +45 -0
- package/src/context/notification.tsx +62 -0
- package/src/context/shell-size.tsx +49 -0
- package/src/context/shell-title.tsx +38 -0
- package/src/entrypoints/print-mode.ts +312 -0
- package/src/entrypoints/repl.tsx +401 -0
- package/src/hooks/use-agent.ts +15 -0
- package/src/hooks/use-api-client.ts +1 -0
- package/src/hooks/use-available-height.ts +8 -0
- package/src/hooks/use-cleanup.ts +29 -0
- package/src/hooks/use-interrupt-manager.ts +242 -0
- package/src/hooks/use-models.ts +22 -0
- package/src/index.ts +217 -0
- package/src/lib/__tests__/ansi.test.ts +255 -0
- package/src/lib/__tests__/cli.test.ts +122 -0
- package/src/lib/__tests__/commands.test.ts +325 -0
- package/src/lib/__tests__/constants.test.ts +15 -0
- package/src/lib/__tests__/focusables.test.ts +25 -0
- package/src/lib/__tests__/fs.test.ts +231 -0
- package/src/lib/__tests__/markdown.test.tsx +348 -0
- package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
- package/src/lib/__tests__/mcpManagement.test.ts +38 -0
- package/src/lib/__tests__/path-paste.test.ts +144 -0
- package/src/lib/__tests__/path.test.ts +300 -0
- package/src/lib/__tests__/queries.test.ts +39 -0
- package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
- package/src/lib/__tests__/text-buffer.test.ts +328 -0
- package/src/lib/__tests__/text-utils.test.ts +32 -0
- package/src/lib/__tests__/timing.test.ts +78 -0
- package/src/lib/__tests__/utils.test.ts +238 -0
- package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
- package/src/lib/ansi.ts +150 -0
- package/src/lib/cli-push-server.ts +112 -0
- package/src/lib/cli.ts +44 -0
- package/src/lib/clipboard.ts +226 -0
- package/src/lib/command-utils.ts +93 -0
- package/src/lib/commands.ts +270 -0
- package/src/lib/constants.ts +3 -0
- package/src/lib/extension-connection.ts +181 -0
- package/src/lib/focusables.ts +7 -0
- package/src/lib/fs.ts +533 -0
- package/src/lib/markdown/code-block.tsx +63 -0
- package/src/lib/markdown/index.ts +4 -0
- package/src/lib/markdown/link.tsx +19 -0
- package/src/lib/markdown/markdown.tsx +372 -0
- package/src/lib/markdown/types.ts +15 -0
- package/src/lib/mcpCommandHandler.ts +121 -0
- package/src/lib/mcpManagement.ts +44 -0
- package/src/lib/path-paste.ts +185 -0
- package/src/lib/path.ts +179 -0
- package/src/lib/queries.ts +15 -0
- package/src/lib/standaloneMcpService.ts +688 -0
- package/src/lib/status-utils.ts +237 -0
- package/src/lib/test-utils.tsx +72 -0
- package/src/lib/text-buffer.ts +2415 -0
- package/src/lib/text-utils.ts +272 -0
- package/src/lib/timing.ts +63 -0
- package/src/lib/types.ts +295 -0
- package/src/lib/utils.ts +182 -0
- package/src/lib/vim-buffer-actions.ts +732 -0
- package/src/providers/agent.tsx +1075 -0
- package/src/providers/api-client.tsx +43 -0
- package/src/services/logger.ts +85 -0
- package/src/terminal/detection.ts +187 -0
- package/src/terminal/exit.ts +279 -0
- package/src/terminal/notification.ts +83 -0
- package/src/terminal/progress.ts +201 -0
- package/src/terminal/setup.ts +797 -0
- package/src/terminal/suspend.ts +58 -0
- package/src/terminal/types.ts +51 -0
- package/src/theme/context.tsx +57 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/themed.tsx +35 -0
- package/src/theme/themes.json +546 -0
- package/src/theme/types.ts +110 -0
- package/src/tools/types.ts +59 -0
- package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
- package/src/tools/utils/tool-ui-components.tsx +631 -0
- package/src/tools/utils/zod-coercion.ts +35 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +29 -0
- package/tsconfig.test.json +27 -0
- package/tsdown.config.ts +17 -0
- package/vitest.config.ts +76 -0
- package/README.md +0 -28
- package/dist/index.js +0 -26
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { View, Text } from "@codellm/jar";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
|
|
4
|
+
import type { HistorySegment } from "../lib/types.js";
|
|
5
|
+
|
|
6
|
+
import { useTheme } from "../theme/index.js";
|
|
7
|
+
import { toolMap } from "./tools/index.js";
|
|
8
|
+
import { BlinkingDot } from "./tools/shared/index.js";
|
|
9
|
+
|
|
10
|
+
/** Tools that are collapsed into summary lines; everything else renders individually */
|
|
11
|
+
export const GROUPABLE_TOOLS = new Set([
|
|
12
|
+
"read_file",
|
|
13
|
+
"list_dir",
|
|
14
|
+
"grep",
|
|
15
|
+
"file_search",
|
|
16
|
+
"semantic_search_server",
|
|
17
|
+
"web_search",
|
|
18
|
+
"fetch_url",
|
|
19
|
+
"get_tab_content",
|
|
20
|
+
"get_terminal_output",
|
|
21
|
+
"get_interactive_elements",
|
|
22
|
+
"navigate_to",
|
|
23
|
+
"new_tab",
|
|
24
|
+
"switch_active_tab",
|
|
25
|
+
"close_tab",
|
|
26
|
+
"refresh_tab",
|
|
27
|
+
"get_diagnostics",
|
|
28
|
+
"upload_image",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export function getToolName(seg: HistorySegment): string {
|
|
32
|
+
const req = seg.toolUseRequest;
|
|
33
|
+
if (!req) return "";
|
|
34
|
+
if (Array.isArray(req)) return (req[0] as { name?: string })?.name ?? "";
|
|
35
|
+
return (req as { name?: string }).name ?? "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getToolInput(seg: HistorySegment): Record<string, unknown> {
|
|
39
|
+
const req = seg.toolUseRequest;
|
|
40
|
+
if (!req) return {};
|
|
41
|
+
if (Array.isArray(req)) return (req[0] as { input?: Record<string, unknown> })?.input ?? {};
|
|
42
|
+
return (req as { input?: Record<string, unknown> }).input ?? {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Get the display params for a tool (e.g. file path, pattern) */
|
|
46
|
+
function getActiveToolParams(seg: HistorySegment): string {
|
|
47
|
+
const name = getToolName(seg);
|
|
48
|
+
const input = getToolInput(seg);
|
|
49
|
+
const def = toolMap[name];
|
|
50
|
+
if (!def) return "";
|
|
51
|
+
try {
|
|
52
|
+
return def.getHeaderParams(input);
|
|
53
|
+
} catch {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Category =
|
|
59
|
+
| "read"
|
|
60
|
+
| "list"
|
|
61
|
+
| "search"
|
|
62
|
+
| "web"
|
|
63
|
+
| "fetch"
|
|
64
|
+
| "browser"
|
|
65
|
+
| "terminal"
|
|
66
|
+
| "diag"
|
|
67
|
+
| "other";
|
|
68
|
+
|
|
69
|
+
function categorize(toolName: string): Category {
|
|
70
|
+
switch (toolName) {
|
|
71
|
+
case "read_file":
|
|
72
|
+
return "read";
|
|
73
|
+
case "list_dir":
|
|
74
|
+
return "list";
|
|
75
|
+
case "grep":
|
|
76
|
+
case "file_search":
|
|
77
|
+
case "semantic_search_server":
|
|
78
|
+
return "search";
|
|
79
|
+
case "web_search":
|
|
80
|
+
return "web";
|
|
81
|
+
case "fetch_url":
|
|
82
|
+
return "fetch";
|
|
83
|
+
case "navigate_to":
|
|
84
|
+
case "new_tab":
|
|
85
|
+
case "switch_active_tab":
|
|
86
|
+
case "close_tab":
|
|
87
|
+
case "refresh_tab":
|
|
88
|
+
case "get_tab_content":
|
|
89
|
+
case "get_interactive_elements":
|
|
90
|
+
return "browser";
|
|
91
|
+
case "get_terminal_output":
|
|
92
|
+
return "terminal";
|
|
93
|
+
case "get_diagnostics":
|
|
94
|
+
return "diag";
|
|
95
|
+
default:
|
|
96
|
+
return "other";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface CategoryCount {
|
|
101
|
+
completed: number;
|
|
102
|
+
executing: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Build summary string. Completed counts use past tense; executing count appended as progressive. */
|
|
106
|
+
function buildSummary(counts: Partial<Record<Category, CategoryCount>>): string {
|
|
107
|
+
const parts: string[] = [];
|
|
108
|
+
|
|
109
|
+
function fmtCategory(cat: Category, completed: number, executing: number): void {
|
|
110
|
+
const total = completed + executing;
|
|
111
|
+
if (total === 0) return;
|
|
112
|
+
|
|
113
|
+
let phrase: string;
|
|
114
|
+
if (executing > 0) {
|
|
115
|
+
// Progressive form for the executing portion
|
|
116
|
+
switch (cat) {
|
|
117
|
+
case "search":
|
|
118
|
+
phrase = total === 1 ? "searching for 1 pattern" : `searching for ${total} patterns`;
|
|
119
|
+
break;
|
|
120
|
+
case "read":
|
|
121
|
+
phrase = total === 1 ? "reading 1 file" : `reading ${total} files`;
|
|
122
|
+
break;
|
|
123
|
+
case "list":
|
|
124
|
+
phrase = total === 1 ? "listing 1 directory" : `listing ${total} directories`;
|
|
125
|
+
break;
|
|
126
|
+
case "web":
|
|
127
|
+
phrase = total === 1 ? "searching the web" : `searching the web ${total} times`;
|
|
128
|
+
break;
|
|
129
|
+
case "fetch":
|
|
130
|
+
phrase = total === 1 ? "fetching 1 URL" : `fetching ${total} URLs`;
|
|
131
|
+
break;
|
|
132
|
+
case "browser":
|
|
133
|
+
phrase = total === 1 ? "navigating browser" : `navigating browser ${total} times`;
|
|
134
|
+
break;
|
|
135
|
+
case "terminal":
|
|
136
|
+
phrase = "getting terminal output";
|
|
137
|
+
break;
|
|
138
|
+
case "diag":
|
|
139
|
+
phrase = "checking diagnostics";
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
phrase = total === 1 ? "1 operation" : `${total} operations`;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
// Past tense for all completed
|
|
147
|
+
switch (cat) {
|
|
148
|
+
case "search":
|
|
149
|
+
phrase =
|
|
150
|
+
completed === 1 ? "searched for 1 pattern" : `searched for ${completed} patterns`;
|
|
151
|
+
break;
|
|
152
|
+
case "read":
|
|
153
|
+
phrase = completed === 1 ? "read 1 file" : `read ${completed} files`;
|
|
154
|
+
break;
|
|
155
|
+
case "list":
|
|
156
|
+
phrase = completed === 1 ? "listed 1 directory" : `listed ${completed} directories`;
|
|
157
|
+
break;
|
|
158
|
+
case "web":
|
|
159
|
+
phrase = completed === 1 ? "searched the web" : `searched the web ${completed} times`;
|
|
160
|
+
break;
|
|
161
|
+
case "fetch":
|
|
162
|
+
phrase = completed === 1 ? "fetched 1 URL" : `fetched ${completed} URLs`;
|
|
163
|
+
break;
|
|
164
|
+
case "browser":
|
|
165
|
+
phrase = completed === 1 ? "navigated browser" : `navigated browser ${completed} times`;
|
|
166
|
+
break;
|
|
167
|
+
case "terminal":
|
|
168
|
+
phrase = "got terminal output";
|
|
169
|
+
break;
|
|
170
|
+
case "diag":
|
|
171
|
+
phrase = "checked diagnostics";
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
phrase = completed === 1 ? "1 operation" : `${completed} operations`;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
parts.push(phrase);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Render in a consistent order
|
|
182
|
+
const order: Category[] = [
|
|
183
|
+
"search",
|
|
184
|
+
"read",
|
|
185
|
+
"list",
|
|
186
|
+
"web",
|
|
187
|
+
"fetch",
|
|
188
|
+
"browser",
|
|
189
|
+
"terminal",
|
|
190
|
+
"diag",
|
|
191
|
+
"other",
|
|
192
|
+
];
|
|
193
|
+
for (const cat of order) {
|
|
194
|
+
const c = counts[cat];
|
|
195
|
+
if (c) fmtCategory(cat, c.completed, c.executing);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return parts.join(", ");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface ToolGroupSummaryProps {
|
|
202
|
+
segments: HistorySegment[];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const ToolGroupSummary = memo(({ segments }: ToolGroupSummaryProps) => {
|
|
206
|
+
const { colors } = useTheme();
|
|
207
|
+
|
|
208
|
+
const counts: Partial<Record<Category, CategoryCount>> = {};
|
|
209
|
+
let activeSeg: HistorySegment | null = null;
|
|
210
|
+
let hasExecuting = false;
|
|
211
|
+
let hasError = false;
|
|
212
|
+
|
|
213
|
+
for (const seg of segments) {
|
|
214
|
+
const name = getToolName(seg);
|
|
215
|
+
const cat = categorize(name);
|
|
216
|
+
const isExecuting = !seg.toolUseResult;
|
|
217
|
+
|
|
218
|
+
if (!counts[cat]) counts[cat] = { completed: 0, executing: 0 };
|
|
219
|
+
if (isExecuting) {
|
|
220
|
+
counts[cat]!.executing++;
|
|
221
|
+
activeSeg = seg;
|
|
222
|
+
hasExecuting = true;
|
|
223
|
+
} else {
|
|
224
|
+
counts[cat]!.completed++;
|
|
225
|
+
// Detect error: rejected flag or content starting with "Error:"
|
|
226
|
+
const result = seg.toolUseResult as { rejected?: boolean; content?: string } | undefined;
|
|
227
|
+
if (result?.rejected || result?.content?.startsWith("Error:")) {
|
|
228
|
+
hasError = true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const rawSummary = buildSummary(counts);
|
|
234
|
+
const summary = rawSummary.charAt(0).toUpperCase() + rawSummary.slice(1);
|
|
235
|
+
const activeParams = activeSeg ? getActiveToolParams(activeSeg) : null;
|
|
236
|
+
|
|
237
|
+
// Dot color: executing → blinking (white), error → red, all success → green
|
|
238
|
+
const dotColor = hasError ? "red" : !hasExecuting ? "green" : "white";
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<View flexDirection="column">
|
|
242
|
+
<View flexDirection="row" gap={1} alignItems="center">
|
|
243
|
+
{hasExecuting ? <BlinkingDot /> : <Text color={dotColor}>⏺</Text>}
|
|
244
|
+
<Text>
|
|
245
|
+
{summary}
|
|
246
|
+
{hasExecuting ? "…" : ""}
|
|
247
|
+
</Text>
|
|
248
|
+
<Text color={colors.textMuted} dimColor>
|
|
249
|
+
(ctrl+o to expand)
|
|
250
|
+
</Text>
|
|
251
|
+
</View>
|
|
252
|
+
{activeParams && (
|
|
253
|
+
<View flexDirection="row" paddingLeft={2}>
|
|
254
|
+
<Text color={colors.textSubtle} dimColor>
|
|
255
|
+
⎿{" "}
|
|
256
|
+
</Text>
|
|
257
|
+
<Text color={colors.textSubtle}>{activeParams}</Text>
|
|
258
|
+
</View>
|
|
259
|
+
)}
|
|
260
|
+
</View>
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
ToolGroupSummary.displayName = "ToolGroupSummary";
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import type { AskUserQuestionItem, PermissionDecision } from "@codellm/agent";
|
|
2
|
+
|
|
3
|
+
import { View, Text } from "@codellm/jar";
|
|
4
|
+
import { type Key, useInput } from "@codellm/jar";
|
|
5
|
+
import { memo, useCallback, useRef, useState } from "react";
|
|
6
|
+
|
|
7
|
+
import { TextBuffer } from "../../lib/text-buffer.js";
|
|
8
|
+
import { Input, type InputKeyDownEvent } from "../ui/input.js";
|
|
9
|
+
import { PermissionPreviewHeader, dashedBorderStyle } from "./permission-preview-header.js";
|
|
10
|
+
|
|
11
|
+
interface AskUserQuestionPermissionUIProps {
|
|
12
|
+
questions: AskUserQuestionItem[];
|
|
13
|
+
onResolve: (decision: PermissionDecision) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const AskUserQuestionPermissionUI = memo(
|
|
17
|
+
({ questions, onResolve }: AskUserQuestionPermissionUIProps) => {
|
|
18
|
+
const [questionIndex, setQuestionIndex] = useState(0);
|
|
19
|
+
const [optionIndex, setOptionIndex] = useState(0);
|
|
20
|
+
// selected: Map from questionIndex → Set of selected option indices
|
|
21
|
+
const [selected, setSelected] = useState<Map<number, Set<number>>>(() => new Map());
|
|
22
|
+
const [noteMode, setNoteMode] = useState(false);
|
|
23
|
+
// notes per question
|
|
24
|
+
const [notes, setNotes] = useState<Map<number, string>>(() => new Map());
|
|
25
|
+
const noteBufferRef = useRef<TextBuffer | null>(null);
|
|
26
|
+
|
|
27
|
+
const currentQuestion = questions[questionIndex];
|
|
28
|
+
const currentSelected = selected.get(questionIndex) ?? new Set<number>();
|
|
29
|
+
|
|
30
|
+
const optionIndexRef = useRef(optionIndex);
|
|
31
|
+
optionIndexRef.current = optionIndex;
|
|
32
|
+
const questionIndexRef = useRef(questionIndex);
|
|
33
|
+
questionIndexRef.current = questionIndex;
|
|
34
|
+
const noteModeRef = useRef(noteMode);
|
|
35
|
+
noteModeRef.current = noteMode;
|
|
36
|
+
const questionsRef = useRef(questions);
|
|
37
|
+
questionsRef.current = questions;
|
|
38
|
+
const selectedRef = useRef(selected);
|
|
39
|
+
selectedRef.current = selected;
|
|
40
|
+
const notesRef = useRef(notes);
|
|
41
|
+
notesRef.current = notes;
|
|
42
|
+
|
|
43
|
+
const buildAnswers = useCallback(
|
|
44
|
+
(finalSelected: Map<number, Set<number>>, finalNotes: Map<number, string>) => {
|
|
45
|
+
const answers: Record<string, string> = {};
|
|
46
|
+
for (let i = 0; i < questionsRef.current.length; i++) {
|
|
47
|
+
const q = questionsRef.current[i];
|
|
48
|
+
if (!q) continue;
|
|
49
|
+
const sel = finalSelected.get(i);
|
|
50
|
+
if (!sel || sel.size === 0) continue;
|
|
51
|
+
const chosen = [...sel]
|
|
52
|
+
.sort((a, b) => a - b)
|
|
53
|
+
.map((idx) => q.options[idx]?.label ?? "")
|
|
54
|
+
.filter(Boolean);
|
|
55
|
+
const note = finalNotes.get(i);
|
|
56
|
+
answers[`question_${i}`] = note ? `${chosen.join(", ")} — ${note}` : chosen.join(", ");
|
|
57
|
+
}
|
|
58
|
+
return answers;
|
|
59
|
+
},
|
|
60
|
+
[],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const submit = useCallback(
|
|
64
|
+
(finalSelected: Map<number, Set<number>>, finalNotes: Map<number, string>) => {
|
|
65
|
+
onResolve({
|
|
66
|
+
type: "question_answers",
|
|
67
|
+
answers: buildAnswers(finalSelected, finalNotes),
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
[onResolve, buildAnswers],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const advanceOrSubmit = useCallback(
|
|
74
|
+
(
|
|
75
|
+
nextQIndex: number,
|
|
76
|
+
latestSelected: Map<number, Set<number>>,
|
|
77
|
+
latestNotes: Map<number, string>,
|
|
78
|
+
) => {
|
|
79
|
+
if (nextQIndex >= questionsRef.current.length) {
|
|
80
|
+
submit(latestSelected, latestNotes);
|
|
81
|
+
} else {
|
|
82
|
+
setQuestionIndex(nextQIndex);
|
|
83
|
+
setOptionIndex(0);
|
|
84
|
+
setNoteMode(false);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
[submit],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Confirm current question and move to next (or submit)
|
|
91
|
+
const confirmCurrent = useCallback(() => {
|
|
92
|
+
const qi = questionIndexRef.current;
|
|
93
|
+
const q = questionsRef.current[qi];
|
|
94
|
+
if (!q) return;
|
|
95
|
+
// If nothing selected, treat as skip for this question (no answer recorded)
|
|
96
|
+
const latestSelected = selectedRef.current;
|
|
97
|
+
const latestNotes = notesRef.current;
|
|
98
|
+
advanceOrSubmit(qi + 1, latestSelected, latestNotes);
|
|
99
|
+
}, [advanceOrSubmit]);
|
|
100
|
+
|
|
101
|
+
const confirmCurrentRef = useRef(confirmCurrent);
|
|
102
|
+
confirmCurrentRef.current = confirmCurrent;
|
|
103
|
+
|
|
104
|
+
const handleNoteKeyDown = useCallback((event: InputKeyDownEvent) => {
|
|
105
|
+
if (event.key.return) {
|
|
106
|
+
const text = noteBufferRef.current?.text?.trim() ?? "";
|
|
107
|
+
const qi = questionIndexRef.current;
|
|
108
|
+
const newNotes = new Map(notesRef.current);
|
|
109
|
+
if (text) newNotes.set(qi, text);
|
|
110
|
+
else newNotes.delete(qi);
|
|
111
|
+
setNotes(newNotes);
|
|
112
|
+
setNoteMode(false);
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (event.key.escape) {
|
|
117
|
+
setNoteMode(false);
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (event.key.tab) {
|
|
122
|
+
// Tab in note mode exits note mode
|
|
123
|
+
setNoteMode(false);
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
const handleNoteSubmit = useCallback((value: string) => {
|
|
130
|
+
const qi = questionIndexRef.current;
|
|
131
|
+
const newNotes = new Map(notesRef.current);
|
|
132
|
+
const text = value.trim();
|
|
133
|
+
if (text) newNotes.set(qi, text);
|
|
134
|
+
else newNotes.delete(qi);
|
|
135
|
+
setNotes(newNotes);
|
|
136
|
+
setNoteMode(false);
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
const keypressHandler = useCallback(
|
|
140
|
+
(_input: string, key: Key) => {
|
|
141
|
+
if (noteModeRef.current) return;
|
|
142
|
+
|
|
143
|
+
const qi = questionIndexRef.current;
|
|
144
|
+
const q = questionsRef.current[qi];
|
|
145
|
+
if (!q) return;
|
|
146
|
+
const numOptions = q.options.length;
|
|
147
|
+
|
|
148
|
+
if (key.upArrow) {
|
|
149
|
+
setOptionIndex((prev) => Math.max(0, prev - 1));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (key.downArrow) {
|
|
153
|
+
setOptionIndex((prev) => Math.min(numOptions - 1, prev + 1));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (key.leftArrow) {
|
|
157
|
+
// Navigate to previous question
|
|
158
|
+
if (qi > 0) {
|
|
159
|
+
setQuestionIndex(qi - 1);
|
|
160
|
+
setOptionIndex(0);
|
|
161
|
+
setNoteMode(false);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (key.rightArrow) {
|
|
166
|
+
// Navigate to next question (only if we've been there)
|
|
167
|
+
if (qi < questionsRef.current.length - 1) {
|
|
168
|
+
setQuestionIndex(qi + 1);
|
|
169
|
+
setOptionIndex(0);
|
|
170
|
+
setNoteMode(false);
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (_input === " ") {
|
|
175
|
+
const oi = optionIndexRef.current;
|
|
176
|
+
const newSelected = new Map(selectedRef.current);
|
|
177
|
+
const sel = new Set(newSelected.get(qi) ?? []);
|
|
178
|
+
if (q.multiSelect) {
|
|
179
|
+
if (sel.has(oi)) sel.delete(oi);
|
|
180
|
+
else sel.add(oi);
|
|
181
|
+
} else {
|
|
182
|
+
sel.clear();
|
|
183
|
+
sel.add(oi);
|
|
184
|
+
}
|
|
185
|
+
newSelected.set(qi, sel);
|
|
186
|
+
setSelected(newSelected);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (key.return) {
|
|
190
|
+
// If nothing selected yet for single-select, select current option first
|
|
191
|
+
const sel = selectedRef.current.get(qi) ?? new Set<number>();
|
|
192
|
+
if (sel.size === 0 && !q.multiSelect) {
|
|
193
|
+
const oi = optionIndexRef.current;
|
|
194
|
+
const newSelected = new Map(selectedRef.current);
|
|
195
|
+
const newSel = new Set([oi]);
|
|
196
|
+
newSelected.set(qi, newSel);
|
|
197
|
+
setSelected(newSelected);
|
|
198
|
+
advanceOrSubmit(qi + 1, newSelected, notesRef.current);
|
|
199
|
+
} else {
|
|
200
|
+
confirmCurrentRef.current();
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (key.tab) {
|
|
205
|
+
setNoteMode(true);
|
|
206
|
+
// Pre-fill with existing note if any
|
|
207
|
+
setTimeout(() => {
|
|
208
|
+
const existingNote = notesRef.current.get(qi) ?? "";
|
|
209
|
+
if (noteBufferRef.current && existingNote) {
|
|
210
|
+
noteBufferRef.current.setText(existingNote);
|
|
211
|
+
}
|
|
212
|
+
}, 0);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (key.escape) {
|
|
216
|
+
// Skip remaining questions and submit what we have
|
|
217
|
+
submit(selectedRef.current, notesRef.current);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
[advanceOrSubmit, submit],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
useInput(keypressHandler, { isActive: !noteMode });
|
|
225
|
+
|
|
226
|
+
if (!currentQuestion) return null;
|
|
227
|
+
|
|
228
|
+
const note = notes.get(questionIndex);
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<View flexDirection="column">
|
|
232
|
+
<PermissionPreviewHeader
|
|
233
|
+
title={`Questions (${questionIndex + 1}/${questions.length}): ${currentQuestion.header}`}
|
|
234
|
+
/>
|
|
235
|
+
<View flexDirection="column" paddingLeft={1} paddingY={1}>
|
|
236
|
+
<Text>{currentQuestion.question}</Text>
|
|
237
|
+
</View>
|
|
238
|
+
<View flexDirection="column" paddingLeft={1}>
|
|
239
|
+
{currentQuestion.options.map(
|
|
240
|
+
(opt: { label: string; description: string }, idx: number) => {
|
|
241
|
+
const isHighlighted = idx === optionIndex;
|
|
242
|
+
const isSel = currentSelected.has(idx);
|
|
243
|
+
const checkbox = currentQuestion.multiSelect
|
|
244
|
+
? isSel
|
|
245
|
+
? "[x] "
|
|
246
|
+
: "[ ] "
|
|
247
|
+
: isSel
|
|
248
|
+
? "◉ "
|
|
249
|
+
: "○ ";
|
|
250
|
+
return (
|
|
251
|
+
<View key={idx} flexDirection="row">
|
|
252
|
+
<Text color={isHighlighted ? "cyan" : undefined}>
|
|
253
|
+
{isHighlighted ? "❯ " : " "}
|
|
254
|
+
</Text>
|
|
255
|
+
<Text color={isSel ? "green" : isHighlighted ? undefined : "gray"}>
|
|
256
|
+
{checkbox}
|
|
257
|
+
{opt.label}
|
|
258
|
+
</Text>
|
|
259
|
+
{opt.description ? <Text dimColor> — {opt.description}</Text> : null}
|
|
260
|
+
</View>
|
|
261
|
+
);
|
|
262
|
+
},
|
|
263
|
+
)}
|
|
264
|
+
</View>
|
|
265
|
+
|
|
266
|
+
{noteMode ? (
|
|
267
|
+
<View flexDirection="column" paddingLeft={1} paddingTop={1}>
|
|
268
|
+
<View flexDirection="row">
|
|
269
|
+
<Text color="cyan">{"❯ "}</Text>
|
|
270
|
+
<Text dimColor>Note: </Text>
|
|
271
|
+
<Input
|
|
272
|
+
ref={noteBufferRef}
|
|
273
|
+
placeholder="Add context or instructions…"
|
|
274
|
+
onSubmit={handleNoteSubmit}
|
|
275
|
+
onKeyDown={handleNoteKeyDown}
|
|
276
|
+
/>
|
|
277
|
+
</View>
|
|
278
|
+
</View>
|
|
279
|
+
) : (
|
|
280
|
+
<View flexDirection="column" paddingLeft={1} paddingTop={1}>
|
|
281
|
+
{note && (
|
|
282
|
+
<Text dimColor>
|
|
283
|
+
Note: <Text italic>{note}</Text>
|
|
284
|
+
</Text>
|
|
285
|
+
)}
|
|
286
|
+
</View>
|
|
287
|
+
)}
|
|
288
|
+
|
|
289
|
+
<View
|
|
290
|
+
borderStyle={dashedBorderStyle}
|
|
291
|
+
borderBottom
|
|
292
|
+
borderTop={false}
|
|
293
|
+
borderLeft={false}
|
|
294
|
+
borderRight={false}
|
|
295
|
+
/>
|
|
296
|
+
<View flexDirection="row" paddingLeft={1} paddingBottom={1} gap={2}>
|
|
297
|
+
<Text dimColor>↑↓ option</Text>
|
|
298
|
+
<Text dimColor>space select</Text>
|
|
299
|
+
<Text dimColor>enter confirm</Text>
|
|
300
|
+
{questions.length > 1 && (
|
|
301
|
+
<>
|
|
302
|
+
<Text dimColor>←→ navigate</Text>
|
|
303
|
+
</>
|
|
304
|
+
)}
|
|
305
|
+
<Text dimColor>tab note</Text>
|
|
306
|
+
<Text dimColor>esc skip</Text>
|
|
307
|
+
</View>
|
|
308
|
+
</View>
|
|
309
|
+
);
|
|
310
|
+
},
|
|
311
|
+
);
|
|
312
|
+
AskUserQuestionPermissionUI.displayName = "AskUserQuestionPermissionUI";
|