Skip to content

JimLiu/baoyu-skills / skills/baoyu-image-gen

baoyu-image-gen

Verified

AI image generation with OpenAI GPT Image 2.5, Azure OpenAI, Google, OpenRouter, DashScope, Z.AI GLM-Image, MiniMax, Jimeng, Seedream, Replicate and Agnes APIs. Supports text-to-image, reference images, aspect ratios, and batch generation from saved prompt files. Sequential by default; use batch parallel generation when the user already has multiple prompts or wants stable multi-image throughput. Use when user asks to generate, create, or draw images.

FileKindSize
SKILL.mdskill md16.2 KB
references/codex-image2-fallback.mdmarkdown1.6 KB
references/codex-oauth-vs-openai-api-key.mdmarkdown1.4 KB
references/config/first-time-setup.mdmarkdown8.8 KB
references/config/preferences-schema.mdmarkdown2.5 KB
references/providers/agnes.mdmarkdown1.9 KB
references/providers/codex-cli.mdmarkdown5.0 KB
references/providers/dashscope.mdmarkdown4.2 KB
references/providers/minimax.mdmarkdown1.1 KB
references/providers/openrouter.mdmarkdown707 B
references/providers/replicate.mdmarkdown1.4 KB
references/providers/zai.mdmarkdown953 B
references/usage-examples.mdmarkdown4.9 KB
scripts/build-batch.test.tsscript4.5 KB
scripts/build-batch.tsscript7.4 KB
scripts/codex-imagegen/cache.tsscript2.2 KB
scripts/codex-imagegen/logger.tsscript1.3 KB
scripts/codex-imagegen/main.tsexecutablescript11.9 KB
scripts/codex-imagegen/parser.tsscript2.0 KB
scripts/codex-imagegen/spawn.tsscript6.5 KB
scripts/codex-imagegen/types.tsscript1.6 KB
scripts/codex-imagegen/validator.tsscript2.3 KB
scripts/main.test.tsscript18.4 KB
scripts/main.tsscript45.5 KB
scripts/providers/agnes.test.tsscript6.7 KB
scripts/providers/agnes.tsscript4.9 KB
scripts/providers/azure.test.tsscript5.3 KB
scripts/providers/azure.tsscript5.7 KB
scripts/providers/codex-cli.test.tsscript1.6 KB
scripts/providers/codex-cli.tsscript5.8 KB
scripts/providers/dashscope.test.tsscript11.4 KB
scripts/providers/dashscope.tsscript18.1 KB
scripts/providers/google.test.tsscript4.1 KB
scripts/providers/google.tsscript10.5 KB
scripts/providers/jimeng.test.tsscript2.7 KB
scripts/providers/jimeng.tsscript12.5 KB
scripts/providers/minimax.test.tsscript5.1 KB
scripts/providers/minimax.tsscript6.2 KB
scripts/providers/openai.test.tsscript6.0 KB
scripts/providers/openai.tsscript12.4 KB
scripts/providers/openrouter.test.tsscript5.3 KB
scripts/providers/openrouter.tsscript9.7 KB
scripts/providers/replicate.test.tsscript7.0 KB
scripts/providers/replicate.tsscript17.4 KB
scripts/providers/seedream.test.tsscript6.4 KB
scripts/providers/seedream.tsscript9.6 KB
scripts/providers/zai.test.tsscript5.2 KB
scripts/providers/zai.tsscript8.7 KB
scripts/types.tsscript2.3 KB

scripts/codex-imagegen/spawn.ts

View on GitHub
import { spawn, type ChildProcess } from "node:child_process";
import { createWriteStream } from "node:fs";
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { GenError, type CodexRunResult } from "./types.ts";
import { parseEventStream } from "./parser.ts";

export interface SpawnInput {
  instruction: string;
  timeoutMs: number;
  refImages?: string[];
  command?: string;
  commandArgs?: string[];
  completionGraceMs?: number;
  exitGraceMs?: number;
  killGraceMs?: number;
  onStart?: (info: { pid: number | undefined; rawLogPath: string }) => void | Promise<void>;
}

type FinishReason = "exit" | "error" | "timeout" | "turn_completed";

interface Finish {
  reason: FinishReason;
  code: number | null;
  signal: NodeJS.Signals | null;
}

export function turnEndType(line: string): "turn.completed" | "turn.failed" | null {
  const trimmed = line.trim();
  if (!trimmed.startsWith("{")) return null;
  try {
    const type = JSON.parse(trimmed)?.type;
    return type === "turn.completed" || type === "turn.failed" ? type : null;
  } catch {
    return null;
  }
}

function isRunning(child: ChildProcess): boolean {
  return child.exitCode === null && child.signalCode === null;
}

function killTree(child: ChildProcess): void {
  if (!isRunning(child)) return;
  if (process.platform === "win32" && child.pid) {
    const killer = spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], {
      stdio: "ignore",
      windowsHide: true,
    });
    killer.on("error", () => child.kill());
    return;
  }
  child.kill("SIGTERM");
  setTimeout(() => {
    if (isRunning(child)) child.kill("SIGKILL");
  }, 2000).unref();
}

function waitForExit(child: ChildProcess, ms: number): Promise<boolean> {
  if (!isRunning(child)) return Promise.resolve(true);
  return new Promise((resolve) => {
    const timer = setTimeout(() => resolve(!isRunning(child)), ms);
    child.once("exit", () => {
      clearTimeout(timer);
      resolve(true);
    });
  });
}

async function stopChild(child: ChildProcess): Promise<void> {
  if (!isRunning(child)) return;
  killTree(child);
  if (await waitForExit(child, 2000)) return;
  if (process.platform !== "win32") child.kill("SIGKILL");
  await waitForExit(child, 1000);
}

export async function runCodexExec(input: SpawnInput): Promise<CodexRunResult> {
  const start = Date.now();
  const logDir = await mkdtemp(path.join(tmpdir(), "codex-imggen-"));
  const rawLogPath = path.join(logDir, "stream.jsonl");
  const completionGraceMs = input.completionGraceMs ?? 15_000;
  const exitGraceMs = input.exitGraceMs ?? 2_000;
  const killGraceMs = input.killGraceMs ?? 5_000;

  // --skip-git-repo-check: lets the wrapper run from non-git cwds
  //   (e.g. /tmp, or a skill installed under ~/.claude/plugins/...).
  //   Without it, codex refuses with "Not inside a trusted directory".
  const args = input.commandArgs ?? [
    "exec",
    "--json",
    "--sandbox",
    "danger-full-access",
    "--skip-git-repo-check",
  ];
  if (!input.commandArgs) {
    for (const img of input.refImages ?? []) {
      args.push("--image", img);
    }
    args.push("-");
  }

  const logStream = createWriteStream(rawLogPath);
  logStream.on("error", () => {});
  const child = spawn(input.command ?? "codex", args, {
    stdio: ["pipe", "pipe", "pipe"],
    windowsHide: true,
  });

  let stdout = "";
  let stderr = "";
  let pendingLine = "";
  let turnEnded = false;
  let turnCompleted = false;
  let timedOut = false;
  let spawnError: NodeJS.ErrnoException | null = null;
  const timers: NodeJS.Timeout[] = [];

  let resolveFinish!: (f: Finish) => void;
  const finished = new Promise<Finish>((resolve) => {
    resolveFinish = resolve;
  });
  let settled = false;
  const finish = (reason: FinishReason, code: number | null = null, signal: NodeJS.Signals | null = null) => {
    if (settled) return;
    settled = true;
    resolveFinish({ reason, code, signal });
  };

  const onLine = (line: string) => {
    const type = turnEndType(line);
    if (!type) return;
    if (type === "turn.completed") turnCompleted = true;
    if (turnEnded) return;
    turnEnded = true;
    timers.push(
      setTimeout(() => {
        killTree(child);
        finish("turn_completed");
      }, completionGraceMs),
    );
  };

  child.stdout.on("data", (chunk) => {
    const text = chunk.toString();
    stdout += text;
    logStream.write(text);
    const lines = (pendingLine + text).split("\n");
    pendingLine = lines.pop() ?? "";
    lines.forEach(onLine);
  });
  child.stderr.on("data", (chunk) => {
    stderr += chunk.toString();
  });
  child.stdin.on("error", () => {});

  child.on("error", (err: NodeJS.ErrnoException) => {
    spawnError = err;
    finish("error");
  });
  child.on("exit", (code, signal) => {
    timers.push(setTimeout(() => finish("exit", code, signal), exitGraceMs));
  });
  child.on("close", (code, signal) => finish("exit", code, signal));

  timers.push(
    setTimeout(() => {
      timedOut = true;
      killTree(child);
      timers.push(setTimeout(() => finish("timeout"), killGraceMs));
    }, input.timeoutMs),
  );

  if (input.onStart) {
    try {
      await input.onStart({ pid: child.pid, rawLogPath });
    } catch {}
  }

  child.stdin.write(input.instruction);
  child.stdin.end();

  const exit = await finished;
  for (const t of timers) clearTimeout(t);
  await stopChild(child);
  child.stdout.destroy();
  child.stderr.destroy();
  child.unref();

  if (turnEndType(pendingLine) === "turn.completed") turnCompleted = true;
  await new Promise<void>((resolve) => {
    logStream.end(stderr ? `\n--- stderr ---\n${stderr}` : "", () => resolve());
  });

  if (spawnError) {
    const err: NodeJS.ErrnoException = spawnError;
    if (err.code === "ENOENT") {
      throw new GenError("codex_not_installed", "codex CLI not installed", false);
    }
    throw new GenError("spawn_failed", `failed to start codex: ${err.message} (log: ${rawLogPath})`);
  }

  if (!turnCompleted) {
    if (timedOut) {
      throw new GenError("timeout", `codex exec exceeded ${input.timeoutMs}ms (log: ${rawLogPath})`);
    }
    if (exit.code !== 0) {
      if (stderr.includes("command not found") || stderr.includes("not found: codex")) {
        throw new GenError("codex_not_installed", "codex CLI not installed", false);
      }
      throw new GenError(
        "spawn_failed",
        `codex exec exited ${exit.code} signal=${exit.signal} (log: ${rawLogPath})`,
      );
    }
  }

  const parsed = parseEventStream(stdout);
  return {
    ...parsed,
    rawLogPath,
    durationMs: Date.now() - start,
  };
}
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall