From 29afaf527c2015abaf09aec4e119939ea5acb7a6 Mon Sep 17 00:00:00 2001 From: ismeth Date: Thu, 12 Feb 2026 14:32:23 +0100 Subject: [PATCH] feat(05-01): add Atlas and Prometheus delegation prompt builders - Build pure prompt constructors with confirmed finding context and agreement levels - Add BDD tests for fix/planning intent, question context, and single-finding edge cases --- src/agents/athena/delegation-prompts.test.ts | 125 +++++++++++++++++++ src/agents/athena/delegation-prompts.ts | 55 ++++++++ src/agents/athena/index.ts | 2 + 3 files changed, 182 insertions(+) create mode 100644 src/agents/athena/delegation-prompts.test.ts create mode 100644 src/agents/athena/delegation-prompts.ts diff --git a/src/agents/athena/delegation-prompts.test.ts b/src/agents/athena/delegation-prompts.test.ts new file mode 100644 index 00000000..3d8e850d --- /dev/null +++ b/src/agents/athena/delegation-prompts.test.ts @@ -0,0 +1,125 @@ +import { describe, expect, test } from "bun:test" +import type { SynthesizedFinding } from "./synthesis-types" +import { buildAtlasDelegationPrompt, buildPrometheusDelegationPrompt } from "./delegation-prompts" + +function createConfirmedFindings(): SynthesizedFinding[] { + return [ + { + summary: "Guard missing council config in startup", + details: "Athena path can proceed with undefined council members in some flows.", + agreementLevel: "unanimous", + reportedBy: ["OpenAI", "Claude", "Gemini"], + assessment: { + agrees: true, + rationale: "Directly observed from startup and config fallback paths.", + }, + isFalsePositiveRisk: false, + }, + { + summary: "Potential retry thrash in background runner", + details: "Repeated failures can cascade retry windows under high load.", + agreementLevel: "minority", + reportedBy: ["Claude"], + assessment: { + agrees: true, + rationale: "Worth addressing to lower operational risk.", + }, + isFalsePositiveRisk: false, + }, + ] +} + +describe("buildAtlasDelegationPrompt", () => { + //#given confirmed findings and an original question + //#when the Atlas delegation prompt is built + //#then it includes both findings and the original question context + test("includes confirmed findings summaries and original question", () => { + const findings = createConfirmedFindings() + const question = "Which issues should we fix first in Athena integration?" + + const prompt = buildAtlasDelegationPrompt(findings, question) + + expect(prompt).toContain("Original question") + expect(prompt).toContain(question) + expect(prompt).toContain("Guard missing council config in startup") + expect(prompt).toContain("Potential retry thrash in background runner") + }) + + //#given confirmed findings + //#when Atlas prompt is generated + //#then it explicitly asks Atlas to fix those specific issues + test("instructs Atlas to implement direct fixes", () => { + const prompt = buildAtlasDelegationPrompt(createConfirmedFindings(), "Fix Athena reliability issues") + + expect(prompt).toContain("Fix these confirmed issues directly") + expect(prompt).toContain("Implement code changes") + expect(prompt).toContain("prioritize by agreement level") + }) + + //#given a single confirmed finding + //#when Atlas prompt is generated + //#then prompt still renders correctly for edge case input + test("handles a single finding edge case", () => { + const [singleFinding] = createConfirmedFindings() + + const prompt = buildAtlasDelegationPrompt([singleFinding], "Fix this one issue") + + expect(prompt).toContain("1. Guard missing council config in startup") + expect(prompt).toContain("Agreement level: unanimous") + }) +}) + +describe("buildPrometheusDelegationPrompt", () => { + //#given confirmed findings and an original question + //#when the Prometheus delegation prompt is built + //#then it includes both findings and the original question context + test("includes confirmed findings summaries and original question", () => { + const findings = createConfirmedFindings() + const question = "How should we sequence Athena integration hardening work?" + + const prompt = buildPrometheusDelegationPrompt(findings, question) + + expect(prompt).toContain("Original question") + expect(prompt).toContain(question) + expect(prompt).toContain("Guard missing council config in startup") + expect(prompt).toContain("Potential retry thrash in background runner") + }) + + //#given confirmed findings + //#when Prometheus prompt is generated + //#then it explicitly asks for phased planning and prioritization + test("instructs Prometheus to create an execution plan", () => { + const prompt = buildPrometheusDelegationPrompt(createConfirmedFindings(), "Plan Athena stabilization") + + expect(prompt).toContain("Create an execution plan") + expect(prompt).toContain("phased implementation plan") + expect(prompt).toContain("prioritize by agreement level and impact") + }) + + //#given a single confirmed finding + //#when Prometheus prompt is generated + //#then prompt still renders correctly for edge case input + test("handles a single finding edge case", () => { + const [singleFinding] = createConfirmedFindings() + + const prompt = buildPrometheusDelegationPrompt([singleFinding], "Plan this one issue") + + expect(prompt).toContain("1. Guard missing council config in startup") + expect(prompt).toContain("Agreement level: unanimous") + }) + + //#given findings at multiple agreement levels + //#when either delegation prompt is generated + //#then each finding includes agreement level context + test("includes agreement level context for each finding in both prompts", () => { + const findings = createConfirmedFindings() + + const atlasPrompt = buildAtlasDelegationPrompt(findings, "Atlas context") + const prometheusPrompt = buildPrometheusDelegationPrompt(findings, "Prometheus context") + + expect(atlasPrompt).toContain("Agreement level: unanimous") + expect(atlasPrompt).toContain("Agreement level: minority") + expect(prometheusPrompt).toContain("Agreement level: unanimous") + expect(prometheusPrompt).toContain("Agreement level: minority") + }) +}) diff --git a/src/agents/athena/delegation-prompts.ts b/src/agents/athena/delegation-prompts.ts new file mode 100644 index 00000000..81cd302b --- /dev/null +++ b/src/agents/athena/delegation-prompts.ts @@ -0,0 +1,55 @@ +import type { SynthesizedFinding } from "./synthesis-types" + +function formatFindingBlock(finding: SynthesizedFinding, index: number): string { + const assessment = finding.assessment.agrees ? "Agrees" : "Disagrees" + + return [ + `${index + 1}. ${finding.summary}`, + ` Details: ${finding.details}`, + ` Agreement level: ${finding.agreementLevel}`, + ` Athena assessment: ${assessment}`, + ` Rationale: ${finding.assessment.rationale}`, + ].join("\n") +} + +function formatConfirmedFindings(confirmedFindings: SynthesizedFinding[]): string { + return confirmedFindings.map((finding, index) => formatFindingBlock(finding, index)).join("\n\n") +} + +export function buildAtlasDelegationPrompt(confirmedFindings: SynthesizedFinding[], question: string): string { + return [ + "# Atlas Delegation Brief", + "Original question:", + question, + "", + "Task:", + "Fix these confirmed issues directly.", + "", + "Confirmed findings:", + formatConfirmedFindings(confirmedFindings), + "", + "Execution instructions:", + "- Implement code changes to resolve each confirmed issue.", + "- prioritize by agreement level, addressing unanimous findings first.", + "- Validate fixes with relevant tests and type safety checks.", + ].join("\n") +} + +export function buildPrometheusDelegationPrompt(confirmedFindings: SynthesizedFinding[], question: string): string { + return [ + "# Prometheus Delegation Brief", + "Original question:", + question, + "", + "Task:", + "Create an execution plan for these confirmed issues.", + "", + "Confirmed findings:", + formatConfirmedFindings(confirmedFindings), + "", + "Planning instructions:", + "- Produce a phased implementation plan with clear task boundaries.", + "- prioritize by agreement level and impact.", + "- Include verification checkpoints for each phase.", + ].join("\n") +} diff --git a/src/agents/athena/index.ts b/src/agents/athena/index.ts index 4ddaaf57..694c0449 100644 --- a/src/agents/athena/index.ts +++ b/src/agents/athena/index.ts @@ -7,4 +7,6 @@ export * from "./council-result-collector" export * from "./synthesis-types" export * from "./synthesis-prompt" export * from "./synthesis-formatter" +export * from "./findings-presenter" +export * from "./delegation-prompts" export * from "../../config/schema/athena"