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:
@@ -85,6 +85,17 @@ describe("trimTriggeringComments", () => {
|
|||||||
expect(trimTriggeringComments(lines, "default")).toEqual(["t3", "t4", "t5"]);
|
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", () => {
|
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 lines = ["h1", "h2", `A${"z".repeat(600)}`, `B${"z".repeat(600)}`, `C${"z".repeat(600)}`];
|
||||||
const trimmed = trimTriggeringComments(lines, "default");
|
const trimmed = trimTriggeringComments(lines, "default");
|
||||||
|
|||||||
@@ -30,16 +30,22 @@ export function trimPromptMd(prompt: string | undefined, template: HeartbeatProm
|
|||||||
return truncate(prompt, PROMPT_MD_CAP[template], TASK_TRUNCATION_MARKER);
|
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[] {
|
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;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selected = lines.slice(-3);
|
const selected = body.slice(-3);
|
||||||
const joined = selected.join("\n");
|
const joined = selected.join("\n");
|
||||||
if (joined.length <= 500) {
|
if (joined.length <= 500) {
|
||||||
return selected;
|
return [...headings, ...selected];
|
||||||
}
|
}
|
||||||
const truncated = truncate(joined, 500, COMMENTS_TRUNCATION_MARKER);
|
const truncated = truncate(joined, 500, COMMENTS_TRUNCATION_MARKER);
|
||||||
return truncated.split("\n");
|
return [...headings, ...truncated.split("\n")];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user