@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,401 @@
|
|
|
1
|
+
import type { AbacusClient } from "@codellm/api";
|
|
2
|
+
|
|
3
|
+
import { AuthManager } from "@codellm/auth";
|
|
4
|
+
import { View, render, Text, useInput } from "@codellm/jar";
|
|
5
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
6
|
+
import {
|
|
7
|
+
Activity,
|
|
8
|
+
useEffect,
|
|
9
|
+
useState,
|
|
10
|
+
useDeferredValue,
|
|
11
|
+
useMemo,
|
|
12
|
+
useCallback,
|
|
13
|
+
useRef,
|
|
14
|
+
} from "react";
|
|
15
|
+
|
|
16
|
+
import type { AgentArgs } from "../args.js";
|
|
17
|
+
import type { HistorySegment } from "../lib/types.js";
|
|
18
|
+
|
|
19
|
+
import { Composer, type ComposerHandle } from "../components/composer/index.js";
|
|
20
|
+
import { AgentMode } from "../components/composer/types.js";
|
|
21
|
+
import { ExitMessage } from "../components/exit-message.js";
|
|
22
|
+
import { ExpandedView } from "../components/expanded-view.js";
|
|
23
|
+
import { Header } from "../components/header.js";
|
|
24
|
+
import { Segment } from "../components/segments.js";
|
|
25
|
+
import { StatusIndicator } from "../components/status-indicator.js";
|
|
26
|
+
import { GROUPABLE_TOOLS, ToolGroupSummary } from "../components/tool-group-summary.js";
|
|
27
|
+
import { ToolPermissionUI } from "../components/tool-permissions/tool-permission-ui.js";
|
|
28
|
+
import { PendingToolCallIdContext } from "../components/tools/shared/index.js";
|
|
29
|
+
import { AgentModeProvider } from "../context/agent-mode.js";
|
|
30
|
+
import { ExtensionFileProvider } from "../context/extension-file.js";
|
|
31
|
+
import { NetworkActivityProvider } from "../context/network-activity.js";
|
|
32
|
+
import { NotificationProvider } from "../context/notification.js";
|
|
33
|
+
import { ShellSizeProvider } from "../context/shell-size.js";
|
|
34
|
+
import { ShellTitleProvider, useShellTitle } from "../context/shell-title.js";
|
|
35
|
+
import { useAgent } from "../hooks/use-agent.js";
|
|
36
|
+
import { useApiClient } from "../hooks/use-api-client.js";
|
|
37
|
+
import { useInterruptManager } from "../hooks/use-interrupt-manager.js";
|
|
38
|
+
import { ANSI } from "../lib/ansi.js";
|
|
39
|
+
import { Timing } from "../lib/timing.js";
|
|
40
|
+
import { AgentProvider, AgentStatus } from "../providers/agent.js";
|
|
41
|
+
import { ApiClientProvider } from "../providers/api-client.js";
|
|
42
|
+
import { onExit, gracefulExit } from "../terminal/exit.js";
|
|
43
|
+
import { setupSuspendHandler } from "../terminal/suspend.js";
|
|
44
|
+
import { ThemeProvider } from "../theme/index.js";
|
|
45
|
+
|
|
46
|
+
/** Group consecutive "groupable" tool call segments together for compact rendering. */
|
|
47
|
+
type RenderItem =
|
|
48
|
+
| { kind: "segment"; segment: HistorySegment }
|
|
49
|
+
| { kind: "tool-group"; id: string; segments: HistorySegment[] };
|
|
50
|
+
|
|
51
|
+
function isToolSeg(seg: HistorySegment): boolean {
|
|
52
|
+
return seg.type === "code_llm_tool_call" || seg.type === "code_llm_agent_tool_request";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function hasToolError(seg: HistorySegment): boolean {
|
|
56
|
+
const result = seg.toolUseResult as { rejected?: boolean; content?: string } | undefined;
|
|
57
|
+
return !!(result?.rejected || result?.content?.startsWith("Error:"));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function groupSegments(segments: HistorySegment[]): RenderItem[] {
|
|
61
|
+
const items: RenderItem[] = [];
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < segments.length) {
|
|
64
|
+
const seg = segments[i];
|
|
65
|
+
|
|
66
|
+
// Thinking segments render inline (visible while active + 2s after completion)
|
|
67
|
+
if (seg.type === "thinking") {
|
|
68
|
+
items.push({ kind: "segment", segment: seg });
|
|
69
|
+
i++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (isToolSeg(seg) && GROUPABLE_TOOLS.has(getToolName(seg))) {
|
|
74
|
+
// Collect all consecutive groupable tool calls, treating thinking as transparent gaps
|
|
75
|
+
// Break the group at any completed tool that returned an error
|
|
76
|
+
const group: HistorySegment[] = [seg];
|
|
77
|
+
let j = i + 1;
|
|
78
|
+
while (j < segments.length) {
|
|
79
|
+
const next = segments[j];
|
|
80
|
+
if (next.type === "thinking") {
|
|
81
|
+
// Thinking between tool calls is transparent — skip without breaking the group
|
|
82
|
+
j++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// If the last tool in the group errored, start a new group from here
|
|
86
|
+
if (hasToolError(group[group.length - 1]!)) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (isToolSeg(next) && GROUPABLE_TOOLS.has(getToolName(next))) {
|
|
90
|
+
group.push(next);
|
|
91
|
+
j++;
|
|
92
|
+
} else {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (group.length === 1) {
|
|
97
|
+
items.push({ kind: "segment", segment: group[0] });
|
|
98
|
+
} else {
|
|
99
|
+
items.push({ kind: "tool-group", id: group[0].id, segments: group });
|
|
100
|
+
}
|
|
101
|
+
i = j;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
items.push({ kind: "segment", segment: seg });
|
|
106
|
+
i++;
|
|
107
|
+
}
|
|
108
|
+
return items;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getToolName(seg: HistorySegment): string {
|
|
112
|
+
const req = seg.toolUseRequest;
|
|
113
|
+
if (!req) return "";
|
|
114
|
+
if (Array.isArray(req)) return (req[0] as { name?: string })?.name ?? "";
|
|
115
|
+
return (req as { name?: string }).name ?? "";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Derive the most recent thinking timing from segments for the status indicator. */
|
|
119
|
+
function getThinkingTiming(segments: HistorySegment[]): {
|
|
120
|
+
thinkingStartTime: number | null;
|
|
121
|
+
thinkingEndTime: number | null;
|
|
122
|
+
} {
|
|
123
|
+
// Find the last thinking segment
|
|
124
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
125
|
+
const seg = segments[i];
|
|
126
|
+
if (seg.type === "thinking") {
|
|
127
|
+
return {
|
|
128
|
+
thinkingStartTime: seg.thinkingStartTime ?? null,
|
|
129
|
+
thinkingEndTime: seg.thinkingEndTime ?? null,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { thinkingStartTime: null, thinkingEndTime: null };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function App({ timing }: { timing: Timing }) {
|
|
137
|
+
const { setTitle } = useShellTitle();
|
|
138
|
+
|
|
139
|
+
const {
|
|
140
|
+
segments: rawSegments,
|
|
141
|
+
agentStatus,
|
|
142
|
+
pendingToolPermission,
|
|
143
|
+
conversationTitle,
|
|
144
|
+
conversationId,
|
|
145
|
+
addNotification,
|
|
146
|
+
stop,
|
|
147
|
+
rejectPendingPermission,
|
|
148
|
+
removeFirstFromQueue,
|
|
149
|
+
clearQueue,
|
|
150
|
+
retryState,
|
|
151
|
+
networkOnline,
|
|
152
|
+
} = useAgent();
|
|
153
|
+
|
|
154
|
+
const composerRef = useRef<ComposerHandle>(null);
|
|
155
|
+
|
|
156
|
+
const { authExpired, clearAuthExpired } = useApiClient();
|
|
157
|
+
|
|
158
|
+
// Show a notification segment when session expires
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (authExpired) {
|
|
161
|
+
addNotification("Session expired — use /login to authenticate again.", "error");
|
|
162
|
+
clearAuthExpired();
|
|
163
|
+
}
|
|
164
|
+
}, [authExpired, addNotification, clearAuthExpired]);
|
|
165
|
+
|
|
166
|
+
// Expanded view: snapshot taken at moment of Ctrl+O
|
|
167
|
+
const [expandedSnapshot, setExpandedSnapshot] = useState<HistorySegment[] | null>(null);
|
|
168
|
+
|
|
169
|
+
const toggleExpand = useCallback(() => {
|
|
170
|
+
setExpandedSnapshot((prev) => {
|
|
171
|
+
if (prev !== null) return null; // close
|
|
172
|
+
// Snapshot: exclude transient/spinny
|
|
173
|
+
return rawSegments.filter((s) => !s.temp && !s.isSpinny);
|
|
174
|
+
});
|
|
175
|
+
}, [rawSegments]);
|
|
176
|
+
|
|
177
|
+
// Global Ctrl+O handler — only active when NOT in expanded mode.
|
|
178
|
+
// When expanded, ExpandedView's own useInput handles the key.
|
|
179
|
+
// Both handlers firing would cause a toggle → re-open race.
|
|
180
|
+
useInput(
|
|
181
|
+
(input, key) => {
|
|
182
|
+
if ((key.ctrl || key.super) && input === "o") {
|
|
183
|
+
toggleExpand();
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{ isActive: expandedSnapshot === null },
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const { lastItem, prevItems, isTruncated } = useMemo(() => {
|
|
190
|
+
const filtered = rawSegments.filter((s) => !s.temp && !s.isSpinny);
|
|
191
|
+
const items = groupSegments(filtered);
|
|
192
|
+
const truncated = items.length > 100;
|
|
193
|
+
const visible = truncated ? items.slice(-100) : items;
|
|
194
|
+
return {
|
|
195
|
+
lastItem: visible.at(-1) ?? null,
|
|
196
|
+
prevItems: visible.slice(0, -1),
|
|
197
|
+
isTruncated: truncated,
|
|
198
|
+
};
|
|
199
|
+
}, [rawSegments]);
|
|
200
|
+
|
|
201
|
+
const deferredPrevItems = useDeferredValue(prevItems);
|
|
202
|
+
|
|
203
|
+
// Thinking timing for status indicator
|
|
204
|
+
const { thinkingStartTime, thinkingEndTime } = useMemo(
|
|
205
|
+
() => getThinkingTiming(rawSegments),
|
|
206
|
+
[rawSegments],
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const isWaitingForPermission =
|
|
210
|
+
agentStatus === AgentStatus.WaitingForToolPermission && pendingToolPermission !== null;
|
|
211
|
+
|
|
212
|
+
const [exiting, setExiting] = useState(false);
|
|
213
|
+
const [exitDuration, setExitDuration] = useState("0");
|
|
214
|
+
const [exitCredits, setExitCredits] = useState(0);
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
if (conversationTitle) {
|
|
218
|
+
setTitle(`${conversationTitle} • Abacus.AI CLI`);
|
|
219
|
+
} else {
|
|
220
|
+
setTitle("Abacus.AI CLI");
|
|
221
|
+
}
|
|
222
|
+
}, [conversationTitle, setTitle]);
|
|
223
|
+
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
const unsubscribe = onExit(
|
|
226
|
+
async () => {
|
|
227
|
+
const duration = timing.getFormattedDuration();
|
|
228
|
+
|
|
229
|
+
setExitCredits(0);
|
|
230
|
+
setExitDuration(duration);
|
|
231
|
+
setExiting(true);
|
|
232
|
+
|
|
233
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 100));
|
|
234
|
+
},
|
|
235
|
+
{ wait: 2000, streams: [process.stdout, process.stderr] },
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
return unsubscribe;
|
|
239
|
+
}, [timing]);
|
|
240
|
+
|
|
241
|
+
const hints = useInterruptManager({
|
|
242
|
+
agentStatus,
|
|
243
|
+
hasPendingPermission: pendingToolPermission !== null,
|
|
244
|
+
composerHasText: () => composerRef.current?.hasText() ?? false,
|
|
245
|
+
hasQueuedMessages: () => composerRef.current?.hasQueue() ?? false,
|
|
246
|
+
stopAgent: stop,
|
|
247
|
+
rejectPermission: rejectPendingPermission,
|
|
248
|
+
saveAndClearComposer: () => composerRef.current?.saveAndClear(),
|
|
249
|
+
clearComposer: () => composerRef.current?.clear(),
|
|
250
|
+
dequeueOne: removeFirstFromQueue,
|
|
251
|
+
clearQueue,
|
|
252
|
+
exitApp: () => gracefulExit(0),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const shouldShowStatusIndicator =
|
|
256
|
+
(agentStatus !== AgentStatus.Idle && agentStatus !== AgentStatus.WaitingForToolPermission) ||
|
|
257
|
+
retryState !== null ||
|
|
258
|
+
!networkOnline;
|
|
259
|
+
|
|
260
|
+
const pendingToolCallId = pendingToolPermission?.request.tool.id ?? null;
|
|
261
|
+
|
|
262
|
+
// Expanded mode: show static snapshot instead of normal UI
|
|
263
|
+
if (expandedSnapshot !== null) {
|
|
264
|
+
return <ExpandedView snapshot={expandedSnapshot} onClose={() => setExpandedSnapshot(null)} />;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<>
|
|
269
|
+
<View flexDirection="column" gap={1} paddingBottom={1} width="95%">
|
|
270
|
+
<Header />
|
|
271
|
+
{isTruncated && (
|
|
272
|
+
<Text dimColor>
|
|
273
|
+
— Output limited to the last 100 items for performance. Use /new to start a fresh
|
|
274
|
+
conversation. —
|
|
275
|
+
</Text>
|
|
276
|
+
)}
|
|
277
|
+
<PendingToolCallIdContext.Provider value={pendingToolCallId}>
|
|
278
|
+
{deferredPrevItems.map((item) =>
|
|
279
|
+
item.kind === "segment" ? (
|
|
280
|
+
<Segment key={item.segment.id} segment={item.segment} />
|
|
281
|
+
) : (
|
|
282
|
+
<ToolGroupSummary key={item.id} segments={item.segments} />
|
|
283
|
+
),
|
|
284
|
+
)}
|
|
285
|
+
{lastItem &&
|
|
286
|
+
(lastItem.kind === "segment" ? (
|
|
287
|
+
<Segment key={lastItem.segment.id} segment={lastItem.segment} />
|
|
288
|
+
) : (
|
|
289
|
+
<ToolGroupSummary key={lastItem.id} segments={lastItem.segments} />
|
|
290
|
+
))}
|
|
291
|
+
</PendingToolCallIdContext.Provider>
|
|
292
|
+
{shouldShowStatusIndicator && (
|
|
293
|
+
<StatusIndicator
|
|
294
|
+
status={agentStatus}
|
|
295
|
+
thinkingStartTime={thinkingStartTime}
|
|
296
|
+
thinkingEndTime={thinkingEndTime}
|
|
297
|
+
retryState={retryState}
|
|
298
|
+
networkOnline={networkOnline}
|
|
299
|
+
/>
|
|
300
|
+
)}
|
|
301
|
+
</View>
|
|
302
|
+
|
|
303
|
+
{exiting ? (
|
|
304
|
+
<ExitMessage
|
|
305
|
+
duration={exitDuration}
|
|
306
|
+
credits={exitCredits}
|
|
307
|
+
conversationId={conversationId}
|
|
308
|
+
/>
|
|
309
|
+
) : (
|
|
310
|
+
<>
|
|
311
|
+
{isWaitingForPermission && <ToolPermissionUI pendingTool={pendingToolPermission} />}
|
|
312
|
+
<Activity mode={isWaitingForPermission ? "hidden" : "visible"}>
|
|
313
|
+
<Composer hints={hints} composerRef={composerRef} />
|
|
314
|
+
</Activity>
|
|
315
|
+
</>
|
|
316
|
+
)}
|
|
317
|
+
</>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface ReplConfig {
|
|
322
|
+
apiClient: AbacusClient;
|
|
323
|
+
authManager: AuthManager;
|
|
324
|
+
agentArgs?: AgentArgs;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export async function runRepl({ apiClient, authManager, agentArgs }: ReplConfig) {
|
|
328
|
+
const queryClient = new QueryClient();
|
|
329
|
+
const timing = new Timing();
|
|
330
|
+
|
|
331
|
+
let initialAgentMode: AgentMode | undefined;
|
|
332
|
+
if (agentArgs?.["dangerously-skip-permissions"]) {
|
|
333
|
+
initialAgentMode = AgentMode.Yolo;
|
|
334
|
+
} else if (agentArgs?.["auto-accept-edits"]) {
|
|
335
|
+
initialAgentMode = AgentMode.AcceptEdits;
|
|
336
|
+
} else if (agentArgs?.["plan-mode"]) {
|
|
337
|
+
initialAgentMode = AgentMode.PlanMode;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const stdout = process.stdout;
|
|
341
|
+
const write = (s: string) => {
|
|
342
|
+
if (stdout && stdout.writable) {
|
|
343
|
+
stdout.write(s);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const hideCursor = () => write(ANSI.HIDE_CURSOR);
|
|
347
|
+
const showCursor = () => write(ANSI.SHOW_CURSOR);
|
|
348
|
+
|
|
349
|
+
hideCursor();
|
|
350
|
+
const cleanupSuspend = setupSuspendHandler({
|
|
351
|
+
onAfterResume: () => {
|
|
352
|
+
// Ink will re-render automatically when stdin resumes
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
const app = render(
|
|
356
|
+
<ThemeProvider>
|
|
357
|
+
<ApiClientProvider client={apiClient} authManager={authManager}>
|
|
358
|
+
<QueryClientProvider client={queryClient}>
|
|
359
|
+
<ShellSizeProvider>
|
|
360
|
+
<ShellTitleProvider>
|
|
361
|
+
<NotificationProvider>
|
|
362
|
+
<ExtensionFileProvider>
|
|
363
|
+
<AgentModeProvider initialMode={initialAgentMode}>
|
|
364
|
+
<NetworkActivityProvider>
|
|
365
|
+
<AgentProvider apiClient={apiClient} agentArgs={agentArgs}>
|
|
366
|
+
<App timing={timing} />
|
|
367
|
+
</AgentProvider>
|
|
368
|
+
</NetworkActivityProvider>
|
|
369
|
+
</AgentModeProvider>
|
|
370
|
+
</ExtensionFileProvider>
|
|
371
|
+
</NotificationProvider>
|
|
372
|
+
</ShellTitleProvider>
|
|
373
|
+
</ShellSizeProvider>
|
|
374
|
+
</QueryClientProvider>
|
|
375
|
+
</ApiClientProvider>
|
|
376
|
+
</ThemeProvider>,
|
|
377
|
+
{
|
|
378
|
+
exitOnCtrlC: false,
|
|
379
|
+
},
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
let cleanedUp = false;
|
|
383
|
+
const cleanup = () => {
|
|
384
|
+
if (cleanedUp) return;
|
|
385
|
+
cleanedUp = true;
|
|
386
|
+
showCursor();
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const handleProcessExit = () => {
|
|
390
|
+
if (!cleanedUp) {
|
|
391
|
+
cleanedUp = true;
|
|
392
|
+
app.cleanupTerminal();
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
process.once("exit", handleProcessExit);
|
|
396
|
+
|
|
397
|
+
await app.waitUntilExit();
|
|
398
|
+
process.off("exit", handleProcessExit);
|
|
399
|
+
cleanupSuspend();
|
|
400
|
+
cleanup();
|
|
401
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { use } from "react";
|
|
2
|
+
|
|
3
|
+
import { AgentContext, AgentProvider } from "../providers/agent.js";
|
|
4
|
+
|
|
5
|
+
export function useAgent() {
|
|
6
|
+
const agent = use(AgentContext);
|
|
7
|
+
|
|
8
|
+
if (!agent) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
`Agent context not found. Did you forget to wrap your component in <${AgentProvider.name}>?`,
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return agent;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useApiClient } from "../providers/api-client.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
export function useCleanup(callback: () => void) {
|
|
4
|
+
const cleaningUpRef = useRef(false);
|
|
5
|
+
const callbackRef = useRef(callback);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
callbackRef.current = callback;
|
|
9
|
+
}, [callback]);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const cleanup = () => {
|
|
13
|
+
if (cleaningUpRef.current) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
cleaningUpRef.current = true;
|
|
17
|
+
callbackRef.current();
|
|
18
|
+
};
|
|
19
|
+
process.on("exit", cleanup);
|
|
20
|
+
process.on("SIGINT", cleanup);
|
|
21
|
+
process.on("SIGTERM", cleanup);
|
|
22
|
+
return () => {
|
|
23
|
+
cleanup();
|
|
24
|
+
process.off("exit", cleanup);
|
|
25
|
+
process.off("SIGINT", cleanup);
|
|
26
|
+
process.off("SIGTERM", cleanup);
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { useInput, type Key } from "@codellm/jar";
|
|
2
|
+
import { useCallback, useEffect, useEffectEvent, useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
import { AgentStatus } from "../providers/agent.js";
|
|
5
|
+
|
|
6
|
+
export interface InterruptHints {
|
|
7
|
+
/** "ESC again to clear" shown bottom-right of composer */
|
|
8
|
+
escClear: boolean;
|
|
9
|
+
/** "Press Ctrl+C/D again to exit" shown bottom-left */
|
|
10
|
+
exitKey: "c" | "d" | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type InterruptContext =
|
|
14
|
+
| "tool-executing"
|
|
15
|
+
| "streaming"
|
|
16
|
+
| "permission-ui"
|
|
17
|
+
| "idle-with-text"
|
|
18
|
+
| "idle-empty";
|
|
19
|
+
|
|
20
|
+
interface UseInterruptManagerProps {
|
|
21
|
+
agentStatus: AgentStatus;
|
|
22
|
+
hasPendingPermission: boolean;
|
|
23
|
+
composerHasText: () => boolean;
|
|
24
|
+
hasQueuedMessages: () => boolean;
|
|
25
|
+
// Actions
|
|
26
|
+
stopAgent: () => void;
|
|
27
|
+
rejectPermission: () => void;
|
|
28
|
+
saveAndClearComposer: () => void;
|
|
29
|
+
clearComposer: () => void;
|
|
30
|
+
dequeueOne: () => void; // pop one queued message (for ESC)
|
|
31
|
+
clearQueue: () => void; // clear all queued messages (for Ctrl+C/D)
|
|
32
|
+
exitApp: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const HINT_TIMEOUT = 2_000;
|
|
36
|
+
|
|
37
|
+
function deriveContext(
|
|
38
|
+
agentStatus: AgentStatus,
|
|
39
|
+
hasPendingPermission: boolean,
|
|
40
|
+
composerHasText: () => boolean,
|
|
41
|
+
): InterruptContext {
|
|
42
|
+
if (agentStatus === AgentStatus.ExecutingTool) return "tool-executing";
|
|
43
|
+
if (agentStatus === AgentStatus.Submitted || agentStatus === AgentStatus.Streaming)
|
|
44
|
+
return "streaming";
|
|
45
|
+
if (agentStatus === AgentStatus.WaitingForToolPermission && hasPendingPermission)
|
|
46
|
+
return "permission-ui";
|
|
47
|
+
if (composerHasText()) return "idle-with-text";
|
|
48
|
+
return "idle-empty";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function useInterruptManager(props: UseInterruptManagerProps): InterruptHints {
|
|
52
|
+
const {
|
|
53
|
+
agentStatus,
|
|
54
|
+
hasPendingPermission,
|
|
55
|
+
composerHasText,
|
|
56
|
+
hasQueuedMessages,
|
|
57
|
+
stopAgent,
|
|
58
|
+
rejectPermission,
|
|
59
|
+
saveAndClearComposer,
|
|
60
|
+
clearComposer,
|
|
61
|
+
dequeueOne,
|
|
62
|
+
clearQueue,
|
|
63
|
+
exitApp,
|
|
64
|
+
} = props;
|
|
65
|
+
|
|
66
|
+
const [escClear, setEscClear] = useState(false);
|
|
67
|
+
const [exitKey, setExitKey] = useState<"c" | "d" | null>(null);
|
|
68
|
+
|
|
69
|
+
const escTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
70
|
+
const exitTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
71
|
+
|
|
72
|
+
const clearEscHint = useCallback(() => {
|
|
73
|
+
setEscClear(false);
|
|
74
|
+
if (escTimerRef.current) {
|
|
75
|
+
clearTimeout(escTimerRef.current);
|
|
76
|
+
escTimerRef.current = null;
|
|
77
|
+
}
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const clearExitHint = useCallback(() => {
|
|
81
|
+
setExitKey(null);
|
|
82
|
+
if (exitTimerRef.current) {
|
|
83
|
+
clearTimeout(exitTimerRef.current);
|
|
84
|
+
exitTimerRef.current = null;
|
|
85
|
+
}
|
|
86
|
+
}, []);
|
|
87
|
+
|
|
88
|
+
const clearAllHints = useCallback(() => {
|
|
89
|
+
clearEscHint();
|
|
90
|
+
clearExitHint();
|
|
91
|
+
}, [clearEscHint, clearExitHint]);
|
|
92
|
+
|
|
93
|
+
// Clear hints when context changes away from idle
|
|
94
|
+
const context = deriveContext(agentStatus, hasPendingPermission, composerHasText);
|
|
95
|
+
const prevContextRef = useRef(context);
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const prev = prevContextRef.current;
|
|
99
|
+
prevContextRef.current = context;
|
|
100
|
+
|
|
101
|
+
if (prev !== context) {
|
|
102
|
+
clearAllHints();
|
|
103
|
+
}
|
|
104
|
+
}, [context, clearAllHints]);
|
|
105
|
+
|
|
106
|
+
const handleInput = useEffectEvent((input: string, key: Key) => {
|
|
107
|
+
// Ctrl+Z → suspend (Unix only)
|
|
108
|
+
if (key.ctrl && input === "z") {
|
|
109
|
+
if (process.platform !== "win32") {
|
|
110
|
+
process.kill(process.pid, "SIGTSTP");
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const isEsc = key.escape;
|
|
116
|
+
const isCtrlC = key.ctrl && input === "c";
|
|
117
|
+
const isCtrlD = key.ctrl && input === "d";
|
|
118
|
+
|
|
119
|
+
if (!isEsc && !isCtrlC && !isCtrlD) return;
|
|
120
|
+
|
|
121
|
+
const ctx = deriveContext(agentStatus, hasPendingPermission, composerHasText);
|
|
122
|
+
|
|
123
|
+
// ── Active contexts: immediate action, no hints ──
|
|
124
|
+
if (ctx === "tool-executing" || ctx === "streaming") {
|
|
125
|
+
clearAllHints();
|
|
126
|
+
stopAgent();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (ctx === "permission-ui") {
|
|
131
|
+
clearAllHints();
|
|
132
|
+
rejectPermission();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ── Idle with text ──
|
|
137
|
+
if (ctx === "idle-with-text") {
|
|
138
|
+
if (isEsc) {
|
|
139
|
+
if (escClear) {
|
|
140
|
+
// Second ESC → clear composer
|
|
141
|
+
clearComposer();
|
|
142
|
+
clearAllHints();
|
|
143
|
+
} else {
|
|
144
|
+
// First ESC → show hint
|
|
145
|
+
clearExitHint();
|
|
146
|
+
setEscClear(true);
|
|
147
|
+
escTimerRef.current = setTimeout(() => {
|
|
148
|
+
setEscClear(false);
|
|
149
|
+
escTimerRef.current = null;
|
|
150
|
+
}, HINT_TIMEOUT);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Ctrl+C or Ctrl+D
|
|
156
|
+
const pressedKey = isCtrlC ? "c" : "d";
|
|
157
|
+
if (exitKey === pressedKey) {
|
|
158
|
+
// Same key pressed again → exit
|
|
159
|
+
clearAllHints();
|
|
160
|
+
exitApp();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (exitKey !== null) {
|
|
165
|
+
// Different key → reset to new key
|
|
166
|
+
clearExitHint();
|
|
167
|
+
setExitKey(pressedKey);
|
|
168
|
+
exitTimerRef.current = setTimeout(() => {
|
|
169
|
+
setExitKey(null);
|
|
170
|
+
exitTimerRef.current = null;
|
|
171
|
+
}, HINT_TIMEOUT);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// First press → save text to history, clear composer, show exit hint
|
|
176
|
+
clearEscHint();
|
|
177
|
+
saveAndClearComposer();
|
|
178
|
+
if (hasQueuedMessages()) {
|
|
179
|
+
clearQueue();
|
|
180
|
+
}
|
|
181
|
+
setExitKey(pressedKey);
|
|
182
|
+
exitTimerRef.current = setTimeout(() => {
|
|
183
|
+
setExitKey(null);
|
|
184
|
+
exitTimerRef.current = null;
|
|
185
|
+
}, HINT_TIMEOUT);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ── Idle empty ──
|
|
190
|
+
if (ctx === "idle-empty") {
|
|
191
|
+
if (isEsc) {
|
|
192
|
+
// Dequeue one message at a time
|
|
193
|
+
if (hasQueuedMessages()) {
|
|
194
|
+
dequeueOne();
|
|
195
|
+
}
|
|
196
|
+
// Otherwise no-op
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Ctrl+C or Ctrl+D
|
|
201
|
+
const pressedKey = isCtrlC ? "c" : "d";
|
|
202
|
+
if (exitKey === pressedKey) {
|
|
203
|
+
clearAllHints();
|
|
204
|
+
exitApp();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (exitKey !== null) {
|
|
209
|
+
// Different key → reset
|
|
210
|
+
clearExitHint();
|
|
211
|
+
setExitKey(pressedKey);
|
|
212
|
+
exitTimerRef.current = setTimeout(() => {
|
|
213
|
+
setExitKey(null);
|
|
214
|
+
exitTimerRef.current = null;
|
|
215
|
+
}, HINT_TIMEOUT);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Clear all queued messages on first Ctrl+C/D
|
|
220
|
+
if (hasQueuedMessages()) {
|
|
221
|
+
clearQueue();
|
|
222
|
+
}
|
|
223
|
+
setExitKey(pressedKey);
|
|
224
|
+
exitTimerRef.current = setTimeout(() => {
|
|
225
|
+
setExitKey(null);
|
|
226
|
+
exitTimerRef.current = null;
|
|
227
|
+
}, HINT_TIMEOUT);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
useInput(handleInput, { isActive: true });
|
|
232
|
+
|
|
233
|
+
// Cleanup timers on unmount
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
return () => {
|
|
236
|
+
if (escTimerRef.current) clearTimeout(escTimerRef.current);
|
|
237
|
+
if (exitTimerRef.current) clearTimeout(exitTimerRef.current);
|
|
238
|
+
};
|
|
239
|
+
}, []);
|
|
240
|
+
|
|
241
|
+
return { escClear, exitKey };
|
|
242
|
+
}
|