fix(agents): skip bootstrap files with undefined path (#22698)

* fix(agents): skip bootstrap files with undefined path

buildBootstrapContextFiles() called file.path.replace() without checking
that path was defined. If a hook pushed a bootstrap file using 'filePath'
instead of 'path', the function threw TypeError and crashed every agent
session — not just the misconfigured hook.

Fix: add a null-guard before the path.replace() call. Files with undefined
path are skipped with a warning so one bad hook can't take down all agents.

Also adds a test covering the undefined-path case.

Fixes #22693

* fix: harden bootstrap path validation and report guards (#22698) (thanks @arosstale)

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
Artale
2026-02-22 13:17:07 +01:00
committed by GitHub
parent 45d7776697
commit 51e9c54f09
7 changed files with 141 additions and 8 deletions

View File

@@ -199,15 +199,22 @@ export function buildBootstrapContextFiles(
if (remainingTotalChars <= 0) {
break;
}
const pathValue = typeof file.path === "string" ? file.path.trim() : "";
if (!pathValue) {
opts?.warn?.(
`skipping bootstrap file "${file.name}" — missing or invalid "path" field (hook may have used "filePath" instead)`,
);
continue;
}
if (file.missing) {
const missingText = `[MISSING] Expected at: ${file.path}`;
const missingText = `[MISSING] Expected at: ${pathValue}`;
const cappedMissingText = clampToBudget(missingText, remainingTotalChars);
if (!cappedMissingText) {
break;
}
remainingTotalChars = Math.max(0, remainingTotalChars - cappedMissingText.length);
result.push({
path: file.path,
path: pathValue,
content: cappedMissingText,
});
continue;
@@ -231,7 +238,7 @@ export function buildBootstrapContextFiles(
}
remainingTotalChars = Math.max(0, remainingTotalChars - contentWithinBudget.length);
result.push({
path: file.path,
path: pathValue,
content: contentWithinBudget,
});
}