#!/usr/bin/env bun /** * product-demo-script * Generates structured product demo scripts using OpenAI. */ import { parseArgs } from "util"; import { existsSync, mkdirSync, appendFileSync, readFileSync } from "fs"; import { join, dirname, resolve } from "path"; type OutputFormat = "markdown" | "json"; type StoryArc = "problem-solution" | "before-after" | "jobs-to-be-done"; type PresenterTone = "confident" | "friendly" | "energetic"; type DemoTemplate = { key_features?: Array>; audience_pains?: Array>; stories?: Array>; objections?: Array>; proof_points?: Array>; notes?: string; }; interface SkillOptions { brief: string; audience?: string; duration?: string; storyArc: StoryArc; tone: PresenterTone; format: OutputFormat; model: string; output?: string; template?: DemoTemplate; } interface OpenAIChatResponse { choices?: Array<{ message?: { content?: string | null; }; }>; error?: { message?: string; }; } const SKILL_SLUG = "product-demo-script"; function ensureDir(path: string) { if (!existsSync(path)) { mkdirSync(path, { recursive: true }); } } function getPaths() { const sessionStamp = new Date().toISOString().replace(/[:.]/g, "_").replace(/-/g, "_"); const exportsRoot = process.env.SKILLS_EXPORTS_DIR || join(process.cwd(), ".skills", "exports"); const logsRoot = process.env.SKILLS_LOGS_DIR || join(process.cwd(), ".skills", "logs"); const skillExportsDir = join(exportsRoot, SKILL_SLUG); const skillLogsDir = join(logsRoot, SKILL_SLUG); ensureDir(skillExportsDir); ensureDir(skillLogsDir); return { sessionStamp, skillExportsDir, skillLogsDir, }; } function createLogger(logDir: string, sessionStamp: string) { const logFile = join(logDir, `log_${sessionStamp}.txt`); function write(level: "info" | "success" | "error", message: string) { const timestamp = new Date().toISOString(); const entry = `[${timestamp}] [${level.toUpperCase()}] ${message}\n`; appendFileSync(logFile, entry); const prefix = level === "success" ? "✅" : level === "error" ? "❌" : "â„šī¸"; console.log(`${prefix} ${message}`); } return { info: (message: string) => write("info", message), success: (message: string) => write("success", message), error: (message: string) => write("error", message), logFile, }; } function slugify(value: string): string { return value .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .slice(0, 40) || "demo-script"; } function parseJsonTemplate(content: string): DemoTemplate | undefined { try { const data = JSON.parse(content); if (typeof data === "object" && data !== null) { return data as DemoTemplate; } } catch (_error) { // treat as plain text if parsing fails } return undefined; } function showHelp(): void { console.log(` product-demo-script - Generate structured product demo scripts using AI Usage: skills run product-demo-script -- [options] skills run product-demo-script -- --text "" [options] Options: -h, --help Show this help message --text Inline product/demo brief --audience Target audience (default: executive audience) --duration