npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

text-gen-cli

v0.1.0

Published

Production-grade Bun + TypeScript CLI scaffold

Readme

text-gen

text-gen is a Bun + TypeScript CLI for provider-agnostic text generation with:

  • OpenAI (text-gen openai)
  • Gemini (text-gen gemini)
  • Claude (text-gen claude)

It supports direct/file/stdin prompts, template interpolation, JSON output, and writing generated text to disk.

Install and Setup (Bun)

Requirements

  • Bun >=1.1.0

Install dependencies

bun install

Run in development

bun run dev -- openai --model gpt-4o-mini --user "Say hello"

Build

bun run build

API Keys

Set provider keys in your shell environment:

export OPENAI_API_KEY="your_openai_key"
export GEMINI_API_KEY="your_gemini_key"
# or use GOOGLE_API_KEY for Gemini
export GOOGLE_API_KEY="your_google_key"
export ANTHROPIC_API_KEY="your_anthropic_key"

Provider key resolution:

  • openai: OPENAI_API_KEY
  • gemini: GEMINI_API_KEY or GOOGLE_API_KEY
  • claude: ANTHROPIC_API_KEY

Command Reference

Global

text-gen --help
text-gen -h
text-gen --version
text-gen -v

Providers

text-gen openai [options]
text-gen gemini [options]
text-gen claude [options]

Provider help:

text-gen openai --help
text-gen gemini --help
text-gen claude --help

Full Flag Reference

All provider commands support:

  • --model <id>: optional model identifier (defaults shown below)
  • --temperature <number>: sampling temperature (validated to 0..2)
  • --max-tokens <integer>: max output tokens (integer, validated >0)
  • --top-p <number>: nucleus sampling (validated to 0..1)
  • --system <text>: inline system prompt
  • --user <text>: inline user prompt
  • --system-file <path>: read system prompt from file
  • --user-file <path>: read user prompt from file
  • --var <key=value>: template variable, repeatable
  • --json: print structured JSON payload
  • --output <path>: write generated text to a file
  • -h, --help: command help

Rules:

  • If omitted, --model defaults to:
    • openai: gpt-5.2-chat-latest
    • gemini: gemini-pro-latest
    • claude: claude-sonnet-4-20250514
  • --var can be repeated; most other flags can only appear once.
  • You cannot combine --system with --system-file.
  • You cannot combine --user with --user-file.

Prompt Input Modes

User prompt resolution order:

  1. --user <text>
  2. --user-file <path>
  3. stdin fallback (only if no --user or --user-file is provided)

System prompt can come from:

  • --system <text>, or
  • --system-file <path>

Direct text

text-gen openai --model gpt-4o-mini --user "Summarize this release note."

File input

text-gen gemini --model gemini-2.5-flash --system-file prompts/system.txt --user-file prompts/user.txt

stdin fallback

echo "Write a 1-line tagline for a coffee shop." | text-gen claude --model claude-3-7-sonnet

Template Variables

Use {{key}} placeholders in prompt text and pass values via repeatable --var key=value.

Example template:

Write a {{tone}} summary about {{topic}}.

CLI usage:

text-gen openai \
  --model gpt-4o-mini \
  --user "Write a {{tone}} summary about {{topic}}." \
  --var tone=concise \
  --var topic=observability

File + variables:

text-gen gemini \
  --model gemini-2.5-flash \
  --user-file prompts/template.txt \
  --var product="text-gen" \
  --var audience=developers

Output Modes

Default (plain text)

Without --json, stdout is only the generated text.

JSON mode (--json)

With --json, stdout is:

{
  "success": true,
  "provider": "openai",
  "model": "gpt-4o-mini",
  "text": "Hello world",
  "usage": {
    "inputTokens": 1,
    "outputTokens": 2,
    "totalTokens": 3
  },
  "finish_reason": "stop"
}

Notes:

  • usage and finish_reason can be null depending on provider response.
  • raw provider output is not printed by the CLI payload.

--output <path> behavior

  • Always writes generated text to the target file.
  • Still prints to stdout (plain text without --json, JSON payload with --json).

Examples

OpenAI

text-gen openai \
  --model gpt-4o-mini \
  --system "You are concise." \
  --user "Explain retries in distributed systems in 3 bullets." \
  --temperature 0.2

Gemini

text-gen gemini \
  --model gemini-2.5-flash \
  --user "Generate 5 release-note headlines for a CLI tool." \
  --top-p 0.9 \
  --max-tokens 120

Claude

text-gen claude \
  --model claude-3-7-sonnet \
  --user "Rewrite this paragraph for a technical audience." \
  --json

stdin + output file

cat prompts/user.txt | text-gen openai --model gpt-4o-mini --output generated.txt

file prompt + JSON

text-gen claude --model claude-3-7-sonnet --user-file prompts/user.txt --json

Troubleshooting

Missing API keys

Examples:

  • OpenAI: Missing API key for OpenAI. Fix: set OPENAI_API_KEY...
  • Gemini: Missing API key for Gemini. Fix: set GEMINI_API_KEY or GOOGLE_API_KEY...
  • Claude: Missing API key for Claude. Fix: set ANTHROPIC_API_KEY...

Fix by exporting the required key(s) before running.

Conflicting prompt arguments

If both inline and file are passed for the same field:

  • --user + --user-file
  • --system + --system-file

CLI fails with a conflict error. Use one source per field.

Unresolved template variables

If placeholders remain after interpolation, CLI fails, for example:

Unresolved template variables in user prompt: {{topic}}. Provide values via --var key=value.

Add all required --var key=value entries.

Flag parsing/validation failures

Examples:

  • Empty model value still fails, e.g. --model without a value.
  • Bad number: Invalid --temperature value "nan". Expected a number.
  • Bad integer: Invalid --max-tokens value "12.5". Expected an integer.
  • Range checks: temperature must be 0..2, topP must be 0..1, and maxTokens must be >0.

Missing user prompt

If no --user, no --user-file, and no stdin input:

Missing user prompt. Provide --user, --user-file, or pipe content via stdin...

Development, Scripts, and Tests

  • bun run dev: run CLI entrypoint in development
  • bun run build: build distributable files to dist/
  • bun run typecheck: TypeScript type checks (tsc --noEmit)
  • bun run test: run test suite (bun test)
  • bun run check: run typecheck then test

Local verification:

bun run typecheck
bun test