OR Key
drop another .md file to compare - side-by-side diff against voice

voice

Turns your text into natural, expressive spoken audio.
description: "Triggers on prompt mention of 'voice'."
personal 2 files 9 recent evals

What it does for you

Turns your text into natural, expressive spoken audio.

What it produces

A recent result, so you can see the kind of work it returns.

loading…

How to get it

These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.

Work with me
For developers how this skill is built, graded, and how it runs

at a glance- the short version

eval modeauto-shape
categorySystem
stages4
dependsopenrouter, elevenlabs

what's inside - the parts that make up a skill 3/4 present

A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.

The skill
state/skills/voice/SKILL.md present
the skill itself, in plain text
The main file. It says what the skill is and lays out the steps in plain English.
Code
state/lib/voice.ts present
code the skill can run
Reusable code this skill can call when it needs to.
Scripts
state/bin/voice/ not present
helper scripts
Optional. Added when a skill has a few commands to run.
Loader
state/skills/voice/AGENTS.md present
what the AI loads on the fly
Loaded automatically the moment this skill is needed. Kept short on purpose.

how it runs - the shared frame every skill uses 3/5 present

Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.

makes the work The worker
inferred
POST http://127.0.0.1:3147/voice/speak` — from the run command
No worker is named directly, so the command this skill runs is treated as the worker.
checks the work The reviewer
inferred
shape gate an automatic check
The check is an automatic pass or fail on the shape of the result, run separately from the work itself.
frame
learns Self-correction
present
fixes itself learns from gaps
When a run hits a gap, the skill gets edited on the spot [FIXED] or queued for a bigger rewrite [LOGGED], so it keeps getting better.
tidies up Background fixes
present
queued for rewrite runs in the background
Bigger fixes that can't be made on the spot get queued and rewritten in the background later.
remembers Run history
present
state/log/evals.ndjson unknown runs
Every run is written down here, so the next time this skill is used it already knows how the last runs went.
Critical rules the things this skill must not get wrong
  1. TTS calls bill per character. POST http://127.0.0.1:3147/voice/speak hits
  2. state/lib/voice.ts is the tone-gate / citation-gate library — NOT the
  3. Without OPENROUTER_API_KEY the enhancer silently skips and the audio

what it has learned - fixes written back in over time sample

When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.

  1. Loading feedback rows…

how the work flows- step by step

inputs openrouterelevenlabs
1 control
Scope — no side effects
Decide tone + length based on the message's intent, not just content:
what this step does
Decide tone + length based on the message's intent, not just content: - **professional** for status updates, build results, neutral notifications - **sultry** for one-off flirty/atmospheric moments (use sparingly) - **hype** for shipping news, deploy success, big wins - **calm** for narration, recap, end-of-session summary Length: - **minimal** — 1–3 words ("Done.") - **short** — under 10 words - **normal** — 1–2 sentences (default) - **verbose** — 2–3 sentences, conversation
2 stage
Gate
Two creds must exist in .env.cache:
ELEVENLABS_API_KEY=sk_...
what this step does
Two creds must exist in .env.cache: Without ELEVENLABS_API_KEY → 503. Without OPENROUTER_API_KEY → enhancement silently skips, raw text goes to ElevenLabs (still works, just sounds flatter).
3 stage
Act
```bash
curl -sS -X POST http://127.0.0.1:3147/voice/speak \
what this step does
In the snappy-shell SwiftUI app: DataClient.voiceSpeak(text:) POSTs and returns the bytes. SpeechPlayer.play(_:) hands them to AVAudioPlayer with a tmp-file fallback for MP3 ADTS streams the in-memory init refuses.
4 generator
Log + eval
The endpoint writes one row per call to state/log/voice-speak.ndjson:
what this step does
The endpoint writes one row per call to state/log/voice-speak.ndjson: Score 1.0 if enhanced: true AND bytes > 5000 (real audio). Score 0.5 if enhanced: false (raw fallback fired). Score 0.0 if ok: false.

SKILL.md- the skill, written out in plain English

voice

Three-layer pipeline; the realism is from layer 2:

raw text → Gemini-3-Flash (tag enhancer) → ElevenLabs eleven_v3 → audio/mpeg

Without enhancement you get flat TTS. Without eleven_v3 the audio tags get spoken aloud as "open bracket happy close bracket" instead of being interpreted.

Ported from Robert's Sloane × ElevenLabs recipe. The recipe is the long-form reference; this skill is the per-turn loader.

Endpoint

POST http://127.0.0.1:3147/voice/speak
Body: {
  "text": "raw text",
  "voiceId"?: "cgSgspJ2msm6clMCkdW9",   // default: Jessica (warm British)
  "modelId"?: "eleven_v3",              // default: eleven_v3 (tags work)
  "tone"?: "professional",              // professional|sultry|hype|calm
  "length"?: "normal",                  // minimal|short|normal|verbose
  "enhance"?: true,                     // default true; false bypasses Gemini
  "voiceSettings"?: { ... }             // overrides tone preset if given
}
Response: audio/mpeg
Headers: x-snappy-voice-enhanced: 0|1, x-snappy-voice-tone, x-snappy-voice-id

Steps

1. Scope - no side effects

Decide tone + length based on the message's intent, not just content:

  • professional for status updates, build results, neutral notifications
  • sultry for one-off flirty/atmospheric moments (use sparingly)
  • hype for shipping news, deploy success, big wins
  • calm for narration, recap, end-of-session summary

Length:

  • minimal - 1-3 words ("Done.")
  • short - under 10 words
  • normal - 1-2 sentences (default)
  • verbose - 2-3 sentences, conversational

2. Gate

Two creds must exist in .env.cache:

ELEVENLABS_API_KEY=sk_...
OPENROUTER_API_KEY=sk-or-v1-...   # for the enhancement step

Without ELEVENLABS_API_KEY → 503. Without OPENROUTER_API_KEY → enhancement silently skips, raw text goes to ElevenLabs (still works, just sounds flatter).

3. Act

curl -sS -X POST http://127.0.0.1:3147/voice/speak \
  -H "Content-Type: application/json" \
  -d '{"text":"the build is green","tone":"professional","length":"short"}' \
  -o /tmp/out.mp3 && afplay /tmp/out.mp3

In the snappy-shell SwiftUI app: DataClient.voiceSpeak(text:) POSTs and returns the bytes. SpeechPlayer.play(_:) hands them to AVAudioPlayer with a tmp-file fallback for MP3 ADTS streams the in-memory init refuses.

4. Log + eval

The endpoint writes one row per call to state/log/voice-speak.ndjson:

{
  "ts": "2026-04-25T22:57:24Z",
  "voiceId": "cgSgspJ2msm6clMCkdW9",
  "modelId": "eleven_v3",
  "tone": "professional",
  "length": "short",
  "enhanced": true,
  "raw_chars": 41,
  "chars": 65,
  "durationMs": 3564,
  "bytes": 88233,
  "ok": true
}

Score 1.0 if enhanced: true AND bytes > 5000 (real audio). Score 0.5 if enhanced: false (raw fallback fired). Score 0.0 if ok: false.

Voice IDs (recipe §3)

SlugVoice IDCharacter
jessica (default)cgSgspJ2msm6clMCkdW9Warm, British
rachel21m00Tcm4TlvDq8ikWAMClear, professional
domiAZnzlk1XvdvUeBnXmlldConfident, assertive
bellaEXAVITQu4vr4xnSDxMaLSoft, gentle
charlotteXB0fDUnXU5powFXDhCwaSeductive, smooth
serenapMsXgVXv3BLzUgSXRplESoft, pleasant
graceoWAxZDx7w5VEj9dCyTzzSouthern, warm

Browse more: https://elevenlabs.io/voice-library

Tone presets (recipe §2)

Tonestabilitystylesimilarity_boost
professional0.50.00.75
sultry0.00.40.85
hype0.00.50.75
calm1.00.00.7

use_speaker_boost: true always.

Audio tags (recipe §5)

Use 1-3 emotion tags + at most 1 non-verbal sound + sparing timing tags.

Emotion: [happy] [sad] [angry] [excited] [confident] [playful] [serious] [whispered] [tender] [cheerful] [concerned] [amused]

Timing: [beat] (comedy), [dramatic pause] (tension), [quick], [slow]

Non-verbal: [sigh] [chuckle] [laughs] [satisfied sigh]

AVOID: environmental tags [rain] [thunder] [footsteps] - cause artifacts.

Known Pitfalls

  • Tags spoken aloud = wrong model. Verify modelId: "eleven_v3".
  • Voice sounds flat = enhancer skipped. Check x-snappy-voice-enhanced: 1

in response headers; check OPENROUTER_API_KEY is in .env.cache.

  • Sultry/hype sounds same as professional = stability not lowered.

TONE_PRESETS in the server handle this, but caller-supplied voiceSettings overrides - don't pass voiceSettings unless you mean it.

  • No audio plays in the macOS shell = AVAudioPlayer choking on MP3 ADTS.

SpeechPlayer's tmp-file fallback handles this - verify the tmp file gets written.

  • Enhancement adds latency (~3s round trip vs ~1s raw). For

status-bar-style notifications use enhance: false.

Self-Test

An agent reading this should correctly:

  1. [ ] Default to Jessica voice + eleven_v3 model + professional tone
  2. [ ] Pick tone based on message intent, not just content
  3. [ ] Bypass enhancement (enhance: false) when latency matters more than realism
  4. [ ] Read the response header x-snappy-voice-enhanced to verify enhancement fired

Self-report

If this loader fell short, append a line:

echo "[$(date -u +%FT%TZ)] voice: <what was missing>" >> state/log/loader-feedback.log

AGENTS.md- what the AI loads when this skill comes up

voice - loader

Per-turn rules for the voice skill. Full reference: state/skills/voice/SKILL.md. Do not skip these.

Critical Rules

  • TTS calls bill per character. POST http://127.0.0.1:3147/voice/speak hits

ElevenLabs (and OpenRouter for the enhancer). For scope-only / dry-run, do NOT invoke the endpoint - run a shape check instead (verify SKILL.md frontmatter, AGENTS.md, state/lib/voice.ts import) and score with eval_mode=shape. Real audio only when the user explicitly confirms apply: true.

  • state/lib/voice.ts is the tone-gate / citation-gate library - NOT the

TTS client. Don't expect a speak() export; use checkTone() / requireCitations(). The TTS pipeline lives behind the local HTTP server.

  • Without OPENROUTER_API_KEY the enhancer silently skips and the audio

sounds flat. Verify the response header x-snappy-voice-enhanced: 1 whenever realism matters.

Commands

| ui dashboard | state/skills/voice/resources/ui.openui | |invoke: POST http://127.0.0.1:3147/voice/speak - see state/skills/voice/SKILL.md for the body schema. Defaults: voiceId=Jessica (cgSgspJ2msm6clMCkdW9), modelId=eleven_v3, tone=professional, enhance=true. |tone-gate lib: state/lib/voice.ts (checkTone(text), requireCitations(draft) - pure, no network, safe to import for shape checks) |reference: state/skills/voice/SKILL.md |eval log: state/log/evals.ndjson (skill: "voice"); per-call telemetry also at state/log/voice-speak.ndjson

Self-Test

An agent reading this should correctly:

  1. [ ] Know which lib/bin artifact backs this skill (or that it is prose-only)
  2. [ ] Know what to write to state/log/evals.ndjson after invoking
  3. [ ] Know the eval mode (auto / shape / manual) from the .md frontmatter

Self-report

If this loader fell short, append a line:

echo "[$(date -u +%FT%TZ)] voice: <what was missing>" >> state/log/loader-feedback.log

<!-- kernel-ok: historical attribution for the PID-loader pattern. -->

Self-correcting loader (PID feedback)

This is the rule that makes loaders learn. Ported from snappy-kernel, where it demonstrably worked: the snappy-dom-cartographer skill mapped Skool admin UI once, every later ship-agent inherited the full map for free.

Before you finish, do two things:

1. Fix gaps (P - proportional). MANDATORY. If this loader didn't cover your case - if you had to read another file, run an undocumented command, work around a wrong selector, or discover a quirk - you MUST attempt an Edit to this AGENTS.md before you log.

  • Default action: edit this file. Surgical. Add the missing line, table

row, or code example where it belongs. No restructuring.

  • Only LOGGED is allowed when: the fix needs >10 lines, spans multiple

files, or requires a structural rewrite. In that case the state/regen/drain.sh queue picks it up asynchronously.

  • "I didn't have time" / "it's minor" / "the next agent will figure it out"

are NOT valid reasons. Minor gaps compound - that's the whole point of this loop.

  • Concrete example of a valid P-fix: discover agent-browser screenshot

takes path positionally not as --output <path>. One line in a table. Edit it in. Do not just log it.

  • The goal: the next agent never has to leave the loader.

2. Log the result.

echo "[$(date -u +%FT%TZ)] voice: <what was missing or fixed> [FIXED|LOGGED]" >> state/log/loader-feedback.log
  • FIXED = you patched this loader inline (P-fix).
  • LOGGED = too large for inline; the PostToolUse enqueue + Stop-hook drain

will rewrite the loader from scratch on next session-end.

Do not skip this. Every agent run must leave the system better than it found it. The loader is the setpoint; you are the sensor; the gap is the error signal; closing the gap is the correction.

OpenUI Resource

  • Skill-owned OpenUI Lang resource: state/skills/voice/resources/ui.openui. Read it before rendering or editing this skill's generated component surface.
  • Treat this resource as a first-class artifact of the skill, not a generic chat response. Improve it when the skill's user-facing output needs to become richer.
  • System resources compose OpenUI primitives and inherit SnappyChat tokens. Use ui_contract: branded in SKILL.md only for deliberate platform or client visuals.

api.ts- the code it can call

#!/usr/bin/env npx tsx
/**
 * state/lib/voice.ts -- Tone gate and citation gate for snappy-os.
 *
 * Ported from snappy-positioning/api.ts (kernel). Frozen snapshot —
 * reconcile manually at end-of-port comparison, not mid-week.
 *
 * checkTone(text) — banned phrases + rhythm-slop regex + em-dash gate.
 * requireCitations(draft) — forces mining pods to stitch verbatim with
 *   [source: mtg ~mm:ss] tags and wrap connective tissue in
 *   <connective>...</connective>. ≤35% connective ratio.
 *
 * This is the eval source for content-polish and any mining skill.
 * If this file drifts from the kernel copy, evals drift — do not edit
 * casually. See program.md §Voice.
 */

const BANNED_PHRASES: string[] = [
  "10x faster",
  "10x developer",
  "100x speed",
  "in minutes",
  "the operating system for",
  "the X for Y",
  "without the Z",
  "before you Q",
  "at the intersection of",
  "one-stop shop",
  "revolutionize",
  "revolutionary",
  "transform",
  "unleash",
  "unlock",
  "unlock the power of",
  "supercharge",
  "empower",
  "empowering",
  "leverage",
  "synergy",
  "game changer",
  "game-changing",
  "ultimate",
  "cutting edge",
  "bleeding edge",
  "next-gen",
  "next generation",
  "seamless",
  "seamlessly",
  "effortless",
  "effortlessly",
  "AI-powered",
  "AI-native",
  "agentic-first",
  "founder-led",
  "ship-ready",
  "vibe coding",
  "Snappy is",
  "feel confident",
  "feel in control",
  "feel unstuck",
  "my stack is opinionated",
  "i dog-food everything",
  "clear boxes, not black boxes",
  "delve",
  "showcase",
  "noteworthy",
  "multifaceted",
  "tapestry",
  "beacon",
  "meticulous",
  "intricate",
  "commendable",
  "paramount",
  "commence",
  "utilize",
  "robust",
  "streamline",
  "harness",
  "illuminate",
  "facilitate",
  "bolster",
  "underscore",
  "pivotal",
  "realm",
  "foster",
  "landscape",
  "paradigm",
  "ecosystem",
  "spearhead",
  "groundbreaking",
  "transformative",
  "game-changer",
  "elevate",
  "deep dive",
  "unpack",
  "in today's fast-paced",
  "it's worth noting",
  "here's where it gets interesting",
  "here's the kicker",
  "let's break this down",
  "let's unpack",
  "the truth is simple",
  "think of it as",
  "imagine a world where",
  "in conclusion",
  "to sum up",
  "studies show",
  "experts say",
  "it goes without saying",
  "importantly,",
  "interestingly,",
  "notably,",
  "furthermore,",
  "moreover,",
  "additionally,",
  "despite its challenges",
  "i'm excited to announce",
  "without further ado",
  "agree?",
  "thoughts?",
  "at its core",
  "whether you're a",
  "whether you're an",
  "the catch?",
  "your ideas, ai's polish",
];

const RHYTHM_PATTERNS: Array<[RegExp, string]> = [
  [/\bnot\s+\w+,\s+not\s+\w+\s*[—-]/i, "Not X, not Y — Z (rhetorical negation trifecta)"],
  [
    /\bif\s+you're\s+(?:a|an)\s+\w+\s+(?:founder|dev|team|builder|engineer)[^.]*stuck\s+between\b/i,
    "'If you're a [X] stuck between' (AI sales opener)",
  ],
  [
    /\bon\s+your\s+repo,\s+on\s+your\s+\w+\s+problem\b/i,
    "'on your repo, on your real problem' (parallel-clause slop)",
  ],
  [/—\s+that's\s+how\s+you\b/i, "'— that's how you' (AI didactic dash)"],
  [/\bnever\s+\w+[,.].{0,40}\balways\b/i, "Never X, always Y (false-symmetry rule)"],
  [
    /\bthe\s+real\s+\w+\s+is\s+(?:simple|that|this)\b/i,
    "'The real [X] is [reveal]' (AI reveal framing)",
  ],
  [/\bhere's\s+the\s+thing\b/i, "'Here's the thing' (AI pivot)"],
  [/\bat\s+the\s+end\s+of\s+the\s+day\b/i, "'At the end of the day' (filler)"],
  [/—/, "em dash — dead AI tell (voice: use commas/periods or restructure)"],
  [/–/, "en dash — dead AI tell (voice: use commas/periods or restructure)"],
  [
    /\b(agree|thoughts|right\?|make sense)\?\s*$/im,
    "engagement-bait closer ('Agree?' / 'Thoughts?') — LinkedIn slop tell",
  ],
  [
    /\bwhether you're (?:a|an)\s+\w+[,\s]+(?:a|an)?\s*\w+[,\s]+or\s+(?:a|an)?\s*\w+/i,
    "'Whether you're X, Y, or Z' template opener",
  ],
  [
    /\b\d{2,}\+?(?:\s+[\w-]+){0,3}\s+(endpoints|tools|clients|projects|integrations|playbooks|skills|apis|deploys|agents|workflows|automations)\b/i,
    "author-scoreboard count — numbers-about-author are decoys",
  ],
  [
    /(?:^|\n)\s*(?:the catch|the twist|the kicker|the surprise|the result|the reality)\?\s*\n/i,
    "mini-question intro fragment",
  ],
  [
    /(?:^|\n)\s*(?:I was |I noticed |Last (?:week|month|year) I |I had a session |I caught an? |I watched an? |I spent |I realized )/i,
    "personal story opener — lead with insight, not diary",
  ],
];

export function getBannedPhrases(): string[] {
  return [...BANNED_PHRASES];
}

export function checkTone(text: string): { pass: boolean; violations: string[] } {
  const cleaned = text
    .replace(/\[source:[^\]]*\]/gi, "")
    .replace(/<connective>[\s\S]*?<\/connective>/gi, "");
  const lower = cleaned.toLowerCase();
  const violations: string[] = [];

  for (const phrase of BANNED_PHRASES) {
    if (lower.includes(phrase.toLowerCase())) violations.push(phrase);
  }

  const nxMatch = text.match(/\b\d+x\b/gi);
  if (nxMatch) {
    for (const m of nxMatch) {
      if (!violations.includes(m)) violations.push(`${m} (Nx claim)`);
    }
  }

  for (const [re, label] of RHYTHM_PATTERNS) {
    if (re.test(text)) violations.push(label);
  }

  return { pass: violations.length === 0, violations };
}

export function getToneGuide(): {
  oneLiner: string;
  shortTagline: string;
  longTagline: string;
  tuningFork: string[];
  principles: string[];
  doRules: string[];
  dontRules: string[];
} {
  return {
    oneLiner: "Snappy helps developers build and control agents that ship real systems.",
    shortTagline: "We build businesses, not demos.",
    longTagline:
      "Faster than vibe coding. Private AI tools to ship real systems while others prompt. We build businesses, not demos.",
    tuningFork: [
      "You built it. You're stuck. Let's fix that, live on your screen.",
      "We open your codebase together, map the architecture, and start fixing what's blocking you.",
      "I burn the hours so you don't.",
      "Build and control agents to get huge results.",
    ],
    principles: [
      "Lead with what happens, not what Snappy is.",
      "First person. 'I' by default. 'We' only when literally true.",
      "Builder-to-builder. Assume the reader has shipped real software.",
      "Earn every adjective. If you can't defend it on a call, delete it.",
      "The four reference sentences are the tuning fork.",
    ],
    doRules: [
      "Write first person. 'I', 'you', 'we built'. Never marketing third person.",
      "Be direct. State the problem, state the fix, stop talking.",
      "Builder-to-builder. Assume the reader has shipped real software.",
      "Lead with the work. Screens, repos, agents running, commits landing.",
      "Short sentences beat clever sentences.",
      "Name the tool when it matters -- but the tool is never the hero. The outcome is.",
      "Earn every adjective. If you can't defend it on a call, delete it.",
    ],
    dontRules: [
      "No hype. No adjective stacking.",
      "No vibe coding language as our own. We build and control.",
      "No false novelty.",
      "No fake urgency.",
      "No third-person hero narration about Robert.",
      "No personification of Snappy.",
      "No 'MCP integration' or 'Xano MCP' as the headline.",
    ],
  };
}

export type FlowProfile = {
  name: string;
  source: string;
  stdev: number;
  rolling5: number;
  lowVarianceCeiling: number;
  shortFloor: number;
  longFloor: number;
};

export const FLOW_PROFILES: Record<string, FlowProfile> = {
  balanced: {
    name: "balanced",
    source:
      "writer-agnostic telegram detector; loose floors that catch metronome rhythm without prescribing any one stylist",
    stdev: 6.0,
    rolling5: 5.5,
    lowVarianceCeiling: 0.4,
    shortFloor: 0.08,
    longFloor: 0.15,
  },
  pg: {
    name: "pg",
    source:
      "Paul Graham corpus, 30377 sentences across 215 essays (HuggingFace sgoel9/paul_graham_essays, April 2026). Measured: stdev 9.79, rolling5 8.42, lowvar 18%, short 15.1%, long 27.9%",
    stdev: 7.5,
    rolling5: 7.0,
    lowVarianceCeiling: 0.3,
    shortFloor: 0.1,
    longFloor: 0.18,
  },
};

export function checkFlow(
  text: string,
  opts: { minSentences?: number; profile?: string } = {},
): {
  pass: boolean;
  profile: string;
  violations: string[];
  stats: {
    sentences: number;
    meanLength: number;
    medianLength: number;
    stdev: number;
    rolling5Stdev: number;
    lowVarianceWindowRatio: number;
    shortRatio: number;
    longRatio: number;
  };
} {
  const minSentences = opts.minSentences ?? 10;
  const profileName = opts.profile ?? "balanced";
  const profile = FLOW_PROFILES[profileName];
  if (!profile) {
    throw new Error(
      `[checkFlow] unknown profile '${profileName}'. Available: ${Object.keys(FLOW_PROFILES).join(", ")}`,
    );
  }

  const stripped = text
    .replace(/```[\s\S]*?```/g, "")
    .replace(/^#.*$/gm, "")
    .replace(/^---[\s\S]*?---/m, "")
    .replace(/<\/?connective>/gi, "")
    .replace(/\[source:[^\]]*\]/gi, "");

  const sentences = splitSentences(stripped);
  const lengths = sentences.map((s) => s.split(/\s+/).filter(Boolean).length);

  const zeroStats = {
    sentences: lengths.length,
    meanLength: 0,
    medianLength: 0,
    stdev: 0,
    rolling5Stdev: 0,
    lowVarianceWindowRatio: 0,
    shortRatio: 0,
    longRatio: 0,
  };

  if (lengths.length < minSentences) {
    return { pass: true, profile: profileName, violations: [], stats: zeroStats };
  }

  const mean = lengths.reduce((a, b) => a + b, 0) / lengths.length;
  const sorted = [...lengths].sort((a, b) => a - b);
  const median = sorted[Math.floor(sorted.length / 2)];
  const variance = lengths.reduce((a, b) => a + (b - mean) ** 2, 0) / lengths.length;
  const stdev = Math.sqrt(variance);

  const windowStdevs: number[] = [];
  for (let i = 0; i + 5 <= lengths.length; i++) {
    const w = lengths.slice(i, i + 5);
    const wMean = w.reduce((a, b) => a + b, 0) / 5;
    const wVar = w.reduce((a, b) => a + (b - wMean) ** 2, 0) / 5;
    windowStdevs.push(Math.sqrt(wVar));
  }
  const rolling5Stdev =
    windowStdevs.length === 0
      ? stdev
      : windowStdevs.reduce((a, b) => a + b, 0) / windowStdevs.length;
  const lowVarianceWindows = windowStdevs.filter((s) => s < 5).length;
  const lowVarianceWindowRatio =
    windowStdevs.length === 0 ? 0 : lowVarianceWindows / windowStdevs.length;

  const shortRatio = lengths.filter((l) => l < 8).length / lengths.length;
  const longRatio = lengths.filter((l) => l > 20).length / lengths.length;

  const violations: string[] = [];

  if (stdev < profile.stdev) {
    violations.push(
      `stdev ${stdev.toFixed(1)} < ${profile.stdev} floor (profile: ${profile.name}). Vary sentence length more.`,
    );
  }
  if (rolling5Stdev < profile.rolling5) {
    violations.push(
      `rolling-5 window stdev ${rolling5Stdev.toFixed(1)} < ${profile.rolling5} floor (profile: ${profile.name}). Metronome rhythm; break it up.`,
    );
  }
  if (lowVarianceWindowRatio > profile.lowVarianceCeiling) {
    violations.push(
      `${(lowVarianceWindowRatio * 100).toFixed(0)}% of 5-sentence windows have stdev<5, ceiling ${(profile.lowVarianceCeiling * 100).toFixed(0)}% (profile: ${profile.name}). Too many flat runs.`,
    );
  }
  if (shortRatio < profile.shortFloor) {
    violations.push(
      `only ${(shortRatio * 100).toFixed(0)}% of sentences are under 8 words, floor ${(profile.shortFloor * 100).toFixed(0)}% (profile: ${profile.name}). Add short punches for emphasis.`,
    );
  }
  if (longRatio < profile.longFloor) {
    violations.push(
      `only ${(longRatio * 100).toFixed(0)}% of sentences are over 20 words, floor ${(profile.longFloor * 100).toFixed(0)}% (profile: ${profile.name}). Add flowing clause-joined sentences.`,
    );
  }

  return {
    pass: violations.length === 0,
    profile: profileName,
    violations,
    stats: {
      sentences: lengths.length,
      meanLength: Math.round(mean * 10) / 10,
      medianLength: median,
      stdev: Math.round(stdev * 100) / 100,
      rolling5Stdev: Math.round(rolling5Stdev * 100) / 100,
      lowVarianceWindowRatio: Math.round(lowVarianceWindowRatio * 100) / 100,
      shortRatio: Math.round(shortRatio * 100) / 100,
      longRatio: Math.round(longRatio * 100) / 100,
    },
  };
}

function splitSentences(text: string): string[] {
  return text
    .split(/(?<=[.!?])\s+/)
    .map((s) => s.trim())
    .filter((s) => s.length > 0 && /[A-Za-z]/.test(s));
}

export function requireCitations(draft: string): {
  pass: boolean;
  totalSentences: number;
  citedSentences: number;
  connectiveSentences: number;
  uncitedSentences: string[];
  connectiveRatio: number;
  reasons: string[];
} {
  const stripped = draft
    .replace(/```[\s\S]*?```/g, "")
    .replace(/^#.*$/gm, "")
    .replace(/^---.*$/gm, "");

  const connectiveMatches = stripped.match(/<connective>[\s\S]*?<\/connective>/gi) || [];
  const connectiveSentences = connectiveMatches.reduce((n, chunk) => {
    const inner = chunk.replace(/<\/?connective>/gi, "");
    return n + splitSentences(inner).length;
  }, 0);
  const withoutConnective = stripped.replace(/<connective>[\s\S]*?<\/connective>/gi, "");

  const sentences = splitSentences(withoutConnective);
  const citeRe = /\[source:\s*[^\]]+?~\s*\d{1,3}:\d{2}[^\]]*\]/i;

  const cited: string[] = [];
  const uncited: string[] = [];
  for (const s of sentences) {
    if (citeRe.test(s)) cited.push(s);
    else uncited.push(s);
  }

  const totalSentences = sentences.length + connectiveSentences;
  const citedSentences = cited.length;
  const connectiveRatio = totalSentences === 0 ? 0 : connectiveSentences / totalSentences;

  const reasons: string[] = [];
  if (uncited.length > 0) {
    reasons.push(
      `${uncited.length} prose sentence(s) lack [source: ...~mm:ss] citation and are not wrapped in <connective>...`,
    );
  }
  if (connectiveRatio > 0.35) {
    reasons.push(
      `connective tissue ratio ${(connectiveRatio * 100).toFixed(0)}% exceeds 35% budget`,
    );
  }

  return {
    pass: reasons.length === 0,
    totalSentences,
    citedSentences,
    connectiveSentences,
    uncitedSentences: uncited,
    connectiveRatio,
    reasons,
  };
}

scripts- helper scripts it can run

prose-only skill - 6 inline code blocks live in SKILL.md above (no state/bin/ sidecar yet).

how we check it- the checks, plus the last 9 runs

rubric auto-shape no rubric declared
recent mean 0.70 · 9 runs actor/auditor: unverifiable
deps openrouter elevenlabs
timestamp verb score primary_issue artifact
2026-04-30 21:02Z - 0.60 - -
2026-04-30 20:58Z - 0.50 - -
2026-04-27 16:54Z - 1.00 - -
2026-04-30 21:02Z - 0.60 - -
2026-04-30 20:58Z - 0.50 - -
2026-04-27 16:54Z - 1.00 - -
2026-04-30 21:02Z - 0.60 - -
2026-04-30 20:58Z - 0.50 - -
2026-04-27 16:54Z - 1.00 - -