Skip to content

Commit 1e74e7a

Browse files
committed
fix: surface agents bootstrap truncation warning
1 parent f4c2add commit 1e74e7a

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/agents/bootstrap-budget.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,28 @@ describe("bootstrap prompt warnings", () => {
326326
expect(lines).toContain("+1 more truncated file(s).");
327327
});
328328

329+
it("warns explicitly when AGENTS.md bootstrap policy is truncated", () => {
330+
const analysis = analyzeBootstrapBudget({
331+
files: [
332+
{
333+
name: "AGENTS.md",
334+
path: "/tmp/AGENTS.md",
335+
missing: false,
336+
rawChars: 150,
337+
injectedChars: 100,
338+
truncated: true,
339+
},
340+
],
341+
bootstrapMaxChars: 120,
342+
bootstrapTotalMaxChars: 200,
343+
});
344+
const lines = formatBootstrapTruncationWarningLines({ analysis });
345+
346+
expect(lines).toContain(
347+
"AGENTS.md was truncated; read the full AGENTS.md before relying on scoped policy.",
348+
);
349+
});
350+
329351
it("disambiguates duplicate file names in warning lines", () => {
330352
const analysis = analyzeBootstrapBudget({
331353
files: [
@@ -390,6 +412,7 @@ describe("bootstrap prompt warnings", () => {
390412
expect(always.warningShown).toBe(true);
391413
expect(always.lines).toStrictEqual([
392414
"AGENTS.md: 150 raw -> 100 injected (~33% removed; max/file).",
415+
"AGENTS.md was truncated; read the full AGENTS.md before relying on scoped policy.",
393416
"If unintentional, raise agents.defaults.bootstrapMaxChars and/or agents.defaults.bootstrapTotalMaxChars.",
394417
]);
395418
});

src/agents/bootstrap-budget.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function formatWarningCause(cause: BootstrapTruncationCause): string {
6868
return cause === "per-file-limit" ? "max/file" : "max/total";
6969
}
7070

71+
function isAgentsBootstrapName(name: string): boolean {
72+
return name.toLowerCase() === "agents.md";
73+
}
74+
7175
function normalizeSeenSignatures(signatures?: string[]): string[] {
7276
if (!Array.isArray(signatures) || signatures.length === 0) {
7377
return [];
@@ -293,6 +297,9 @@ export function formatBootstrapTruncationWarningLines(params: {
293297
`+${params.analysis.truncatedFiles.length - topFiles.length} more truncated file(s).`,
294298
);
295299
}
300+
if (params.analysis.truncatedFiles.some((file) => isAgentsBootstrapName(file.name))) {
301+
lines.push("AGENTS.md was truncated; read the full AGENTS.md before relying on scoped policy.");
302+
}
296303
lines.push(
297304
"If unintentional, raise agents.defaults.bootstrapMaxChars and/or agents.defaults.bootstrapTotalMaxChars.",
298305
);

src/agents/pi-embedded-helpers/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function buildAgentsPolicyDigest(content: string, budget: number): PolicyDigest
207207

208208
const lines = candidates
209209
.filter((candidate) => selected.has(candidate.index))
210-
.sort((a, b) => a.index - b.index)
210+
.toSorted((a, b) => a.index - b.index)
211211
.map((candidate) => candidate.line);
212212
return {
213213
text: lines.join("\n"),

0 commit comments

Comments
 (0)