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

patbat-codegen

v0.1.1

Published

Simple template for typescript packages

Readme

PatBat - Constrained Code Generation

A tool for constrained code generation with integrated validation, powered by AI. Use it as a library in your TypeScript/JavaScript projects or directly from the command line.

Prerequisites

  • Bun Runtime
  • Environment Variables:
    • For Anthropic: ANTHROPIC_API_KEY
    • For OpenAI: OPENAI_API_KEY

Installation

bunx patbat-codegen

Usage

SDK Mode

import { AITransformData } from "patbat-codegen";

const result = await AITransformData(
  {
    // Core inputs
    problem: "transform data to get average age and oldest person",
    inputSchema: "z.object({ name: z.string(), age: z.number() })",
    inputData: [
      { name: "Alice", age: 25 },
      { name: "Bob", age: 30 }
    ],
    outputSchema: "z.object({ averageAge: z.string(), oldestPerson: z.string() })"
  },
  {
    // Optional configuration
    failOnInvalidData: false,
    returnGeneratedCode: false,
    minSamplesCount: 1,
    maxSampleTokenSize: 1000,
    validateOutput: false,
    aiAdapterConfig: {
      provider: 'anthropic',
      model: 'claude-3-5-haiku-20241022',
      temperature: 0
    }
  }
);

CLI Mode

The CLI supports multiple ways to provide input and configuration:

1. Single Input File

bunx patbat-codegen --input-path input.json

Where input.json contains all required fields (inputSchema, inputData, outputSchema).

2. Component Files

You can provide each component separately:

bunx patbat-codegen \
  --input-schema-path schema.ts \
  --input-data-path data.json \
  --output-schema-path output-schema.ts

3. Unix-Style Pipeline

Use stdin for any component while specifying which one via the --stdin flag:

# Pipe in complete input
cat input.json | bunx patbat-codegen --stdin input

# Pipe in just the data (or any other component via --stdin)
cat data.json | bunx patbat-codegen \
  --stdin inputData \
  --input-schema-path schema.ts \
  --output-schema-path output-schema.ts

CLI Options

Core Options

  • --input-path <path> - Path to complete input JSON file
  • --config-path <path> - Path to configuration JSON file
  • --problem <text> - Override or set the problem description

Component File Options

  • --input-schema-path <path> - Path to input schema file
  • --input-data-path <path> - Path to input data JSON file
  • --output-schema-path <path> - Path to output schema file

Input Method

  • --stdin <type> - Read from stdin: "input", "inputData", "inputSchema", or "outputSchema"

Debug Options

  • --debug - Write generated code to code.tmp.ts
  • --stats - Write full response to stats.tmp.json

Output Handling

  • stdout contains only the transformation result
  • Warnings and errors are written to stderr
  • Debug files (if enabled) are written to:
    • code.tmp.ts - Generated TypeScript code
    • stats.tmp.json - Complete execution statistics

Configuration Options

Input Schema

type CodegenInput = {
  problem: string;        // Transformation description
  inputSchema: string;    // Zod schema for input validation
  inputData: any[];      // Array of data to transform
  outputSchema: string;   // Zod schema for output validation
}

Configuration Schema

type CodegenConfig = {
  failOnInvalidData: boolean;     // Stop on validation errors
  returnGeneratedCode: boolean;   // Include code in response
  minSamplesCount: number;        // Minimum samples for context
  maxSampleTokenSize: number;     // Max tokens for sampling
  validateOutput: boolean;        // Validate transformation result
  aiAdapterConfig: {
    provider: 'anthropic' | 'openai-standard' | 'openai-custom';
    model: string;
    temperature?: number;
    maxTokens?: number;
  }
}

Testing

Run the CLI tests with:

bash ./samples/cli-sample1/run-test.sh

Future Improvements

  1. Smart Sample Selection
    Planning to integrate the "pickasso" npm package for more intelligent data sampling.

  2. Modular Architecture
    The following modules are being prepared for separate npm packages:

    • aidap - AI adapter module for different providers
    • zodinator - Zod convenience utilities

    These modules are already well-separated in the codebase and will be published independently.

  3. maxRetries, timeoutMs, lifecycle hooks are not implemented yet on this branch

  4. Correct shebangs for the right runtimes during build