fix(core): fix three JIT context bugs in read_file, read_many_files, and memoryDiscovery (#22679)

This commit is contained in:
Sandy Tao
2026-03-16 13:10:50 -07:00
committed by GitHub
parent dfe22aae21
commit b91f75cd6d
7 changed files with 221 additions and 12 deletions
+13 -5
View File
@@ -20,7 +20,7 @@ import {
import { ToolErrorType } from './tool-error.js';
import { buildFilePathArgsPattern } from '../policy/utils.js';
import type { PartUnion } from '@google/genai';
import type { PartListUnion } from '@google/genai';
import {
processSingleFileContent,
getSpecificMimeType,
@@ -34,7 +34,11 @@ import { READ_FILE_TOOL_NAME, READ_FILE_DISPLAY_NAME } from './tool-names.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import { READ_FILE_DEFINITION } from './definitions/coreTools.js';
import { resolveToolDeclaration } from './definitions/resolver.js';
import { discoverJitContext, appendJitContext } from './jit-context.js';
import {
discoverJitContext,
appendJitContext,
appendJitContextToParts,
} from './jit-context.js';
/**
* Parameters for the ReadFile tool
@@ -135,7 +139,7 @@ class ReadFileToolInvocation extends BaseToolInvocation<
};
}
let llmContent: PartUnion;
let llmContent: PartListUnion;
if (result.isTruncated) {
const [start, end] = result.linesShown!;
const total = result.originalLineCount!;
@@ -173,8 +177,12 @@ ${result.llmContent}`;
// Discover JIT subdirectory context for the accessed file path
const jitContext = await discoverJitContext(this.config, this.resolvedPath);
if (jitContext && typeof llmContent === 'string') {
llmContent = appendJitContext(llmContent, jitContext);
if (jitContext) {
if (typeof llmContent === 'string') {
llmContent = appendJitContext(llmContent, jitContext);
} else {
llmContent = appendJitContextToParts(llmContent, jitContext);
}
}
return {