Fixed @ file content not being added or sent to server (#962)
This commit is contained in:
parent
61d0cc39fd
commit
b7daa7c702
|
@ -154,9 +154,7 @@ describe('handleAtCommand', () => {
|
||||||
const query = `@${filePath}`;
|
const query = `@${filePath}`;
|
||||||
const fileContent = 'This is the file content.';
|
const fileContent = 'This is the file content.';
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${filePath} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${filePath} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 file.',
|
returnDisplay: 'Read 1 file.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -202,9 +200,7 @@ ${fileContent}`,
|
||||||
isDirectory: () => true,
|
isDirectory: () => true,
|
||||||
} as Stats);
|
} as Stats);
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${resolvedGlob} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${resolvedGlob} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read directory contents.',
|
returnDisplay: 'Read directory contents.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -245,9 +241,7 @@ ${fileContent}`,
|
||||||
// Current implementation of read_many_files for images returns base64 in text.
|
// Current implementation of read_many_files for images returns base64 in text.
|
||||||
const imageFileTextContent = '[base64 image data for path/to/image.png]';
|
const imageFileTextContent = '[base64 image data for path/to/image.png]';
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${imagePath} ---\n\n${imageFileTextContent}\n\n`],
|
||||||
--- ${imagePath} ---
|
|
||||||
${imageFileTextContent}`,
|
|
||||||
returnDisplay: 'Read 1 image.',
|
returnDisplay: 'Read 1 image.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -276,9 +270,7 @@ ${imageFileTextContent}`,
|
||||||
const query = `${textBefore}@${filePath}${textAfter}`;
|
const query = `${textBefore}@${filePath}${textAfter}`;
|
||||||
const fileContent = 'Markdown content.';
|
const fileContent = 'Markdown content.';
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${filePath} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${filePath} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 doc.',
|
returnDisplay: 'Read 1 doc.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -310,9 +302,7 @@ ${fileContent}`,
|
||||||
const query = `@${rawPath}`;
|
const query = `@${rawPath}`;
|
||||||
const fileContent = 'Content of file with space.';
|
const fileContent = 'Content of file with space.';
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${unescapedPath} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${unescapedPath} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 file.',
|
returnDisplay: 'Read 1 file.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -338,11 +328,10 @@ ${fileContent}`,
|
||||||
const query = `@${file1} @${file2}`;
|
const query = `@${file1} @${file2}`;
|
||||||
|
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [
|
||||||
--- ${file1} ---
|
`--- ${file1} ---\n\n${content1}\n\n`,
|
||||||
${content1}
|
`--- ${file2} ---\n\n${content2}\n\n`,
|
||||||
--- ${file2} ---
|
],
|
||||||
${content2}`,
|
|
||||||
returnDisplay: 'Read 2 files.',
|
returnDisplay: 'Read 2 files.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -381,11 +370,10 @@ ${content2}`,
|
||||||
const query = `${text1}@${file1}${text2}@${file2}${text3}`;
|
const query = `${text1}@${file1}${text2}@${file2}${text3}`;
|
||||||
|
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [
|
||||||
--- ${file1} ---
|
`--- ${file1} ---\n\n${content1}\n\n`,
|
||||||
${content1}
|
`--- ${file2} ---\n\n${content2}\n\n`,
|
||||||
--- ${file2} ---
|
],
|
||||||
${content2}`,
|
|
||||||
returnDisplay: 'Read 2 files.',
|
returnDisplay: 'Read 2 files.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -446,11 +434,10 @@ ${content2}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [
|
||||||
--- ${file1} ---
|
`--- ${file1} ---\n\n${content1}\n\n`,
|
||||||
${content1}
|
`--- ${resolvedFile2} ---\n\n${content2}\n\n`,
|
||||||
--- ${resolvedFile2} ---
|
],
|
||||||
${content2}`,
|
|
||||||
returnDisplay: 'Read 2 files.',
|
returnDisplay: 'Read 2 files.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -537,9 +524,7 @@ ${content2}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${queryPath} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${queryPath} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 file.',
|
returnDisplay: 'Read 1 file.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -628,9 +613,7 @@ ${fileContent}`,
|
||||||
|
|
||||||
mockFileDiscoveryService.shouldIgnoreFile.mockReturnValue(false);
|
mockFileDiscoveryService.shouldIgnoreFile.mockReturnValue(false);
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${validFile} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${validFile} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 file.',
|
returnDisplay: 'Read 1 file.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -670,9 +653,7 @@ ${fileContent}`,
|
||||||
(path: string) => path === gitIgnoredFile,
|
(path: string) => path === gitIgnoredFile,
|
||||||
);
|
);
|
||||||
mockReadManyFilesExecute.mockResolvedValue({
|
mockReadManyFilesExecute.mockResolvedValue({
|
||||||
llmContent: `
|
llmContent: [`--- ${validFile} ---\n\n${fileContent}\n\n`],
|
||||||
--- ${validFile} ---
|
|
||||||
${fileContent}`,
|
|
||||||
returnDisplay: 'Read 1 file.',
|
returnDisplay: 'Read 1 file.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -366,39 +366,23 @@ export async function handleAtCommand({
|
||||||
confirmationDetails: undefined,
|
confirmationDetails: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (Array.isArray(result.llmContent)) {
|
||||||
result.llmContent &&
|
const fileContentRegex = /^--- (.*?) ---\n\n([\s\S]*?)\n\n$/;
|
||||||
typeof result.llmContent === 'string' &&
|
|
||||||
result.llmContent.trim() !== ''
|
|
||||||
) {
|
|
||||||
processedQueryParts.push({
|
processedQueryParts.push({
|
||||||
text: '\n--- Content from referenced files ---',
|
text: '\n--- Content from referenced files ---',
|
||||||
});
|
});
|
||||||
const fileContentRegex =
|
for (const part of result.llmContent) {
|
||||||
/\n--- (.*?) ---\n([\s\S]*?)(?=\n--- .*? ---\n|$)/g;
|
if (typeof part === 'string') {
|
||||||
let match;
|
const match = fileContentRegex.exec(part);
|
||||||
const foundContentForSpecs = new Set<string>();
|
if (match) {
|
||||||
while ((match = fileContentRegex.exec(result.llmContent)) !== null) {
|
|
||||||
const filePathSpecInContent = match[1]; // This is a resolved pathSpec
|
const filePathSpecInContent = match[1]; // This is a resolved pathSpec
|
||||||
const fileActualContent = match[2].trim();
|
const fileActualContent = match[2].trim();
|
||||||
if (pathSpecsToRead.includes(filePathSpecInContent)) {
|
|
||||||
// Ensure we only add content for paths we requested
|
|
||||||
processedQueryParts.push({
|
processedQueryParts.push({
|
||||||
text: `\nContent from @${filePathSpecInContent}:\n`,
|
text: `\nContent from @${filePathSpecInContent}:\n`,
|
||||||
});
|
});
|
||||||
processedQueryParts.push({ text: fileActualContent });
|
processedQueryParts.push({ text: fileActualContent });
|
||||||
foundContentForSpecs.add(filePathSpecInContent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if any requested pathSpecs didn't yield content in the parsed block, could indicate an issue.
|
|
||||||
for (const requestedSpec of pathSpecsToRead) {
|
|
||||||
if (!foundContentForSpecs.has(requestedSpec)) {
|
|
||||||
onDebugMessage(
|
|
||||||
`Content for @${requestedSpec} was expected but not found in read_many_files output.`,
|
|
||||||
);
|
|
||||||
// Optionally add a note about missing content for this spec
|
|
||||||
// processedQueryParts.push({ text: `\nContent for @${requestedSpec} not found or empty.\n` });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
processedQueryParts.push({ text: '\n--- End of content ---' });
|
processedQueryParts.push({ text: '\n--- End of content ---' });
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue