mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 00:21:09 -07:00
feat: implement /rewind command (#15720)
This commit is contained in:
@@ -18,12 +18,17 @@ import {
|
||||
isNodeError,
|
||||
unescapePath,
|
||||
ReadManyFilesTool,
|
||||
REFERENCE_CONTENT_START,
|
||||
REFERENCE_CONTENT_END,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import type { HistoryItem, IndividualToolCallDisplay } from '../types.js';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||
|
||||
const REF_CONTENT_HEADER = `\n${REFERENCE_CONTENT_START}`;
|
||||
const REF_CONTENT_FOOTER = `\n${REFERENCE_CONTENT_END}`;
|
||||
|
||||
interface HandleAtCommandParams {
|
||||
query: string;
|
||||
config: Config;
|
||||
@@ -499,10 +504,17 @@ export async function handleAtCommand({
|
||||
const resourceResults = await Promise.all(resourcePromises);
|
||||
const resourceReadDisplays: IndividualToolCallDisplay[] = [];
|
||||
let resourceErrorOccurred = false;
|
||||
let hasAddedReferenceHeader = false;
|
||||
|
||||
for (const result of resourceResults) {
|
||||
resourceReadDisplays.push(result.display);
|
||||
if (result.success) {
|
||||
if (!hasAddedReferenceHeader) {
|
||||
processedQueryParts.push({
|
||||
text: REF_CONTENT_HEADER,
|
||||
});
|
||||
hasAddedReferenceHeader = true;
|
||||
}
|
||||
processedQueryParts.push({ text: `\nContent from @${result.uri}:\n` });
|
||||
processedQueryParts.push(...result.parts);
|
||||
} else {
|
||||
@@ -540,6 +552,9 @@ export async function handleAtCommand({
|
||||
userMessageTimestamp,
|
||||
);
|
||||
}
|
||||
if (hasAddedReferenceHeader) {
|
||||
processedQueryParts.push({ text: REF_CONTENT_FOOTER });
|
||||
}
|
||||
return { processedQuery: processedQueryParts };
|
||||
}
|
||||
|
||||
@@ -570,9 +585,12 @@ export async function handleAtCommand({
|
||||
|
||||
if (Array.isArray(result.llmContent)) {
|
||||
const fileContentRegex = /^--- (.*?) ---\n\n([\s\S]*?)\n\n$/;
|
||||
processedQueryParts.push({
|
||||
text: '\n--- Content from referenced files ---',
|
||||
});
|
||||
if (!hasAddedReferenceHeader) {
|
||||
processedQueryParts.push({
|
||||
text: REF_CONTENT_HEADER,
|
||||
});
|
||||
hasAddedReferenceHeader = true;
|
||||
}
|
||||
for (const part of result.llmContent) {
|
||||
if (typeof part === 'string') {
|
||||
const match = fileContentRegex.exec(part);
|
||||
|
||||
Reference in New Issue
Block a user