import { readFile } from 'node:fs/promises'; import { existsSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; export interface VideoPromptReference { name: string; category: 'provider' | 'framework'; summary: string; file: string; } const REFERENCE_REGISTRY: VideoPromptReference[] = [ { name: 'seedance-ugc-formulas', category: 'provider', summary: 'Seedance formulas for UGC-style and character-led prompting.', file: 'seedance-ugc-formulas.md', }, { name: 'veo-prompting-guide', category: 'provider', summary: 'Prompt structure and execution guidance for local Veo usage.', file: 'veo-prompting-guide.md', }, { name: 'style-template-schema', category: 'framework', summary: 'Schema guidance for reusable style/template assets.', file: 'style-template-schema.md', }, { name: 'stage-directors', category: 'framework', summary: 'Operational stage guidance for brief, storyboard, assets, review, and publish.', file: 'stage-directors.md', }, { name: 'checkpoint-protocol', category: 'framework', summary: 'Checkpoint rules for explicit, artifact-based progression.', file: 'checkpoint-protocol.md', }, { name: 'generation-telemetry', category: 'framework', summary: 'Rules for recording route, cost, duration, and output telemetry after generation.', file: 'generation-telemetry.md', }, { name: 'dialogue-duration-preflight', category: 'framework', summary: 'Dialogue timing budgets for short clips and director-mode preflight.', file: 'dialogue-duration-preflight.md', }, { name: 'character-reference-sheet', category: 'framework', summary: 'Reference-sheet coverage guidance for stable character identity.', file: 'character-reference-sheet.md', }, { name: 'clone-ad-template-workflow', category: 'framework', summary: 'Reference-ad analysis dimensions for reusable clone plans.', file: 'clone-ad-template-workflow.md', }, { name: 'multi-shot-framework', category: 'framework', summary: 'Compressed timecoded multi-shot cinematic prompt builder (cinematic-15s preset).', file: 'multi-shot-framework.md', }, ]; function referencesDir(root = process.cwd()): string { // Prefer a copy under the caller's workspace/cwd; fall back to the copy bundled // in the installed npm package (dist/video/ -> package root) so `prompt-lib-show` // works for anyone who installed the package and runs from a different directory. const cwdDir = join(resolve(root), 'references', 'video'); if (existsSync(cwdDir)) return cwdDir; const packaged = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', 'references', 'video'); return existsSync(packaged) ? packaged : cwdDir; } export function listPromptReferences(): VideoPromptReference[] { return [...REFERENCE_REGISTRY]; } export async function readPromptReference( name: string, root = process.cwd(), ): Promise<(VideoPromptReference & { content: string }) | null> { const entry = REFERENCE_REGISTRY.find((reference) => reference.name === name); if (!entry) return null; const path = join(referencesDir(root), entry.file); if (!existsSync(path)) return null; const content = await readFile(path, 'utf-8'); return { ...entry, content, }; }