From d3a607e4e5ad2791cf502f4fcf1bb182cb720898 Mon Sep 17 00:00:00 2001 From: sobird Date: Sun, 5 Apr 2026 01:37:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=9C=A8=E7=BB=88=E7=AB=AF=E9=AB=98=E4=BA=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit highlight.js v11 result = hljs().highlight(); 已经不存在result.emitter,使用result._emitter替代 --- packages/color-diff-napi/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/color-diff-napi/src/index.ts b/packages/color-diff-napi/src/index.ts index 779e23b65..f8c0d70b2 100644 --- a/packages/color-diff-napi/src/index.ts +++ b/packages/color-diff-napi/src/index.ts @@ -528,19 +528,20 @@ function highlightLine( // hljs throws on unknown language despite ignoreIllegals return [[defaultStyle(theme), code]] } - if (!hasRootNode(result.emitter)) { + const emitter = result._emitter; + if (!hasRootNode(emitter)) { if (!loggedEmitterShapeError) { loggedEmitterShapeError = true logError( new Error( - `color-diff: hljs emitter shape mismatch (keys: ${Object.keys(result.emitter).join(',')}). Syntax highlighting disabled.`, + `color-diff: hljs emitter shape mismatch (keys: ${Object.keys(emitter).join(',')}). Syntax highlighting disabled.`, ), ) } return [[defaultStyle(theme), code]] } const blocks: Block[] = [] - flattenHljs(result.emitter.rootNode, theme, undefined, blocks) + flattenHljs(emitter.rootNode, theme, undefined, blocks) return blocks } From 354c11f035d7592fa47860eac180147b43297f58 Mon Sep 17 00:00:00 2001 From: xutianyi Date: Sun, 5 Apr 2026 01:43:18 +0800 Subject: [PATCH 2/3] fix: improve size calculation for LRU cache and handle nested object content --- src/utils/fileStateCache.ts | 13 ++++++++++++- src/utils/queryHelpers.ts | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/utils/fileStateCache.ts b/src/utils/fileStateCache.ts index c7bb2f1dd..165b3fa1d 100644 --- a/src/utils/fileStateCache.ts +++ b/src/utils/fileStateCache.ts @@ -34,7 +34,18 @@ export class FileStateCache { this.cache = new LRUCache({ max: maxEntries, maxSize: maxSizeBytes, - sizeCalculation: value => Math.max(1, Buffer.byteLength(value.content)), + sizeCalculation: value => { + const c = value.content + const s = + typeof c === 'string' + ? c + : c === null || c === undefined + ? '' + : typeof c === 'object' + ? JSON.stringify(c) + : String(c) + return Math.max(1, Buffer.byteLength(s, 'utf8')) + }, }) } diff --git a/src/utils/queryHelpers.ts b/src/utils/queryHelpers.ts index 520588b54..c1c82bb6e 100644 --- a/src/utils/queryHelpers.ts +++ b/src/utils/queryHelpers.ts @@ -45,6 +45,14 @@ export type PermissionPromptTool = Tool< // during permission prompts or limited tool operations const ASK_READ_FILE_STATE_CACHE_SIZE = 10 +/** Transcript JSON may deserialize Write tool `content` as a nested object — LRU needs strings. */ +function coerceToolContentToString(value: unknown): string { + if (typeof value === 'string') return value + if (value === null || value === undefined) return '' + if (typeof value === 'object') return JSON.stringify(value) + return String(value) +} + /** * Checks if the result should be considered successful based on the last message. * Returns true if: @@ -402,14 +410,18 @@ export function extractReadFilesFromMessages( ) { // Extract file_path and content from the Write tool use input const input = content.input as - | { file_path?: string; content?: string } + | { file_path?: string; content?: unknown } | undefined - if (input?.file_path && input?.content) { + if ( + input?.file_path && + input.content !== undefined && + input.content !== null + ) { // Normalize to absolute path for consistent cache lookups const absolutePath = expandPath(input.file_path, cwd) fileWriteToolUseIds.set(content.id, { filePath: absolutePath, - content: input.content, + content: coerceToolContentToString(input.content), }) } } else if ( From c16fc628770ff50a7779fa25b1cef75269861cf1 Mon Sep 17 00:00:00 2001 From: sobird Date: Sun, 5 Apr 2026 09:12:48 +0800 Subject: [PATCH 3/3] chore: update --- packages/color-diff-napi/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/color-diff-napi/src/index.ts b/packages/color-diff-napi/src/index.ts index f8c0d70b2..afaf924ea 100644 --- a/packages/color-diff-napi/src/index.ts +++ b/packages/color-diff-napi/src/index.ts @@ -528,7 +528,7 @@ function highlightLine( // hljs throws on unknown language despite ignoreIllegals return [[defaultStyle(theme), code]] } - const emitter = result._emitter; + const emitter = result._emitter || {}; if (!hasRootNode(emitter)) { if (!loggedEmitterShapeError) { loggedEmitterShapeError = true