/** * Prompt composer. The base is the OD-adapted "expert designer" system * prompt (see ./official-system.ts) — a full identity, workflow, and * content-philosophy charter. Stacked on top: * * 1. The discovery + planning + huashu-philosophy layer (./discovery.ts) * — interactive question-form syntax, direction-picker fork, * brand-spec extraction, TodoWrite reinforcement, 5-dim critique, * and the embedded `directions.ts` library. * 2. The active design system's DESIGN.md (if any) — palette, typography, * spacing rules treated as authoritative tokens. * 3. The active skill's SKILL.md (if any) — workflow specific to the * kind of artifact being built. When the skill ships a seed * (`assets/template.html`) and references (`references/layouts.md`, * `references/checklist.md`), we inject a hard pre-flight rule above * the skill body so the agent reads them BEFORE writing any code. * 4. For decks (skillMode === 'deck' OR metadata.kind === 'deck'), the * deck framework directive (./deck-framework.ts) is pinned LAST so it * overrides any softer slide-handling wording earlier in the stack — * this is the load-bearing nav / counter / scroll JS / print * stylesheet contract that PDF stitching depends on. We also fire on * the metadata path so deck-kind projects without a bound skill * (skill_id null) still get a framework, instead of having the agent * re-author scaling / nav / print logic from scratch each turn. When * the active skill ships its own seed (skill body references * `assets/template.html`), we defer to that seed and skip the generic * skeleton — the skill's framework wins to avoid double-injection. * * The composed string is what the daemon sees as `systemPrompt` and what * the Anthropic path sends as `system`. */ import { OFFICIAL_DESIGNER_PROMPT } from './official-system.js'; import { DISCOVERY_AND_PHILOSOPHY } from './discovery.js'; import { DECK_FRAMEWORK_DIRECTIVE } from './deck-framework.js'; import { MEDIA_GENERATION_CONTRACT } from './media-contract.js'; import { IMAGE_MODELS } from '../media-models.js'; import { renderPanelPrompt } from './panel.js'; import { defaultCritiqueConfig, type CritiqueConfig } from '@open-design/contracts/critique'; const ELEVENLABS_VOICE_PROMPT_OPTION_LIMIT = 100; const ELEVENLABS_VOICE_OPTIONS_PROMPT_PREFIX = 'ElevenLabs voice list could not be loaded'; const PROMPT_SAFE_HTTP_STATUS_LABELS: Record = { '400': 'Bad Request', '401': 'Unauthorized', '403': 'Forbidden', '404': 'Not Found', '429': 'Too Many Requests', '500': 'Internal Server Error', '502': 'Bad Gateway', '503': 'Service Unavailable', '504': 'Gateway Timeout', }; function normalizePromptText(value: string): string { return value .replace(/[\r\n]+/g, ' ') .replace(/\s+/g, ' ') .trim(); } function formatElevenLabsVoiceOptionsErrorForPrompt( error: string | undefined, ): string | undefined { const trimmed = normalizePromptText(error ?? ''); if (!trimmed) return undefined; if (/no ElevenLabs API key/i.test(trimmed)) { return `${ELEVENLABS_VOICE_OPTIONS_PROMPT_PREFIX} because the ElevenLabs API key is missing. Tell the user to configure it in Settings or paste a voice id manually.`; } const statusMatch = trimmed.match( /(?:\((\d{3})(?:\s+([^)]+))?\)|\b(\d{3})(?:\s+([A-Za-z][A-Za-z -]{0,40}))?\b)/, ); if (statusMatch) { const statusCode = statusMatch[1] ?? statusMatch[3]; const statusText = statusCode ? PROMPT_SAFE_HTTP_STATUS_LABELS[statusCode] ?? '' : ''; const suffix = statusText ? ` ${statusText}` : ''; return `${ELEVENLABS_VOICE_OPTIONS_PROMPT_PREFIX} (${statusCode}${suffix}). Tell the user to retry the lookup or paste a voice id manually.`; } return `${ELEVENLABS_VOICE_OPTIONS_PROMPT_PREFIX}. Tell the user to retry the lookup or paste a voice id manually.`; } type ProjectMetadata = { kind?: string; intent?: string | null; fidelity?: string | null; speakerNotes?: boolean | null; animations?: boolean | null; includeLandingPage?: boolean | null; includeOsWidgets?: boolean | null; templateId?: string | null; templateLabel?: string | null; platform?: string | null; platformTargets?: string[] | null; inspirationDesignSystemIds?: string[]; skipDiscoveryBrief?: boolean | null; imageModel?: string | null; imageAspect?: string | null; imageStyle?: string | null; videoModel?: string | null; videoLength?: number | null; videoAspect?: string | null; audioKind?: string | null; audioModel?: string | null; audioDuration?: number | null; voice?: string | null; promptTemplate?: { id?: string | null; surface?: 'image' | 'video' | null; title?: string | null; prompt?: string | null; summary?: string | null; category?: string | null; tags?: string[] | null; model?: string | null; aspect?: string | null; source?: { repo?: string | null; license?: string | null; author?: string | null; url?: string | null; } | null; } | null; contextPlugins?: Array<{ id?: string | null; title?: string | null; description?: string | null; }> | null; contextMcpServers?: Array<{ id?: string | null; label?: string | null; transport?: string | null; url?: string | null; command?: string | null; }> | null; contextConnectors?: Array<{ id?: string | null; name?: string | null; provider?: string | null; category?: string | null; status?: string | null; accountLabel?: string | null; }> | null; }; type ProjectTemplate = { name: string; description?: string | null; files: Array<{ name: string; content: string }> }; type AudioVoiceOption = { name: string; voiceId: string; category?: string | null; labels?: Record | null; }; export const BASE_SYSTEM_PROMPT = OFFICIAL_DESIGNER_PROMPT; export const SKIP_DISCOVERY_BRIEF_OVERRIDE = `# Automated project mode — skip discovery form This project was created through the daemon API with \`skipDiscoveryBrief: true\`. Override the discovery rules below: do NOT emit \`\`, do NOT show "Quick brief — 30 seconds", and do NOT ask a first-turn clarification form. Treat the user's first message and project metadata as the brief, then proceed directly to planning/building under the normal artifact workflow. Ask at most one concise follow-up only if a required detail is impossible to infer safely.`; const ACTIVE_DESIGN_SYSTEM_VISUAL_DIRECTION_OVERRIDE = ` --- ## Active design system visual direction Active design system exception: the active design system is the visual direction for this project. Use its DESIGN.md palette, typography, spacing, component rules, and theme tokens as the source of truth for color and mood. - Do not ask the user to pick a separate theme color, visual direction, palette, typography mood, or direction card. - Do not emit a direction question-form, a \`direction-cards\` picker, or any visual-direction card while an active design system is present. - If an earlier discovery answer asks to "Pick a direction for me", treat that as already satisfied by the active design system and continue with the plan. - When a downstream framework mentions "active direction" or "theme tokens", bind those fields from the active design system instead of the built-in direction library. `; const DEFAULT_DESIGN_SYSTEM_USAGE = `Read DESIGN.md for visual principles, paste tokens.css verbatim into the first