/**
* Visualization — system prompt builder (Std 5, cost-appropriate
* prompts inherited from Pillar 2). Same scoped-prompt machinery
* as every other agent. In the foundational rule set the
* Visualization agent never calls the LLM (rule.action is structured
* and applied deterministically), but the builder exists for future
* SME-encoded rules that genuinely require LLM judgment.
*/
import { STANDARDS_SUMMARY, type PromptScope } from '../../../standards.js';
import {
AGENT_NAME,
AGENT_VERSION,
visualizationContract,
visualizationMatrix,
} from './matrix.js';
interface OpPrinciple { readonly n: number; readonly text: string; }
const OPERATING_PRINCIPLES: readonly OpPrinciple[] = [
{ n: 1, text: 'render only. Do NOT re-interpret findings, do NOT deliver — those are siblings\' jobs.' },
{ n: 3, text: 'every visualization choice traces to a declared visualization rule; record which rule.' },
{ n: 4, text: 'never misrepresent data via scaling, aggregation, color, or narrative claims. Spec fields must bind to real recommendation fields.' },
{ n: 5, text: 'query find_rules(type="visualization", agent="visualization") with the recommendation\'s suggestedActionCategory and audienceTier as triggers.' },
{ n: 6, text: 'cost-appropriate execution: most visualization rules apply deterministically (rule.action is structured). LLM only when a rule explicitly requires judgment to construct the specification.' },
{ n: 7, text: 'per-visualization confidence inherits from the recommendation; rule.confidence_framework declares adjustments.' },
{ n: 8, text: 'flag disclosure-policy concerns and material-impact carry-through explicitly.' },
{ n: 9, text: 'escalations route to compliance-reviewer (disclosure concerns), domain-expert (rule gaps), authorizing-decision-maker (material findings).' },
{ n: 0, text: 'Decision-forbidden: do not re-analyze findings, do not embed a charting library (downstream renderer\'s job), do not bypass disclosure policies, do not deliver.' },
];
function renderUniversal(engaged?: readonly number[]): string {
const set = engaged && engaged.length > 0 ? new Set(engaged) : null;
return STANDARDS_SUMMARY
.filter(s => !set || set.has(s.n))
.map(s => `${s.n}. ${s.name} — ${s.gist}`)
.join('\n');
}
function renderMatrix(): string {
return Object.entries(visualizationMatrix)
.map(([key, value]) => `${key.split('_')[0]}. ${value}`)
.join('\n');
}
function renderRunbook(): string {
return visualizationContract.runbook
.map(s => ` ${s.n}. ${s.name} — ${s.description}`)
.join('\n');
}
function renderPrinciples(engaged?: readonly number[]): string {
const set = engaged && engaged.length > 0 ? new Set(engaged) : null;
return OPERATING_PRINCIPLES
.filter(p => p.n === 0 || !set || set.has(p.n))
.map(p => (p.n === 0 ? `- ${p.text}` : `- Std ${p.n}: ${p.text}`))
.join('\n');
}
export function buildSystemPrompt(scope?: PromptScope): string {
const engaged = scope?.engagedStandards;
const isScoped = !!(engaged && engaged.length > 0);
const omitMatrix = scope?.omitMatrix ?? isScoped;
const omitRunbook = scope?.omitRunbook ?? isScoped;
const lines: string[] = [
`You are the ${AGENT_NAME} agent (v${AGENT_VERSION}) — the second agent of the BID Decision pillar.`,
];
if (isScoped) {
lines.push(
`All 12 universal operational standards govern your behavior. ` +
(scope?.stepLabel ? `Current step: "${scope.stepLabel}". ` : '') +
`Standards directly engaged by this step:`,
renderUniversal(engaged),
);
} else {
lines.push(
`Your operation is bounded by the 12 universal operational standards plus your per-agent matrix row.`,
``,
`## Universal standards`,
renderUniversal(),
);
}
if (!omitMatrix) {
lines.push(``, `## Your matrix row`, renderMatrix());
}
if (!omitRunbook) {
lines.push(``, `## Your runbook (Std 6)`, renderRunbook());
}
lines.push(``, `## Operating principles`, renderPrinciples(engaged));
return lines.join('\n');
}