Skip to content

Commit a902c62

Browse files
committed
Fix ACP tool call header stats
1 parent 7d4b2d8 commit a902c62

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

anycode/components/agent/AcpMessage.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ const ToolCallMessage: React.FC<{
9595
() => getToolCallView(message, toolUpdates, toolResult),
9696
[message, toolResult, toolUpdates],
9797
);
98-
const primaryDiff = toolCallView.diffs[0];
99-
const toggleLabel = primaryDiff ? getFileNameFromPath(primaryDiff.path) : displayCommand;
100-
const toggleStats = primaryDiff ? countDiffLines(primaryDiff.oldText, primaryDiff.newText) : undefined;
98+
const diffFileNames = getToolCallFileNames(toolCallView.diffs);
99+
const toggleLabel = formatToolCallLabel(diffFileNames, displayCommand);
100+
const toggleStats = getToolCallStats(toolCallView.diffs);
101101

102102
return (
103103
<div className="acp-message acp-message-tool_call">
@@ -364,6 +364,42 @@ const getFileNameFromPath = (path: string): string => {
364364
return path.split('/').pop() ?? path;
365365
};
366366

367+
const formatToolCallLabel = (diffPaths: string[], fallbackLabel: string): string => {
368+
if (diffPaths.length === 0) {
369+
return fallbackLabel;
370+
}
371+
372+
if (diffPaths.length === 1) {
373+
return getFileNameFromPath(diffPaths[0]);
374+
}
375+
376+
const visibleNames = diffPaths.slice(0, 2).map(getFileNameFromPath);
377+
const hiddenCount = diffPaths.length - visibleNames.length;
378+
return hiddenCount > 0
379+
? `${visibleNames.join(', ')} +${hiddenCount}`
380+
: visibleNames.join(', ');
381+
};
382+
383+
const getToolCallStats = (diffs: AcpDiffContent[]) => {
384+
if (diffs.length === 0) {
385+
return undefined;
386+
}
387+
388+
return diffs.reduce(
389+
(acc, diff) => {
390+
const diffStats = countDiffLines(diff.oldText, diff.newText);
391+
acc.added += diffStats.added;
392+
acc.deleted += diffStats.deleted;
393+
return acc;
394+
},
395+
{ added: 0, deleted: 0 },
396+
);
397+
};
398+
399+
const getToolCallFileNames = (diffs: AcpDiffContent[]): string[] => {
400+
return Array.from(new Set(diffs.map((diff) => getFileNameFromPath(diff.path))));
401+
};
402+
367403
const asRecord = (value: unknown): Record<string, unknown> | undefined => {
368404
return typeof value === 'object' && value !== null ? value as Record<string, unknown> : undefined;
369405
};

anycode/components/agent/AcpMessages.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77

88
.acp-dialog-messages-inner {
9-
padding: 0 8px;
9+
padding: 16px;
1010
display: flex;
1111
flex-direction: column;
1212
gap: 2px;

anycode/hooks/useEditors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
3535
const [editorStates, setEditorStates] = useState<Map<string, AnycodeEditor>>(new Map());
3636
const editorStatesRef = useRef<Map<string, AnycodeEditor>>(new Map());
3737
const editorRefs = useRef<Map<string, AnycodeEditor>>(new Map());
38+
const defaultFileInitializedRef = useRef(false);
3839

3940
const savedFileContentsRef = useRef<Map<string, string>>(new Map());
4041
const diagnosticsRef = useRef<Map<string, Diagnostic[]>>(new Map());
@@ -289,7 +290,8 @@ export const useEditors = ({ wsRef, isConnected, diffEnabled, onFileClosed }: Us
289290
}, [files, initializeEditors]);
290291

291292
useEffect(() => {
292-
if (files.length === 0) {
293+
if (files.length === 0 && !defaultFileInitializedRef.current) {
294+
defaultFileInitializedRef.current = true;
293295
setFiles([DEFAULT_FILE]);
294296
setActiveFileId(DEFAULT_FILE.id);
295297
cursorHistory.current.undoStack.push({ file: DEFAULT_FILE.id, cursor: { line: 0, column: 0 } });

0 commit comments

Comments
 (0)