fix(FN-4400): preserve triggering comment headings in trim helper

Fusion-Task-Id: FN-4400
Fusion-Task-Lineage: 0d4f9c48-5b8b-49eb-9cf3-d1d585ffe7fc
This commit is contained in:
Fusion
2026-05-14 03:45:09 -07:00
committed by gsxdsm
parent 5c9a1b0463
commit 146f0668ca
2 changed files with 21 additions and 4 deletions

View File

@@ -85,6 +85,17 @@ describe("trimTriggeringComments", () => {
expect(trimTriggeringComments(lines, "default")).toEqual(["t3", "t4", "t5"]);
});
it("preserves heading lines while trimming comment body", () => {
const headings = [
"",
"You were woken because of new comments on this task. Review them and take appropriate action.",
"Triggering comment type: task",
"New comments since last run:",
];
const lines = [...headings, "c1", "c2", "c3", "c4", "c5"];
expect(trimTriggeringComments(lines, "compact")).toEqual([...headings, "c3", "c4", "c5"]);
});
it("caps joined body at 500 chars and appends marker", () => {
const lines = ["h1", "h2", `A${"z".repeat(600)}`, `B${"z".repeat(600)}`, `C${"z".repeat(600)}`];
const trimmed = trimTriggeringComments(lines, "default");

View File

@@ -30,16 +30,22 @@ export function trimPromptMd(prompt: string | undefined, template: HeartbeatProm
return truncate(prompt, PROMPT_MD_CAP[template], TASK_TRUNCATION_MARKER);
}
const TRIGGERING_COMMENT_HEADING = "New comments since last run:";
export function trimTriggeringComments(lines: string[], _template: HeartbeatPromptTemplate): string[] {
if (lines.length <= 3) {
const headingIndex = lines.indexOf(TRIGGERING_COMMENT_HEADING);
const headings = headingIndex >= 0 ? lines.slice(0, headingIndex + 1) : [];
const body = headingIndex >= 0 ? lines.slice(headingIndex + 1) : lines;
if (body.length <= 3) {
return lines;
}
const selected = lines.slice(-3);
const selected = body.slice(-3);
const joined = selected.join("\n");
if (joined.length <= 500) {
return selected;
return [...headings, ...selected];
}
const truncated = truncate(joined, 500, COMMENTS_TRUNCATION_MARKER);
return truncated.split("\n");
return [...headings, ...truncated.split("\n")];
}