From 3017388dc036aa62f4408058aa9f9b9feabfab3b Mon Sep 17 00:00:00 2001 From: 0xRaini <0xRaini@users.noreply.github.com> Date: Fri, 13 Feb 2026 03:12:58 +0800 Subject: [PATCH] fix(agents): guard against undefined path in context file entries buildAgentSystemPrompt crashes with 'Cannot read properties of undefined (reading trim)' when a workspace context file has path: undefined. Filter out invalid entries before processing. Closes #14635 --- src/agents/system-prompt.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/agents/system-prompt.ts b/src/agents/system-prompt.ts index 36ab37060ec2..4e48a559da83 100644 --- a/src/agents/system-prompt.ts +++ b/src/agents/system-prompt.ts @@ -550,8 +550,11 @@ export function buildAgentSystemPrompt(params: { } const contextFiles = params.contextFiles ?? []; - if (contextFiles.length > 0) { - const hasSoulFile = contextFiles.some((file) => { + const validContextFiles = contextFiles.filter( + (file) => typeof file.path === "string" && file.path.trim(), + ); + if (validContextFiles.length > 0) { + const hasSoulFile = validContextFiles.some((file) => { const normalizedPath = file.path.trim().replace(/\\/g, "/"); const baseName = normalizedPath.split("/").pop() ?? normalizedPath; return baseName.toLowerCase() === "soul.md"; @@ -563,7 +566,7 @@ export function buildAgentSystemPrompt(params: { ); } lines.push(""); - for (const file of contextFiles) { + for (const file of validContextFiles) { lines.push(`## ${file.path}`, "", file.content, ""); } }