Skip to content

JaimeJunr/claude-code-frontend-skills / plugins/hyperframes/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
SKILL.mdskill md5.3 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.7 KB
audio/references/sfx.mdmarkdown4.0 KB
audio/references/transcribe.mdmarkdown2.8 KB
audio/references/tts-to-captions.mdmarkdown1.7 KB
audio/references/tts.mdmarkdown13.9 KB
audio/scripts/audio.mjsscript15.2 KB
audio/scripts/audio.test.mjsscript8.4 KB
audio/scripts/carve.mjsscript20.1 KB
audio/scripts/carve.test.mjsscript12.2 KB
audio/scripts/extract-audio-data.pyscript7.1 KB
audio/scripts/gemini-pipeline.test.mjsscript4.8 KB
audio/scripts/heygen-tts.mjsexecutablescript4.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-carve.mjsscript16.6 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.5 KB
audio/scripts/lib/bgm.test.mjsscript4.7 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.mjsscript14.3 KB
audio/scripts/lib/heygen.test.mjsscript22.9 KB
audio/scripts/lib/main-module.mjsscript479 B
audio/scripts/lib/media-record.mjsscript5.1 KB
audio/scripts/lib/media-record.test.mjsscript12.6 KB
audio/scripts/lib/openverse.mjsscript4.9 KB
audio/scripts/lib/project-path.mjsscript2.2 KB
audio/scripts/lib/project-path.test.mjsscript3.0 KB
audio/scripts/lib/python.mjsscript4.6 KB
audio/scripts/lib/python.test.mjsscript7.8 KB
audio/scripts/lib/recording.mjsscript4.4 KB
audio/scripts/lib/sfx.mjsscript7.2 KB
audio/scripts/lib/sfx.test.mjsscript11.6 KB
audio/scripts/lib/tts.cleanup.test.mjsscript7.0 KB
audio/scripts/lib/tts.mjsscript18.6 KB
audio/scripts/lib/tts.spawn.test.mjsscript6.0 KB
audio/scripts/lib/tts.test.mjsscript10.2 KB
audio/scripts/lib/voice-credit.mjsscript686 B
audio/scripts/lib/voice-credit.test.mjsscript946 B
audio/scripts/lyria-recipe.pyscript4.9 KB
audio/scripts/recording.test.mjsscript9.2 KB
audio/scripts/trusted-program.test.mjsscript3.4 KB
audio/scripts/trusted_program.pyscript2.8 KB
audio/scripts/wait-bgm.mjsscript6.1 KB
audio/scripts/wait-bgm.test.mjsscript8.0 KB
luts/README.mdmarkdown1.1 KB
luts/index.jsonconfig2.0 KB
references/audio.mdmarkdown3.5 KB
references/grading.mdmarkdown7.0 KB
references/heygen.mdmarkdown11.8 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.4 KB
references/mixing.mdmarkdown4.5 KB
references/operations.mdmarkdown15.8 KB
references/resolve.mdmarkdown9.9 KB
references/setup-providers.mdmarkdown9.1 KB
references/telemetry-dashboard.mdmarkdown4.1 KB
scripts/audio-duck.mjsscript4.0 KB
scripts/compatibility.test.mjsscript1.6 KB
scripts/dither.mjsscript9.8 KB
scripts/dither.test.mjsscript4.6 KB
scripts/eval.mjsscript14.6 KB
scripts/lib/config-lock.mjsscript1.5 KB
scripts/lib/credit-limit.mjsscript2.0 KB
scripts/lib/cutlist.mjsscript6.2 KB
scripts/lib/duck.mjsscript3.8 KB
scripts/lib/error-diffusion.mjsscript6.5 KB
scripts/lib/index-gen.mjsscript2.0 KB
scripts/lib/manifest.mjsscript10.6 KB
scripts/lib/media-fetch.mjsscript2.8 KB
scripts/lib/media-home.mjsscript730 B
scripts/lib/npx-sync.mjsscript3.2 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.mjsscript3.0 KB
scripts/lib/transcriptCutFade.mjsscript911 B
scripts/lib/windows-exe-search.mjsscript640 B
scripts/lib/words.mjsscript728 B
scripts/prefs.mjsscript2.3 KB
scripts/recipe.mjsscript3.8 KB
scripts/resolve-plugin.test.mjsscript3.2 KB
scripts/resolve.mjsscript1.4 KB
scripts/transcribe.mjsscript8.0 KB
scripts/transcribe.test.mjsscript7.7 KB
scripts/transcript-cut.mjsscript10.1 KB
scripts/transcript-cut.test.mjsscript9.6 KB

scripts/lib/manifest.mjs

View on GitHub
import {
  readFileSync,
  mkdirSync,
  existsSync,
  readdirSync,
  openSync,
  closeSync,
  writeFileSync,
  writeSync,
  rmSync,
  renameSync,
  statSync,
  lstatSync,
  realpathSync,
  constants,
} from "node:fs";
import { randomBytes } from "node:crypto";
import { basename, join } from "node:path";

const MANIFEST_FILE = "manifest.jsonl";
const INDEX_FILE = "index.md";

const TYPE_DIRS = {
  bgm: "audio/bgm",
  sfx: "audio/sfx",
  voice: "audio/voice",
  image: "images",
  icon: "images",
  logo: "images",
  brand: "images",
  video: "video",
  grade: "luts",
  lut: "luts",
  recipe: "recipes",
};

export function mediaDir(projectDir) {
  return join(projectDir, ".media");
}

export function manifestPath(projectDir) {
  return join(mediaDir(projectDir), MANIFEST_FILE);
}

export function indexPath(projectDir) {
  return join(mediaDir(projectDir), INDEX_FILE);
}

export function typeSubdir(type) {
  const sub = TYPE_DIRS[type];
  if (!sub) throw new Error(`unknown media type: ${type}`);
  return sub;
}

export function typeDirPath(projectDir, type) {
  return join(mediaDir(projectDir), typeSubdir(type));
}

export function readManifest(projectDir) {
  const p = manifestPath(projectDir);
  if (!existsSync(p)) return [];
  const raw = readFileSync(p, "utf8");
  const records = [];
  for (const line of raw.split(/\r?\n/)) {
    const trimmed = line.trim();
    if (!trimmed) continue;
    try {
      records.push(JSON.parse(trimmed));
    } catch {
      // ponytail: skip malformed lines, don't crash
    }
  }
  return records;
}

/**
 * The project's `.media` folder, made if missing. Throws when it is a link or resolves outside the project, since
 * a project from someone else could carry such a link to send manifest and index writes elsewhere.
 */
export function ownMediaDir(projectDir) {
  const dir = mediaDir(projectDir);
  mkdirSync(dir, { recursive: true });
  if (
    lstatSync(dir).isSymbolicLink() ||
    realpathSync(dir) !== join(realpathSync(projectDir), ".media")
  ) {
    throw new Error(`${dir} leads outside the project folder; nothing was written there`);
  }
  return dir;
}

function refuseLink(path) {
  if (lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) {
    throw new Error(`${path} is a link; nothing was written through it`);
  }
}

/** Replaces the file at `path` with `content` by writing a temp file beside it and renaming it over, so a link there is replaced, never followed. */
export function replaceFile(path, content) {
  // Same shape as core atomicTempPath, which Studio's project history skips.
  const temp = `${path}.hf${randomBytes(3).toString("hex")}.tmp`;
  writeFileSync(temp, content, { flag: "wx" });
  try {
    renameSync(temp, path);
  } catch (error) {
    rmSync(temp, { force: true });
    throw error;
  }
}

export function appendRecord(projectDir, record) {
  ownMediaDir(projectDir);
  const typeDir = typeDirPath(projectDir, record.type);
  mkdirSync(typeDir, { recursive: true });

  const p = manifestPath(projectDir);
  refuseLink(p);
  const fd = openSync(
    p,
    constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | (constants.O_NOFOLLOW ?? 0),
    0o666,
  );
  try {
    writeSync(fd, JSON.stringify(record) + "\n");
  } finally {
    closeSync(fd);
  }
}

/** Sources that mean the agent made or fetched the file; any other file is the person's own. */
export const AGENT_SOURCES = ["generated", "search", "bundled"];

/** The record a path has now: the manifest only appends, so the last one for a path wins. */
export function latestRecordFor(projectDir, path) {
  return readManifest(projectDir).findLast((record) => record.path === path);
}

/** Records with every older record for the same path dropped, since the last one for a path is its record. */
export function currentRecords(projectDir) {
  const records = readManifest(projectDir);
  const last = new Map(records.map((record, index) => [record.path, index]));
  return records.filter((record, index) => !record.path || last.get(record.path) === index);
}

/** Records a file already in the project where it is, unless its current record already says the same thing. */
export function recordInPlace(
  projectDir,
  { type, path, source, description, duration, provenance },
) {
  const fields = {
    type,
    path,
    source,
    description: description || basename(path),
    ...(duration != null && { duration: Math.round(duration * 10) / 10 }),
  };
  return withMediaLock(projectDir, () => {
    const latest = latestRecordFor(projectDir, path);
    const same = ["source", "description", "duration"].every(
      (key) => latest?.[key] === fields[key],
    );
    if (latest && same) return latest;
    const record = { id: nextFreeId(projectDir, type), ...fields, provenance };
    appendRecord(projectDir, record);
    return record;
  });
}

// Match prompts forgivingly. Agents rarely re-emit a byte-identical intent, so
// keying cache lookups on exact equality meant "Calm piano" and "calm  piano"
// re-searched and re-downloaded. Normalize (trim, lowercase, collapse internal
// whitespace) on both sides; the raw prompt is still stored for audit.
export function normalizePrompt(prompt) {
  return String(prompt ?? "")
    .trim()
    .toLowerCase()
    .replace(/\s+/g, " ");
}

export function findByPrompt(projectDir, prompt, type) {
  const key = normalizePrompt(prompt);
  if (!key) return null;
  const records = currentRecords(projectDir);
  return (
    records.find(
      (r) => normalizePrompt(r.provenance?.prompt) === key && (type == null || r.type === type),
    ) || null
  );
}

export function findByEntity(projectDir, entity) {
  const lower = entity.toLowerCase();
  const records = currentRecords(projectDir);
  return records.find((r) => r.entity && r.entity.toLowerCase() === lower) || null;
}

export function nextId(projectDir, type) {
  const records = readManifest(projectDir);
  const prefix = type;
  let max = 0;
  for (const r of records) {
    if (r.type !== type) continue;
    const m = r.id?.match(new RegExp(`^${prefix}_(\\d+)$`));
    if (m) max = Math.max(max, parseInt(m[1], 10));
  }
  return `${prefix}_${String(max + 1).padStart(3, "0")}`;
}

// Sync sleep (no busy-spin) for the allocation lock retry.
function sleepMs(ms) {
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
}

// Coarse per-project lock so concurrent resolves don't race on id allocation.
// ponytail: one lock file with a 15s stale-steal (a crashed holder can't wedge
// the project); fine for agent-scale concurrency — revisit if throughput needs
// finer locking. Date.now() is available here (a normal Node CLI, not a
// workflow DSL), so mtime-based staleness is safe.
const LOCK_STALE_MS = 15000;
const LOCK_TIMEOUT_MS = 20000;

function withLock(dir, fn) {
  const lock = join(dir, ".lock");
  const start = Date.now();
  for (;;) {
    try {
      closeSync(openSync(lock, "wx")); // O_EXCL: atomic acquire
      break;
    } catch (err) {
      if (err.code !== "EEXIST") throw err;
      try {
        if (Date.now() - statSync(lock).mtimeMs > LOCK_STALE_MS) {
          rmSync(lock, { force: true }); // steal a stale lock from a dead holder
          continue;
        }
      } catch {
        continue; // lock vanished between check and stat — retry the acquire
      }
      if (Date.now() - start > LOCK_TIMEOUT_MS) {
        throw new Error("media-use: timed out acquiring .media/.lock");
      }
      sleepMs(25);
    }
  }
  try {
    return fn();
  } finally {
    rmSync(lock, { force: true });
  }
}

/** Runs `fn` holding the project's `.media/.lock`, so concurrent resolves take turns on what it guards. */
export function withMediaLock(projectDir, fn) {
  mkdirSync(mediaDir(projectDir), { recursive: true });
  return withLock(mediaDir(projectDir), fn);
}

// Atomically allocate the next free id for `type` AND reserve it on disk, so a
// slow download/copy between allocation and appendRecord can't let a concurrent
// caller grab the same id (the MU-23 clobber). Under the lock we take the max id
// across BOTH the manifest and any already-reserved files in the type dir, then
// O_EXCL-create an empty marker under core's atomic temp name, which Studio's
// project history skips. Returns { id, localPath, markerPath }.
export function allocateId(projectDir, type, ext) {
  mkdirSync(typeDirPath(projectDir, type), { recursive: true });
  return withMediaLock(projectDir, () => {
    const id = nextFreeId(projectDir, type);
    const localPath = `.media/${typeSubdir(type)}/${id}${ext}`;
    // Same shape as core atomicTempPath: an empty file at the final name would be committed.
    const markerPath = `${join(projectDir, localPath)}.hf${randomBytes(3).toString("hex")}.tmp`;
    writeFileSync(markerPath, "", { flag: "wx" }); // durable reservation
    return { id, localPath, markerPath };
  });
}

// Call under the lock: counts recorded ids and ids reserved by a file not yet recorded.
function nextFreeId(projectDir, type) {
  const re = new RegExp(`^${type}_(\\d+)`);
  let max = 0;
  for (const r of readManifest(projectDir)) {
    if (r.type !== type) continue;
    const m = r.id?.match(re);
    if (m) max = Math.max(max, parseInt(m[1], 10));
  }
  const typeDir = typeDirPath(projectDir, type);
  for (const f of existsSync(typeDir) ? readdirSync(typeDir) : []) {
    const m = f.match(re);
    if (m) max = Math.max(max, parseInt(m[1], 10));
  }
  return `${type}_${String(max + 1).padStart(3, "0")}`;
}

function reservedFile(projectDir, type, ext) {
  const allocation = allocateId(projectDir, type, ext);
  return { ...allocation, fullPath: join(projectDir, allocation.localPath) };
}

function releaseReservation(reservation, committed) {
  if (!committed) rmSync(reservation.fullPath, { force: true });
  rmSync(reservation.markerPath, { force: true });
}

// A reservation is committed only when populate returns a non-null value.
// Throwing/rejecting or returning null means no usable asset was produced, so
// the reservation and any partial asset are released. Keeping this transaction
// beside allocateId prevents provider/cache/LUT paths from forgetting the rollback.
export function withReservedFileSync(projectDir, type, ext, populate) {
  const reservation = reservedFile(projectDir, type, ext);
  try {
    const result = populate(reservation);
    releaseReservation(reservation, result != null);
    return result;
  } catch (error) {
    releaseReservation(reservation, false);
    throw error;
  }
}

export async function withReservedFile(projectDir, type, ext, populate) {
  const reservation = reservedFile(projectDir, type, ext);
  try {
    const result = await populate(reservation);
    releaseReservation(reservation, result != null);
    return result;
  } catch (error) {
    releaseReservation(reservation, false);
    throw error;
  }
}
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