Skip to content

Makkov-design/makkov-harness / skills/media-use

media-use

Verified

Get or make any media for a HyperFrames video - music, sound effects, images, icons, logos, voiceover, avatar and generated video, transcripts, cutouts, colour grades and looks - with HeyGen or free local tools, and mix placed audio. Also for footage that looks dark, flat or dull, or should be stylized or hidden.

FileKindSize
.gitignoreother17 B
LICENSEother10.5 KB
SKILL.mdskill md5.9 KB
audio/assets/sfx/CREDITS.mdmarkdown1.2 KB
audio/assets/sfx/chime.mp3binary26.7 KB
audio/assets/sfx/click-soft.mp3binary11.4 KB
audio/assets/sfx/click.mp3binary11.4 KB
audio/assets/sfx/error.mp3binary50.6 KB
audio/assets/sfx/glitch-1.mp3binary82.4 KB
audio/assets/sfx/glitch-2.mp3binary109.5 KB
audio/assets/sfx/glitch-3.mp3binary96.8 KB
audio/assets/sfx/impact-bass-1.mp3binary66.1 KB
audio/assets/sfx/impact-bass-2.mp3binary81.0 KB
audio/assets/sfx/key-press.mp3binary3.8 KB
audio/assets/sfx/manifest.jsonconfig3.6 KB
audio/assets/sfx/notification.mp3binary76.7 KB
audio/assets/sfx/ping.mp3binary25.8 KB
audio/assets/sfx/pop.mp3binary22.5 KB
audio/assets/sfx/riser.mp3binary313.5 KB
audio/assets/sfx/sparkle.mp3binary56.3 KB
audio/assets/sfx/typing.mp3binary26.2 KB
audio/assets/sfx/whoosh-cinematic.mp3binary173.3 KB
audio/assets/sfx/whoosh-short.mp3binary18.0 KB
audio/assets/sfx/whoosh.mp3binary18.0 KB
audio/references/bgm.mdmarkdown7.9 KB
audio/references/captions/authoring.mdmarkdown9.2 KB
audio/references/captions/motion.mdmarkdown5.4 KB
audio/references/captions/transcript-handling.mdmarkdown5.3 KB
audio/references/remove-background.mdmarkdown8.3 KB
audio/references/requirements.mdmarkdown4.4 KB
audio/references/sfx.mdmarkdown6.4 KB
audio/references/transcribe.mdmarkdown2.8 KB
audio/references/tts-to-captions.mdmarkdown1.7 KB
audio/references/tts.mdmarkdown13.7 KB
audio/scripts/audio.mjsscript13.1 KB
audio/scripts/audio.test.mjsscript5.9 KB
audio/scripts/carve.mjsscript23.3 KB
audio/scripts/carve.test.mjsscript11.5 KB
audio/scripts/extract-audio-data.pyscript7.0 KB
audio/scripts/gemini-pipeline.test.mjsscript5.0 KB
audio/scripts/heygen-tts.mjsscript4.3 KB
audio/scripts/heygen-tts.test.mjsscript1.4 KB
audio/scripts/heygen-voice.mjsscript3.8 KB
audio/scripts/heygen-voice.test.mjsscript8.3 KB
audio/scripts/lib/audio-meta.mjsscript1.1 KB
audio/scripts/lib/audio-meta.test.mjsscript4.5 KB
audio/scripts/lib/bgm-volume.mjsscript236 B
audio/scripts/lib/bgm.mjsscript11.3 KB
audio/scripts/lib/bgm.test.mjsscript2.6 KB
audio/scripts/lib/concurrency.mjsscript527 B
audio/scripts/lib/concurrency.test.mjsscript1.6 KB
audio/scripts/lib/gemini-auth.mjsscript1.6 KB
audio/scripts/lib/gemini-auth.pyscript1.9 KB
audio/scripts/lib/gemini-auth.test.mjsscript3.0 KB
audio/scripts/lib/gemini-auth_test.pyscript4.3 KB
audio/scripts/lib/gemini-tts.mjsscript5.0 KB
audio/scripts/lib/gemini-tts.test.mjsscript9.2 KB
audio/scripts/lib/heygen.mjsscript12.6 KB
audio/scripts/lib/heygen.test.mjsscript14.8 KB
audio/scripts/lib/main-module.mjsscript479 B
audio/scripts/lib/media-record.mjsscript4.1 KB
audio/scripts/lib/media-record.test.mjsscript7.7 KB
audio/scripts/lib/openverse.mjsscript7.8 KB
audio/scripts/lib/openverse.test.mjsscript4.3 KB
audio/scripts/lib/python.mjsscript3.2 KB
audio/scripts/lib/python.test.mjsscript5.2 KB
audio/scripts/lib/sfx.mjsscript7.2 KB
audio/scripts/lib/sfx.test.mjsscript11.6 KB
audio/scripts/lib/tts.cleanup.test.mjsscript6.6 KB
audio/scripts/lib/tts.mjsscript17.3 KB
audio/scripts/lib/tts.spawn.test.mjsscript5.1 KB
audio/scripts/lib/tts.test.mjsscript8.1 KB
audio/scripts/lyria-recipe.pyscript4.9 KB
audio/scripts/wait-bgm.mjsscript5.7 KB
audio/scripts/wait-bgm.test.mjsscript3.3 KB
luts/README.mdmarkdown1.1 KB
luts/index.jsonconfig2.0 KB
references/audio.mdmarkdown2.4 KB
references/grading.mdmarkdown7.0 KB
references/heygen.mdmarkdown8.5 KB
references/local.mdmarkdown2.6 KB
references/media-treatment-recipes.mdmarkdown35.0 KB
references/media-treatments.mdmarkdown13.8 KB
references/memory.mdmarkdown3.7 KB
references/meta.mdmarkdown6.8 KB
references/mixing.mdmarkdown4.5 KB
references/operations.mdmarkdown15.7 KB
references/resolve.mdmarkdown9.5 KB
references/setup-providers.mdmarkdown9.3 KB
references/telemetry-dashboard.mdmarkdown4.1 KB
scripts/audio-duck.mjsscript4.0 KB
scripts/compatibility.test.mjsscript1.6 KB
scripts/dither.mjsscript9.7 KB
scripts/dither.test.mjsscript4.6 KB
scripts/eval.mjsscript14.5 KB
scripts/lib/config-lock.mjsscript1.5 KB
scripts/lib/cutlist.mjsscript6.2 KB
scripts/lib/duck.mjsscript3.8 KB
scripts/lib/error-diffusion.mjsscript6.5 KB
scripts/lib/hyperframes-pin.mjsscript1.8 KB
scripts/lib/hyperframes-pin.test.mjsscript1.0 KB
scripts/lib/index-gen.mjsscript1.9 KB
scripts/lib/manifest.mjsscript9.2 KB
scripts/lib/media-fetch.mjsscript2.8 KB
scripts/lib/media-home.mjsscript730 B
scripts/lib/npx-sync.mjsscript2.3 KB
scripts/lib/parakeet-words.mjsscript1.1 KB
scripts/lib/prefs-store.mjsscript6.8 KB
scripts/lib/recipe-store.mjsscript13.0 KB
scripts/lib/telemetry.mjsscript8.8 KB
scripts/lib/telemetry.test.mjsscript2.8 KB
scripts/lib/transcriptCutFade.mjsscript911 B
scripts/lib/words.mjsscript728 B
scripts/prefs.mjsscript2.3 KB
scripts/recipe.mjsscript3.8 KB
scripts/resolve-plugin.test.mjsscript2.5 KB
scripts/resolve.mjsscript1.3 KB
scripts/transcribe.mjsscript7.5 KB
scripts/transcribe.test.mjsscript4.0 KB
scripts/transcript-cut.mjsscript10.0 KB
scripts/transcript-cut.test.mjsscript9.6 KB

audio/scripts/lib/heygen.mjs

View on GitHub
import { fetchMedia } from "../../../scripts/lib/media-fetch.mjs";
// heygen.mjs — vendored HeyGen REST helpers (auth + transport) for the audio
// pipeline. The credential resolver matches the hyperframes CLI auth: first
// usable source wins — a host gateway ($HEYGEN_API_BASE with its own
// $HEYGEN_API_KEY) → a host-injected OAuth $HEYGEN_ACCESS_TOKEN (Bearer) →
// the live login in ~/.hyperframes/credentials → $HEYGEN_API_KEY /
// $HYPERFRAMES_API_KEY (or a nearby .env) → the API key saved in
// ~/.hyperframes/credentials. An expired login gives way to an env key but
// never to the saved API key ($HYPERFRAMES_CONFIG_DIR overrides the dir).
// $HEYGEN_API_BASE moves every request to that host, as it does for the
// heygen CLI; plain HTTP needs $HEYGEN_ALLOW_HTTP=1, as there.
// Vendored so the skill ships standalone. Pure node.

import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join, resolve } from "node:path";

export const HEYGEN_BASE = "https://api.heygen.com/v3";

// The v3 base every request goes to: $HEYGEN_API_BASE when a host app names its own gateway (HyperFrames Desktop
// forwards it to HeyGen with the API key saved in its Settings), else HeyGen's public API. Plain HTTP carries the key
// in the clear, so it needs $HEYGEN_ALLOW_HTTP=1, the heygen CLI's own rule.
export function heygenBase() {
  const host = process.env.HEYGEN_API_BASE?.trim().replace(/\/+$/, "");
  if (!host) return HEYGEN_BASE;
  if (host.startsWith("http://") && process.env.HEYGEN_ALLOW_HTTP !== "1")
    throw new Error(
      `HEYGEN_API_BASE (${host}) uses HTTP, which sends the key in plaintext. Set HEYGEN_ALLOW_HTTP=1 to allow it.`,
    );
  return `${host}/v3`;
}

// No base override, or one on HeyGen's own hosts (a canary or dev API).
function heygenOwnBase() {
  const host = process.env.HEYGEN_API_BASE?.trim();
  if (!host) return true;
  try {
    const name = new URL(host).hostname;
    return name === "heygen.com" || name.endsWith(".heygen.com");
  } catch {
    return false;
  }
}

// A host gateway: the host pointed the API base away from HeyGen and set the key that base accepts. It pays for every
// call, so it wins over any other credential the environment carries.
const hostGatewayKey = () =>
  !heygenOwnBase() && process.env.HEYGEN_API_KEY ? process.env.HEYGEN_API_KEY : null;
export const HEYGEN_CLI_SOURCE_HEADERS = { "X-HeyGen-Source": "cli" };
// Tool-attribution sent on EVERY media-use HeyGen call regardless of auth type, so
// the backend can isolate media-use consumption from other free TTS / avatar video.
// Unconditional — a paying user's media-use call is still media-use — unlike the
// OAuth-only cli-source header above, which also gates the free allowance.
export const HEYGEN_CLIENT_SOURCE_HEADERS = { "X-HeyGen-Client-Source": "media-use" };

// A missing `.env`, or a `.env` folder (some home dirs have one), is no env file: null. Read without checking first,
// so the file cannot change between a check and the read.
function envFileText(path) {
  try {
    return readFileSync(path, "utf8");
  } catch (error) {
    if (["ENOENT", "ENOTDIR", "EISDIR"].includes(error.code)) return null;
    throw error;
  }
}

// A host app sets these in the environment it spawns, never in a project file: a project's .env naming its own base
// would send the person's shell HEYGEN_API_KEY to that host.
const HOST_ONLY = new Set(["HEYGEN_API_BASE", "HEYGEN_ALLOW_HTTP"]);

// Walk up ≤5 dirs from startDir; load the first .env (shell env always wins).
export function loadEnvFromDir(startDir) {
  let dir = resolve(startDir);
  for (let i = 0; i < 5; i++) {
    const text = envFileText(join(dir, ".env"));
    if (text != null) {
      for (const raw of text.split("\n")) {
        let line = raw.trim();
        if (!line || line.startsWith("#")) continue;
        if (line.startsWith("export ")) line = line.slice(7).trim();
        const eq = line.indexOf("=");
        if (eq < 1) continue;
        const key = line.slice(0, eq).trim();
        let val = line.slice(eq + 1).trim();
        if (val.startsWith('"') || val.startsWith("'")) {
          const q = val[0];
          const end = val.indexOf(q, 1);
          val = end > 0 ? val.slice(1, end) : val.slice(1);
        }
        if (!HOST_ONLY.has(key) && !(key in process.env)) process.env[key] = val;
      }
      return;
    }
    const parent = dirname(dir);
    if (parent === dir) break;
    dir = parent;
  }
}

// → { headers } | { expired: true } | null. Never throws.
export function heygenCredential() {
  const cred = resolveCredential();
  return cred?.unreadable ? null : cred;
}

// heygenCredential's answer, or { unreadable: { file, code } } when the credentials path exists but cannot be read
// (a folder, a locked ~/.hyperframes), so heygenAuthHeaders can say to fix that path: logging in again would fail there too.
// Read without checking first, so the file cannot change between a check and the read.
function resolveCredential() {
  const gatewayKey = hostGatewayKey();
  if (gatewayKey) return { headers: { "X-Api-Key": gatewayKey } };
  // Every other credential belongs to HeyGen: a base on any other host gets none of them.
  if (!heygenOwnBase()) return null;
  const accessToken = process.env.HEYGEN_ACCESS_TOKEN;
  if (accessToken) return { headers: { Authorization: `Bearer ${accessToken}` } };
  const envKey = process.env.HEYGEN_API_KEY || process.env.HYPERFRAMES_API_KEY;
  const stored = storedCredential();
  // A live login wins over an env key; an expired, foreign or unreadable store gives way to one.
  if (stored?.headers && "Authorization" in stored.headers) return stored;
  return envKey ? { headers: { "X-Api-Key": envKey } } : stored;
}

// The credential saved in ~/.hyperframes/credentials: { headers } | { expired: true } | { unreadable } | null.
function storedCredential() {
  const root = process.env.HYPERFRAMES_CONFIG_DIR || join(homedir(), ".hyperframes");
  const file = join(root, ...(process.env.HYPERFRAMES_ENV === "dev" ? ["dev"] : []), "credentials");
  let raw;
  try {
    raw = readFileSync(file, "utf8").trim();
  } catch (error) {
    return error.code === "ENOENT" ? null : { unreadable: { file, code: error.code } };
  }
  if (!raw) return null;
  if (!raw.startsWith("{")) return { headers: { "X-Api-Key": raw } };

  // A malformed credentials file (partial write / wrong shape) must degrade to
  // "no credential", not crash the engine at startup.
  let cred;
  try {
    cred = JSON.parse(raw);
  } catch {
    return null;
  }
  const oauth = cred.oauth;
  if (oauth?.access_token) {
    const expectedClient = process.env.HYPERFRAMES_OAUTH_CLIENT_ID || "Zg3LF4FCLoeJoGs2YqMtZ17g";
    const expectedTokenEndpoint =
      process.env.HYPERFRAMES_OAUTH_TOKEN_URL || "https://api2.heygen.com/v1/oauth/token";
    if (
      !expectedClient ||
      oauth.client_id !== expectedClient ||
      oauth.token_endpoint !== expectedTokenEndpoint
    )
      return { expired: true };
    const expired = oauth.expires_at && new Date(oauth.expires_at).getTime() - 60_000 < Date.now();
    if (!expired) return { headers: { Authorization: `Bearer ${oauth.access_token}` } };
    return { expired: true };
  }
  if (cred.api_key) return { headers: { "X-Api-Key": cred.api_key } };
  return null;
}

// → "oauth" | "api_key" | null. Same oauth-vs-api-key check heygenAuthHeaders()
// makes internally, exposed on its own so callers that only need to *tag* the
// auth path (telemetry) don't have to parse headers back apart. Never throws:
// no credential (or an expired one) is just `null`, same as a fresh resolve
// with nothing to tag.
export function heygenAuthMethod() {
  const cred = heygenCredential();
  if (!cred?.headers) return null;
  return "Authorization" in cred.headers ? "oauth" : "api_key";
}

// → auth headers object, or throw with a fix hint.
export function heygenAuthHeaders() {
  const cred = resolveCredential();
  if (cred?.headers) {
    // Only tag OAuth (Bearer) traffic as cli-source — the backend uses it to
    // grant the free allowance for OAuth requests and ignores it for API-key
    // (X-Api-Key) traffic, where it's dead metadata.
    const isOauth = "Authorization" in cred.headers;
    return isOauth
      ? { ...cred.headers, ...HEYGEN_CLI_SOURCE_HEADERS, ...HEYGEN_CLIENT_SOURCE_HEADERS }
      : { ...cred.headers, ...HEYGEN_CLIENT_SOURCE_HEADERS };
  }
  if (cred?.unreadable)
    throw new Error(
      `HeyGen credentials at ${cred.unreadable.file} can't be read (${cred.unreadable.code}) — fix or remove that path, then run \`npx hyperframes auth login\``,
    );
  if (cred?.expired)
    throw new Error(
      "HeyGen OAuth token expired — run `npx hyperframes auth refresh` (or `npx hyperframes auth login`)",
    );
  throw new Error(
    "no HyperFrames credentials — set $HEYGEN_API_KEY, or run `npx hyperframes auth login` (writes ~/.hyperframes/credentials)",
  );
}

// Authed JSON request against the v3 API; throws on a non-OK status.
export async function heygenJSON(path, { method = "GET", headers = {}, body } = {}) {
  const opts = { method, headers: { ...HEYGEN_CLIENT_SOURCE_HEADERS, ...headers } };
  if (body !== undefined) {
    opts.headers["Content-Type"] = "application/json";
    opts.body = JSON.stringify(body);
  }
  const res = await fetch(`${heygenBase()}${path}`, opts);
  if (!res.ok) {
    const detail = await res.text().catch(() => "");
    const message = `HeyGen ${method} ${path} → HTTP ${res.status}${detail ? `\n${detail.slice(0, 300)}` : ""}`;
    throw Object.assign(new Error(message), { status: res.status, body: detail });
  }
  // A DELETE may answer 204 with no body.
  const text = await res.text();
  return text ? JSON.parse(text) : {};
}

function errorCode(body) {
  try {
    const parsed = JSON.parse(body);
    return parsed?.error?.code ?? parsed?.code ?? null;
  } catch {
    return null;
  }
}

// One line the agent relays as written when the HyperFrames plan can't pay: no plan, out of credits, or a
// sign-in the plan doesn't cover yet. Null for every other failure.
export function billingRefusal(e) {
  const code = e?.body ? errorCode(e.body) : null;
  if (code === "hf_subscription_required")
    return "This needs a HyperFrames plan. Run `npx hyperframes billing subscribe`: it opens the page and waits.";
  if (code === "hf_usage_exhausted")
    return "Out of HyperFrames credits. Run `npx hyperframes billing add-credits`: it opens the page and waits.";
  if (code === "api_key_required")
    return "This HeyGen feature isn't available with this sign-in yet. Nothing was charged. Use a HeyGen API key, or wait for HyperFrames billing in the CLI.";
  return null;
}

// HeyGen's own words for a failed call: a billing refusal line first, then its {"error":{"message"}}, else the
// raw body, else the error's message.
export function heygenMessage(e) {
  const refusal = billingRefusal(e);
  if (refusal) return refusal;
  if (!e?.body) return e?.message ? String(e.message) : String(e);
  try {
    return JSON.parse(e.body).error?.message ?? e.body;
  } catch {
    return e.body;
  }
}

// Download a (presigned) URL to destPath; returns byte length.
export async function downloadTo(url, destPath) {
  const res = await fetchMedia(url);
  if (!res.ok) throw new Error(`download HTTP ${res.status}: ${String(url).slice(0, 80)}`);
  const bytes = Buffer.from(await res.arrayBuffer());
  mkdirSync(dirname(destPath), { recursive: true });
  writeFileSync(destPath, bytes);
  return bytes.length;
}

// Retrieval search over HeyGen's audio catalog (NOT generation). type =
// "music" | "sound_effects". Returns the ranked results array (best first); each
// item has a presigned `audio_url` (+ `duration`, `description`, `name`, `score`).
// `query` is required (≥1 char, empty → HTTP 400) and `limit` is capped at 50.
// `minScore`: omit to use the server default (0.7). That default is TOO HIGH for
// sound_effects — good SFX hits score ~0.5–0.67, so callers wanting SFX should
// pass a lower floor (~0.4); music scores high and is fine at the default.
export async function searchSounds(query, type, headers, { limit = 5, minScore } = {}) {
  const params = new URLSearchParams({ query, type, limit: String(limit) });
  if (minScore != null) params.set("min_score", String(minScore));
  const payload = await heygenJSON(`/audio/sounds?${params.toString()}`, { headers });
  // `data` comes back as a ranked array (best first). Older responses keyed it by
  // numeric index ("0","1",…); normalize both shapes to an array (empty → []).
  const data = payload?.data ?? payload;
  if (Array.isArray(data)) return data;
  if (data && typeof data === "object") return Object.values(data);
  throw new Error(
    `unexpected /audio/sounds shape — top keys: ${Object.keys(payload ?? {}).join(", ")}`,
  );
}
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall