fix(agents): guard against undefined path in context file entries (#14903)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25856b863d
Co-authored-by: 0xRaini <190923101+0xRaini@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
0xRain
2026-02-13 04:27:56 +08:00
committed by GitHub
parent 571a237d5a
commit d8d8109711
2 changed files with 23 additions and 3 deletions

View File

@@ -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().length > 0,
);
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, "");
}
}