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

audio/scripts/lib/heygen.test.mjs

View on GitHub
import { test } from "node:test";
import assert from "node:assert/strict";
import { linkSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { createServer } from "node:http";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
  billingRefusal,
  heygenAuthHeaders,
  heygenAuthMethod,
  heygenBase,
  heygenCredential,
  heygenJSON,
  heygenMessage,
  loadEnvFromDir,
} from "./heygen.mjs";

const HEYGEN_ENV = [
  "HEYGEN_ACCESS_TOKEN",
  "HEYGEN_API_KEY",
  "HYPERFRAMES_API_KEY",
  "HYPERFRAMES_CONFIG_DIR",
  "HYPERFRAMES_ENV",
  "HYPERFRAMES_OAUTH_CLIENT_ID",
  "HYPERFRAMES_OAUTH_TOKEN_URL",
  "HEYGEN_API_BASE",
  "HEYGEN_ALLOW_HTTP",
];

// Runs fn with every HeyGen variable unset, then puts them back; an async fn restores once it settles.
function withCleanHeygenEnv(fn) {
  const previous = Object.fromEntries(HEYGEN_ENV.map((name) => [name, process.env[name]]));
  const restore = () => {
    for (const [name, value] of Object.entries(previous)) {
      if (value === undefined) delete process.env[name];
      else process.env[name] = value;
    }
  };
  for (const name of HEYGEN_ENV) delete process.env[name];
  let result;
  try {
    result = fn();
  } catch (error) {
    restore();
    throw error;
  }
  if (result && typeof result.then === "function") return result.finally(restore);
  restore();
  return result;
}

test("heygenAuthHeaders does not tag API-key requests as CLI traffic, but still carries the media-use tool tag", () => {
  withCleanHeygenEnv(() => {
    process.env.HEYGEN_API_KEY = "hg_test";
    // API-key requests use normal billing; the backend ignores the cli-source
    // header for them, so it's not sent. The tool-attribution header IS sent on
    // every media-use call (any auth type) so the backend can isolate media-use.
    assert.deepEqual(heygenAuthHeaders(), {
      "X-Api-Key": "hg_test",
      "X-HeyGen-Client-Source": "media-use",
    });
  });
});

test("heygenAuthHeaders tags OAuth requests as CLI traffic and with the media-use tool tag", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      writeFileSync(
        join(dir, "credentials"),
        JSON.stringify({
          oauth: {
            client_id: "Zg3LF4FCLoeJoGs2YqMtZ17g",
            token_endpoint: "https://api2.heygen.com/v1/oauth/token",
            access_token: "at_test",
            expires_at: "2099-01-01T00:00:00Z",
          },
        }),
      );
      assert.deepEqual(heygenAuthHeaders(), {
        Authorization: "Bearer at_test",
        "X-HeyGen-Source": "cli",
        "X-HeyGen-Client-Source": "media-use",
      });
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("development audio uses its isolated store and the client and token host from the environment", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "hf-dev-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      process.env.HYPERFRAMES_ENV = "dev";
      process.env.HYPERFRAMES_OAUTH_CLIENT_ID = "fake-client";
      process.env.HYPERFRAMES_OAUTH_TOKEN_URL = "https://auth.example.test/token";
      mkdirSync(join(dir, "dev"));
      writeFileSync(
        join(dir, "dev", "credentials"),
        JSON.stringify({
          oauth: {
            access_token: "dev-at",
            client_id: "fake-client",
            token_endpoint: "https://auth.example.test/token",
          },
        }),
      );
      assert.equal(heygenBase(), "https://api.heygen.com/v3");
      assert.equal(heygenAuthHeaders().Authorization, "Bearer dev-at");
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("a host-injected HEYGEN_ACCESS_TOKEN wins over an API key and is treated as OAuth", () => {
  withCleanHeygenEnv(() => {
    process.env.HEYGEN_ACCESS_TOKEN = "at_host";
    process.env.HEYGEN_API_KEY = "hg_test";
    assert.deepEqual(heygenAuthHeaders(), {
      Authorization: "Bearer at_host",
      "X-HeyGen-Source": "cli",
      "X-HeyGen-Client-Source": "media-use",
    });
    assert.equal(heygenAuthMethod(), "oauth");
  });
});

test("a live login wins over HEYGEN_API_KEY; an expired one gives way to it", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "hf-login-vs-env-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      process.env.HEYGEN_API_KEY = "hg_env";
      const credential = {
        api_key: "saved-wallet",
        oauth: {
          client_id: "Zg3LF4FCLoeJoGs2YqMtZ17g",
          token_endpoint: "https://api2.heygen.com/v1/oauth/token",
          access_token: "at_login",
          expires_at: "2099-01-01T00:00:00Z",
        },
      };
      writeFileSync(join(dir, "credentials"), JSON.stringify(credential));
      assert.deepEqual(heygenCredential(), { headers: { Authorization: "Bearer at_login" } });
      // HeyGen's own base is no gateway, so naming it changes nothing.
      process.env.HEYGEN_API_BASE = "https://api.heygen.com";
      assert.deepEqual(heygenCredential(), { headers: { Authorization: "Bearer at_login" } });
      delete process.env.HEYGEN_API_BASE;
      credential.oauth.expires_at = "2000-01-01T00:00:00Z";
      writeFileSync(join(dir, "credentials"), JSON.stringify(credential));
      assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "hg_env" } });
      writeFileSync(join(dir, "credentials"), JSON.stringify({ api_key: "saved-wallet" }));
      assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "hg_env" } });
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

// Runs fn(dir, notes, project) with a temp credentials dir and a project whose .env sets name=key.
function withProjectEnv(key, received, fn, name = "HEYGEN_API_KEY") {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    const project = mkdtempSync(join(tmpdir(), "heygen-env-"));
    const write = process.stderr.write;
    const notes = [];
    process.stderr.write = (line) => notes.push(String(line));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      writeFileSync(join(project, ".env"), `${name}=${key}\n`);
      if (received !== undefined) {
        mkdirSync(join(project, ".hyperframes"));
        writeFileSync(join(project, ".hyperframes", "received-files.json"), received);
      }
      loadEnvFromDir(project);
      fn(dir, notes, project);
    } finally {
      process.stderr.write = write;
      rmSync(dir, { recursive: true, force: true });
      rmSync(project, { recursive: true, force: true });
    }
  });
}

// A cloned or copied folder has no received-files record; a received one lists its .env.
const PROJECT_KINDS = [
  ["a folder with no received-files record", undefined],
  ["a received folder", JSON.stringify({ files: [".env"] })],
];

for (const [kind, record] of [...PROJECT_KINDS, ["an unreadable received-files record", "{oops"]]) {
  test(`a project .env key from ${kind} gives way to the saved API key`, () => {
    withProjectEnv("hg_project", record, (dir, notes) => {
      writeFileSync(join(dir, "credentials"), JSON.stringify({ api_key: "saved-wallet" }));
      assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "saved-wallet" } });
      assert.deepEqual(notes, []);
    });
  });
}

for (const [projectName, shellName] of [
  ["HEYGEN_API_KEY", "HYPERFRAMES_API_KEY"],
  ["HYPERFRAMES_API_KEY", "HEYGEN_API_KEY"],
]) {
  test(`the shell's ${shellName} wins over a project .env's ${projectName}, with or without a saved key`, () => {
    withProjectEnv(
      "hg_project",
      undefined,
      (dir) => {
        process.env[shellName] = "hg_shell";
        assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "hg_shell" } });
        writeFileSync(join(dir, "credentials"), JSON.stringify({ api_key: "saved-wallet" }));
        assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "hg_shell" } });
      },
      projectName,
    );
  });
}

// Loads a project .env with HEYGEN_API_KEY=hg_received and a saved key; arrange(root, project) places the record.
function receivedBy(arrange, load = (project) => project) {
  return withCleanHeygenEnv(() => {
    const root = mkdtempSync(join(tmpdir(), "heygen-rec-"));
    const project = join(root, "real", "p");
    mkdirSync(project, { recursive: true });
    writeFileSync(join(project, ".env"), "HEYGEN_API_KEY=hg_received\n");
    process.env.HYPERFRAMES_CONFIG_DIR = join(root, "cred");
    mkdirSync(process.env.HYPERFRAMES_CONFIG_DIR);
    writeFileSync(join(root, "cred", "credentials"), JSON.stringify({ api_key: "saved-wallet" }));
    try {
      arrange(root, project);
      loadEnvFromDir(load(project, root));
      return heygenCredential().headers["X-Api-Key"];
    } finally {
      rmSync(root, { recursive: true, force: true });
    }
  });
}

test(
  "a received .env reached through a linked folder is still received",
  { skip: process.platform === "win32" },
  () => {
    const key = receivedBy(
      (root, project) => {
        mkdirSync(join(root, "real", ".hyperframes"));
        writeFileSync(
          join(root, "real", ".hyperframes", "received-files.json"),
          JSON.stringify({ files: ["p/.env"] }),
        );
        symlinkSync(project, join(root, "link"));
      },
      (_project, root) => join(root, "link"),
    );
    assert.equal(key, "saved-wallet");
  },
);

test("a received .env listed under another path to the same file is received", () => {
  const key = receivedBy((_root, project) => {
    mkdirSync(join(project, ".hyperframes"));
    linkSync(join(project, ".env"), join(project, "copy.env"));
    writeFileSync(
      join(project, ".hyperframes", "received-files.json"),
      JSON.stringify({ files: ["copy.env"] }),
    );
  });
  assert.equal(key, "saved-wallet");
});

test("an unreadable record in the project's own folder counts its .env as received", () => {
  const key = receivedBy((_root, project) => {
    mkdirSync(join(project, ".hyperframes", "received-files.json"), { recursive: true });
  });
  assert.equal(key, "saved-wallet");
});

test("a project .env key works with no saved credential, and the process names its file once", () => {
  const lines = [];
  for (const [, record] of PROJECT_KINDS) {
    withProjectEnv("hg_project", record, (_dir, notes, project) => {
      assert.deepEqual(heygenCredential(), { headers: { "X-Api-Key": "hg_project" } });
      heygenCredential();
      lines.push(...notes.map((line) => line.replace(join(project, ".env"), "<file>")));
    });
  }
  assert.deepEqual(lines, [
    "[hyperframes] Using HEYGEN_API_KEY from the project .env (<file>): generated media goes to that key's HeyGen account.\n",
  ]);
});

for (const [why, oauth, state, hint] of [
  [
    "expired",
    { client_id: "Zg3LF4FCLoeJoGs2YqMtZ17g", expires_at: "2000-01-01T00:00:00Z" },
    { expired: true },
    /OAuth token expired — run `npx hyperframes auth refresh`/,
  ],
  [
    "from another client",
    { client_id: "shared-heygen-client", expires_at: "2099-01-01T00:00:00Z" },
    { expired: true, foreign: true },
    /another OAuth client or environment — run `npx hyperframes auth login`/,
  ],
]) {
  for (const [kind, record] of PROJECT_KINDS) {
    test(`a project .env key from ${kind} never replaces a saved login that is ${why}`, () => {
      withProjectEnv("hg_project", record, (dir, notes) => {
        const login = {
          token_endpoint: "https://api2.heygen.com/v1/oauth/token",
          access_token: "at_login",
          ...oauth,
        };
        writeFileSync(join(dir, "credentials"), JSON.stringify({ oauth: login }));
        assert.deepEqual(heygenCredential(), state);
        assert.throws(() => heygenAuthHeaders(), hint);
        assert.deepEqual(notes, []);
      });
    });
  }
}

for (const [kind, record] of PROJECT_KINDS) {
  test(`a malformed credentials file refuses a project .env key from ${kind} and says to fix that file`, () => {
    withProjectEnv("hg_project", record, (dir, notes) => {
      writeFileSync(join(dir, "credentials"), "{not valid");
      assert.equal(heygenCredential(), null);
      assert.throws(() => heygenAuthHeaders(), /can't be read \(not valid JSON\)/);
      assert.deepEqual(notes, []);
    });
  });
}

test("heygenAuthMethod returns api_key for an env API key, without tagging headers", () => {
  withCleanHeygenEnv(() => {
    process.env.HEYGEN_API_KEY = "hg_test";
    assert.equal(heygenAuthMethod(), "api_key");
  });
});

test("heygenAuthMethod returns oauth for a live OAuth credential", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      writeFileSync(
        join(dir, "credentials"),
        JSON.stringify({
          oauth: {
            client_id: "Zg3LF4FCLoeJoGs2YqMtZ17g",
            token_endpoint: "https://api2.heygen.com/v1/oauth/token",
            access_token: "at_test",
            expires_at: "2099-01-01T00:00:00Z",
          },
        }),
      );
      assert.equal(heygenAuthMethod(), "oauth");
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("heygenAuthMethod returns null with no credential at all", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir; // no credentials file written
      assert.equal(heygenAuthMethod(), null);
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("an expired or foreign OAuth login never falls back to a saved API wallet", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "hf-auth-payer-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      const credential = {
        api_key: "other-wallet",
        oauth: {
          client_id: "Zg3LF4FCLoeJoGs2YqMtZ17g",
          token_endpoint: "https://api2.heygen.com/v1/oauth/token",
          access_token: "expired",
          expires_at: "2000-01-01T00:00:00Z",
        },
      };
      writeFileSync(join(dir, "credentials"), JSON.stringify(credential));
      assert.deepEqual(heygenCredential(), { expired: true });
      credential.oauth.expires_at = "2099-01-01T00:00:00Z";
      credential.oauth.client_id = "shared-heygen-client";
      writeFileSync(join(dir, "credentials"), JSON.stringify(credential));
      assert.deepEqual(heygenCredential(), { expired: true, foreign: true });
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("loadEnvFromDir skips a .env folder and loads the .env file above it", () => {
  const root = mkdtempSync(join(tmpdir(), "heygen-env-"));
  const project = join(root, "project");
  mkdirSync(join(project, ".env"), { recursive: true });
  writeFileSync(join(root, ".env"), "ELEVENLABS_API_KEY=from-parent\n");
  const saved = process.env.ELEVENLABS_API_KEY;
  delete process.env.ELEVENLABS_API_KEY;
  try {
    loadEnvFromDir(project);
    assert.equal(process.env.ELEVENLABS_API_KEY, "from-parent");
  } finally {
    if (saved === undefined) delete process.env.ELEVENLABS_API_KEY;
    else process.env.ELEVENLABS_API_KEY = saved;
    rmSync(root, { recursive: true, force: true });
  }
});

test("a project's .env supplies provider keys only, never programs, runtime options or another account", () => {
  const keys = [
    "ELEVENLABS_API_KEY",
    "HYPERFRAMES_PYTHON",
    "HYPERFRAMES_PARAKEET",
    "NODE_OPTIONS",
    "npm_config_registry",
    "DYLD_INSERT_LIBRARIES",
    "HYPERFRAMES_CONFIG_DIR",
    "HEYGEN_ACCESS_TOKEN",
    "HYPERFRAMES_CLI_ENTRY",
    "GOOGLE_APPLICATION_CREDENTIALS",
  ];
  const saved = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
  for (const key of keys) delete process.env[key];
  const project = mkdtempSync(join(tmpdir(), "heygen-env-"));
  writeFileSync(join(project, ".env"), keys.map((key) => `${key}=/project/value`).join("\n"));
  try {
    loadEnvFromDir(project);
    assert.equal(process.env.ELEVENLABS_API_KEY, "/project/value");
    for (const key of keys.slice(1)) assert.equal(process.env[key], undefined, key);
  } finally {
    for (const key of keys) {
      if (saved[key] === undefined) delete process.env[key];
      else process.env[key] = saved[key];
    }
    rmSync(project, { recursive: true, force: true });
  }
});

test("a project's .env cannot name the HeyGen base, so a shell key never leaves for its host", () => {
  withCleanHeygenEnv(() => {
    const project = mkdtempSync(join(tmpdir(), "heygen-env-"));
    writeFileSync(
      join(project, ".env"),
      "HEYGEN_API_BASE=https://proxy.example.com\nHEYGEN_ALLOW_HTTP=1\nHYPERFRAMES_TTS_CONCURRENCY=3\n",
    );
    const savedConcurrency = process.env.HYPERFRAMES_TTS_CONCURRENCY;
    delete process.env.HYPERFRAMES_TTS_CONCURRENCY;
    try {
      process.env.HEYGEN_API_KEY = "hg_shell_real";
      loadEnvFromDir(project);
      assert.equal(process.env.HYPERFRAMES_TTS_CONCURRENCY, "3");
      assert.equal(process.env.HEYGEN_API_BASE, undefined);
      assert.equal(process.env.HEYGEN_ALLOW_HTTP, undefined);
      assert.equal(heygenBase(), "https://api.heygen.com/v3");
    } finally {
      if (savedConcurrency === undefined) delete process.env.HYPERFRAMES_TTS_CONCURRENCY;
      else process.env.HYPERFRAMES_TTS_CONCURRENCY = savedConcurrency;
      rmSync(project, { recursive: true, force: true });
    }
  });
});

test("heygenAuthMethod returns null when the credentials path is a folder", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      mkdirSync(join(dir, "credentials"));
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      assert.equal(heygenAuthMethod(), null);
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("heygenAuthMethod returns null when the credentials path is a symlink loop", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      symlinkSync(join(dir, "credentials"), join(dir, "credentials"));
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      assert.equal(heygenAuthMethod(), null);
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("heygenAuthHeaders says to fix an unreadable credentials path, and to log in when there is none", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      assert.throws(() => heygenAuthHeaders(), /no HyperFrames credentials/);
      mkdirSync(join(dir, "credentials"));
      assert.equal(heygenCredential(), null);
      assert.throws(
        () => heygenAuthHeaders(),
        (error) =>
          error.message.includes(join(dir, "credentials")) &&
          /fix or remove that path/.test(error.message),
      );
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("heygenBase is HeyGen's public API unless a host names another", () => {
  withCleanHeygenEnv(() => {
    assert.equal(heygenBase(), "https://api.heygen.com/v3");
    process.env.HEYGEN_API_BASE = "https://api-canary.heygen.com/";
    assert.equal(heygenBase(), "https://api-canary.heygen.com/v3");
  });
});

test("heygenBase refuses a plain-HTTP host unless HEYGEN_ALLOW_HTTP is set, as the heygen CLI does", () => {
  withCleanHeygenEnv(() => {
    process.env.HEYGEN_API_BASE = "http://127.0.0.1:4100";
    assert.throws(() => heygenBase(), /HEYGEN_ALLOW_HTTP=1/);
    process.env.HEYGEN_ALLOW_HTTP = "1";
    assert.equal(heygenBase(), "http://127.0.0.1:4100/v3");
  });
});

test("a host gateway (HEYGEN_API_BASE with its own HEYGEN_API_KEY) wins over a host OAuth token", () => {
  withCleanHeygenEnv(() => {
    process.env.HEYGEN_API_BASE = "http://127.0.0.1:4100";
    process.env.HEYGEN_ALLOW_HTTP = "1";
    process.env.HEYGEN_API_KEY = "gateway-token";
    process.env.HEYGEN_ACCESS_TOKEN = "at_host";
    assert.deepEqual(heygenAuthHeaders(), {
      "X-Api-Key": "gateway-token",
      "X-HeyGen-Client-Source": "media-use",
    });
    assert.equal(heygenAuthMethod(), "api_key");
  });
});

test("heygenJSON sends its request to the host's HEYGEN_API_BASE with the host's key", async () => {
  /** @type {{ url?: string, key?: string | string[] }} */
  const seen = {};
  const server = createServer((req, res) => {
    seen.url = req.url;
    seen.key = req.headers["x-api-key"];
    res.writeHead(200, { "content-type": "application/json" }).end('{"data":[]}');
  });
  await new Promise((done) => server.listen(0, "127.0.0.1", done));
  const { port } = /** @type {import("node:net").AddressInfo} */ (server.address());
  try {
    await withCleanHeygenEnv(async () => {
      process.env.HEYGEN_API_BASE = `http://127.0.0.1:${port}`;
      process.env.HEYGEN_ALLOW_HTTP = "1";
      process.env.HEYGEN_API_KEY = "gateway-token";
      const reply = await heygenJSON("/voices?limit=1", { headers: heygenAuthHeaders() });
      assert.deepEqual(reply, { data: [] });
    });
    assert.equal(seen.url, "/v3/voices?limit=1");
    assert.equal(seen.key, "gateway-token");
  } finally {
    server.close();
  }
});

test("a base that isn't HeyGen's gets no stored or host OAuth credential, only a key named for it", () => {
  withCleanHeygenEnv(() => {
    const dir = mkdtempSync(join(tmpdir(), "heygen-cred-"));
    try {
      process.env.HYPERFRAMES_CONFIG_DIR = dir;
      writeFileSync(join(dir, "credentials"), JSON.stringify({ api_key: "hg_stored" }));
      process.env.HEYGEN_ACCESS_TOKEN = "at_host";
      process.env.HEYGEN_API_BASE = "https://proxy.example.com";
      assert.equal(heygenCredential(), null);
      assert.throws(() => heygenAuthHeaders(), /no HyperFrames credentials/);
      // HeyGen's own hosts keep every credential source.
      process.env.HEYGEN_API_BASE = "https://api-canary.heygen.com";
      assert.equal(heygenAuthMethod(), "oauth");
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  });
});

test("a refused HyperFrames-plan call becomes one line with the billing command", () => {
  const refused = (code) => ({
    status: 402,
    body: JSON.stringify({ error: { code, message: "raw" } }),
  });
  assert.equal(
    heygenMessage(refused("hf_subscription_required")),
    "This needs a HyperFrames plan. Run `npx hyperframes billing subscribe --skill media-use`: it opens the page and waits.",
  );
  assert.equal(
    heygenMessage(refused("hf_usage_exhausted")),
    "Out of HyperFrames credits. Run `npx hyperframes billing add-credits --skill media-use`: it opens the page and waits.",
  );
  assert.match(
    heygenMessage({ status: 403, body: JSON.stringify({ error: { code: "api_key_required" } }) }),
    /Nothing was charged/,
  );
  // Every other failure keeps HeyGen's own words.
  assert.equal(
    billingRefusal({
      status: 400,
      body: JSON.stringify({ error: { code: "invalid_parameter", message: "bad voice" } }),
    }),
    null,
  );
  assert.equal(
    heygenMessage({ status: 400, body: JSON.stringify({ error: { message: "bad voice" } }) }),
    "bad voice",
  );
});
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