Skip to content

Commit e7174a7

Browse files
committed
fix(vscode): 修复@文件夹导致上下文一次爆炸的bug;增强了文件搜索功能
(cherry picked from commit 96f85a5)
1 parent 0343201 commit e7174a7

19 files changed

Lines changed: 376 additions & 69 deletions

File tree

package-lock.json

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/ui/commands/copyCommand.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { copyCommand } from './copyCommand.js';
99
import { type CommandContext } from './types.js';
1010
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
1111
import { copyToClipboard } from '../utils/commandUtils.js';
12+
import { t } from '../utils/i18n.js';
1213

1314
vi.mock('../utils/commandUtils.js', () => ({
1415
copyToClipboard: vi.fn(),
@@ -119,7 +120,7 @@ describe('copyCommand', () => {
119120
expect(result).toEqual({
120121
type: 'message',
121122
messageType: 'info',
122-
content: '📋已复制到粘贴板',
123+
content: t('command.copy.success'),
123124
});
124125

125126
expect(mockCopyToClipboard).toHaveBeenCalledWith(
@@ -146,7 +147,7 @@ describe('copyCommand', () => {
146147
expect(result).toEqual({
147148
type: 'message',
148149
messageType: 'info',
149-
content: '📋已复制到粘贴板',
150+
content: t('command.copy.success'),
150151
});
151152
});
152153

@@ -173,7 +174,7 @@ describe('copyCommand', () => {
173174
expect(result).toEqual({
174175
type: 'message',
175176
messageType: 'info',
176-
content: '📋已复制到粘贴板',
177+
content: t('command.copy.success'),
177178
});
178179
});
179180

@@ -204,7 +205,7 @@ describe('copyCommand', () => {
204205
expect(result).toEqual({
205206
type: 'message',
206207
messageType: 'info',
207-
content: '📋已复制到粘贴板',
208+
content: t('command.copy.success'),
208209
});
209210
});
210211

packages/cli/src/ui/commands/copyCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const copyCommand: SlashCommand = {
4545
return {
4646
type: 'message',
4747
messageType: 'info',
48-
content: '📋已复制到粘贴板',
48+
content: t('command.copy.success'),
4949
};
5050
} catch (error) {
5151
const message = error instanceof Error ? error.message : String(error);

packages/cli/src/ui/utils/i18n.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ export const translations = {
825825
'command.compress.description': 'Compress context through summary replacement',
826826
'command.compress.starting': 'Compressing context, approximately 20 seconds, please wait...',
827827
'command.copy.description': 'Copy last result or code snippet to clipboard',
828+
'command.copy.success': '📋 Copied to clipboard',
828829
'command.editor.description': 'Set external editor preferences',
829830
'command.memory.description': 'Commands to interact with memory',
830831
'command.stats.description': 'View all statistics (session, model, and tools). Usage: /stats [model [name]|tools]',
@@ -2145,6 +2146,7 @@ export const translations = {
21452146
'command.compress.description': '通过摘要替换来压缩上下文',
21462147
'command.compress.starting': '正在压缩,大约需要20秒,请稍等...',
21472148
'command.copy.description': '将最后的结果或代码片段复制到剪贴板',
2149+
'command.copy.success': '📋已复制到粘贴板',
21482150
'command.editor.description': '设置外部编辑器偏好',
21492151
'command.memory.description': '与记忆交互的命令',
21502152
'command.stats.description': '查看所有统计信息(会话、模型和工具)。用法:/stats [model [名称]|tools]',

packages/vscode-ui-plugin/src/utils/messageContentConverter.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function convertMessageContentToParts(
4848
case 'file_reference':
4949
return `@[${item.value.fileName}]`;
5050
case 'folder_reference': // 🎯 文件夹引用
51-
return `@[📁${item.value.folderName}]`;
51+
return `@[${item.value.folderName}]`;
5252
case 'image_reference':
5353
return `[IMAGE:${item.value.fileName}]`;
5454
case 'code_reference': // 🎯 代码引用
@@ -120,27 +120,12 @@ export async function convertMessageContentToParts(
120120
}
121121
fileParts++; // 计入文件部分(作为上下文内容)
122122
} else if (item.type === 'folder_reference') {
123-
// 🎯 文件夹引用:读取文件夹内所有文件内容
123+
// 🚫 严禁展开文件夹内容:只传递路径文本。
124+
// 原因:展开会将整个文件夹文件塞入上下文,瞬间耗尽模型上下文窗口,导致响应失败/错乱。
125+
// 如需展开,必须通过显式的“文件夹展开”功能并加上限制/确认,不得在此处修改。
124126
console.log(`📁 [MessageConverter] 处理 folder_reference: ${item.value.folderName}, path: ${item.value.folderPath}`);
125127
const folderInfo = `--- Folder: ${item.value.folderName} (${item.value.folderPath}) ---`;
126128
allParts.push({ text: folderInfo });
127-
128-
// 读取文件夹内的文件
129-
try {
130-
const result = await processFolderToPartsList(item.value.folderPath, workspaceRoot);
131-
if (result.parts.length > 0) {
132-
console.log(`✅ [MessageConverter] 文件夹内容已添加: ${item.value.folderName}, ${result.parts.length} parts, ${result.fileCount} files`);
133-
allParts.push(...result.parts);
134-
fileParts += result.fileCount;
135-
} else {
136-
console.warn(`⚠️ [MessageConverter] 文件夹为空或无可读文件: ${item.value.folderName}`);
137-
allParts.push({ text: '(Folder is empty or contains no readable files)' });
138-
}
139-
} catch (error) {
140-
const errorMessage = error instanceof Error ? error.message : String(error);
141-
console.error(`❌ [MessageConverter] 读取文件夹失败: ${item.value.folderName}`, errorMessage);
142-
warnings.push(`Error reading folder ${item.value.folderName}: ${errorMessage}`);
143-
}
144129
}
145130
// text类型已经在第一步处理了,这里跳过
146131
} catch (error) {

0 commit comments

Comments
 (0)