Skip to content

Commit 08bd7b7

Browse files
committed
fix(context): fall back to path basename when bootstrap file name is missing
Hook-injected virtual bootstrap files may omit the name field. buildBootstrapInjectionStats now falls back to basename(path) so the context breakdown never renders a literal "undefined" label. Closes #47941
1 parent 3832f93 commit 08bd7b7

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/agents/bootstrap-budget.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ describe("buildBootstrapInjectionStats", () => {
4848
truncated: true,
4949
});
5050
});
51+
52+
it("falls back to basename of path when name is missing (#47941)", () => {
53+
const bootstrapFiles = [
54+
{
55+
name: undefined as unknown as string,
56+
path: "/workspace/SELF_IMPROVEMENT_REMINDER.md",
57+
content: "reminder text",
58+
missing: false,
59+
},
60+
{
61+
name: "" as unknown as string,
62+
path: "/workspace/NOTES.md",
63+
content: "notes",
64+
missing: false,
65+
},
66+
] as unknown as WorkspaceBootstrapFile[];
67+
68+
const injectedFiles = [
69+
{ path: "/workspace/SELF_IMPROVEMENT_REMINDER.md", content: "reminder text" },
70+
{ path: "/workspace/NOTES.md", content: "notes" },
71+
];
72+
73+
const stats = buildBootstrapInjectionStats({ bootstrapFiles, injectedFiles });
74+
expect(stats[0]?.name).toBe("SELF_IMPROVEMENT_REMINDER.md");
75+
expect(stats[1]?.name).toBe("NOTES.md");
76+
});
5177
});
5278

5379
describe("analyzeBootstrapBudget", () => {

src/agents/bootstrap-budget.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ export function buildBootstrapInjectionStats(params: {
150150
injectedByBaseName.get(file.name);
151151
const injectedChars = injected ? injected.length : 0;
152152
const truncated = !file.missing && injectedChars < rawChars;
153+
const name =
154+
file.name || path.posix.basename(pathValue.replace(/\\/g, "/")) || "(virtual file)";
153155
return {
154-
name: file.name,
155-
path: pathValue || file.name,
156+
name,
157+
path: pathValue || name,
156158
missing: file.missing,
157159
rawChars,
158160
injectedChars,

0 commit comments

Comments
 (0)