mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 00:52:05 +00:00
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
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
571a237d5a
commit
3017388dc0
@@ -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, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user