CLI Printing Press

repository·main·Indexed 25 days ago

https://github.com/mvanhorn/cli-printing-press

A tool to generate high-performance, agent-native CLIs and MCP servers for any API or website. It produces Go-based binaries featuring local-first SQLite data layers, FTS5 search, and token-efficient flags like `--compact`. The tool can generate specifications from OpenAPI specs, HAR files, or by capturing browser traffic. It supports a 'Creativity Ladder' of sophistication ranging from basic API wrappers to advanced behavioral insights and domain analytics.

Tokens
213.8K
Snippets
359
Records
1K
Agent score
88%

What's inside cli-printing-press

  1. Core Features and Capabilities of CLI Printing Press

    main

    CLI Printing Press generates domain-aware CLIs and MCP servers from API specifications. Key capabilities include:

    • Local-first data layer: Generates domain-specific SQLite tables, FTS5 full-text search indexes, and incremental sync with cursor tracking. This enables offline sync, millisecond search, and direct sql querying.
    • Machine-owned freshness: Supports bounded pre-read refreshes via cache.enabled to keep local stores current when using --data-source auto.
    • Agent-native design:
      • Human-friendly tables in terminals.
      • Automatic JSON output when piped (no --json flag required).
      • --compact flag to reduce token usage by 60-80% by dropping non-essential fields.
      • Typed exit codes (0, 2, 3, 4, 5, 7) for agent self-correction.
      • --dry-run for safe exploration.
    • Spec Generation: If no OpenAPI spec is available, the tool can reverse-engineer an API by capturing traffic from a website.
    • Dual Interface: Generates both a Cobra-based CLI (<api>-pp-cli) for shell agents and an MCP server (<api>-pp-mcp) for IDE agents (Claude Desktop, Cursor, etc.) from a single specification.
  2. Understand Library PR Plumbing for /printing-press-amend

    main

    The /printing-press-amend workflow uses a specific 'plumbing' pattern to manage the lifecycle of a Pull Request (PR) against the mvanhorn/printing-press-library repository. This process follows a sequence of: fork/clone management $\rightarrow$ managed-clone setup $\rightarrow$ branch creation $\rightarrow$ commit $\rightarrow$ push $\rightarrow$ PR creation.

    Note on Drift: This plumbing is a specialized version of the patterns used in /printing-press-publish. While similar, it is adapted specifically for patching existing CLI tools rather than publishing new ones. If the publishing plumbing changes, this amend plumbing may require manual auditing.

  3. Compare CLI vs MCP usage in Cursor

    main

    Printing Press provides both a Cobra-based CLI and an MCP server for the same specification. Choose based on your priority:

    • CLI (Shell-based): Best for saving context tokens. Use this flow (Skills + Terminal) if you want to minimize the amount of data sent to the LLM.
    • MCP (Tool-based): Best for IDE-native tool discovery. Use this if you want the tools to appear directly in Cursor's native tool interface.
  4. Understand the Steinberger Scorecard scoring architecture

    main

    The Steinberger scorecard uses a two-tier scoring system where each tier contributes a maximum of 50 points to a total score (0-100).

    Tier 1: Infrastructure

    Max Raw Base: 200 points (20 dimensions, 0-10 each). Focus: Core CLI stability, auth, error handling, README, and MCP (Model Context Protocol) quality.

    Tier 2: Domain Correctness

    Max Raw Base: 60 points (7 dimensions, varying max). Focus: Path validity, auth protocols, data pipeline integrity, sync correctness, type fidelity, dead code, and live API verification.

    Total Score Formula

    1. tier1Normalized = (tier1Raw * 50) / tier1Max
    2. tier2Normalized = (tier2Raw * 50) / tier2Max
    3. Total = tier1Normalized + tier2Normalized
  5. Understand Printing Press terminology

    main

    To communicate effectively with the Printing Press, use the following terminology:

    • The Printing Press: The entire system that produces CLIs. Use this name for all user-facing output.
    • Generator: The subsystem containing templates that emit Go code (internal/generator/).
    • Scorer: The subsystem containing tools that grade output (e.g., verify, dogfood, scorecard).
    • Skills: The SKILL.md instructions that guide the agent during generation.
    • Binary: The Go CLI itself, including commands, flags, and parsers (cmd/cli-printing-press/).
    • Printed CLI: A specific CLI produced by the Printing Press for a particular API (e.g., notion-pp-cli).
  6. Review CLI generation quality gates and agent-native flags

    main

    The Printing Press CLI generation process includes several built-in quality gates and agent-optimized features:

    Quality Gates:

    • go mod tidy
    • go vet
    • go build
    • --help validation
    • version check
    • doctor command

    Agent-Native Flags: These flags are wired across 80+ commands to support automated interaction:

    • --json
    • --select
    • --compact
    • --csv
    • --dry-run
    • --agent
  7. Understand Auth Error Handling in Generated CLIs

    main

    Generated CLIs in this project use a pattern-matching approach to provide actionable feedback when authentication fails. Instead of generic error messages, the CLI identifies specific authentication issues (even when APIs return HTTP 400 instead of 401/403) and provides the exact environment variable required and a setup command.

    Key Behaviors:

    • Actionable Hints: Errors include the specific environment variable name (e.g., STEAM_API_KEY) and a one-line setup command (e.g., export STEAM_API_KEY=<your-key>).
    • Key Discovery: If a registration URL is known for the API, the error message includes a Get a key at: <url> line.
    • Per-Call Validation: Authentication is checked per-call rather than at startup. This allows CLIs with mixed-auth APIs to function correctly for endpoints that do not require credentials, even if the environment variable is not set.
    • Best-Effort URLs: If a key registration URL cannot be determined, the CLI simply omits the URL line rather than showing a placeholder or an incorrect link.
  8. Understand write-through caching behavior

    main

    In some CLI implementations, the local SQLite store only grows via explicit sync commands. This means browsing or searching via the live API does not automatically populate the local searchable corpus.

    For large-catalog APIs where a full sync is impractical, look for implementations that support 'write-through caching,' where successful live API reads are automatically upserted into the local store to build the index incrementally.

  9. Understand the Printing Press Pipeline flows

    main

    The Printing Press provides different ways to execute work flows. While the managed pipeline is the primary structure, two other entrypoints exist that share similar logic but different execution models:

    • printing-press run: This command drives the MakeBestCLI flow. It compresses the entire process into a single call and returns a FullRunResult. Its internal steps (research, generate, polish, coverage, dogfood, verification, workflow-verify, scorecard, fix plans, publish) map to the managed phases but do not utilize the formal phase state machine.
    • /printing-press skill: This uses a high-level Phase 0..5 layout. This is a compressed version of the work rather than a competing contract, and its artifacts should match the shape described in the managed pipeline phases.
  10. Understand the Discovery Manuscript Provenance structure

    main

    When generating a CLI via discovery methods (like Browser Sniff), the system preserves evidence of how the API was discovered. This evidence is stored in a dedicated discovery/ directory within the API run directory. This ensures reproducibility and auditability by recording what was observed, what was inferred, and the confidence levels for each endpoint.

    Directory Structure

    Discovery artifacts are stored in $API_RUN_DIR/discovery/ and are prefixed by the method used (e.g., sniff-*).

    • Browser Sniff (Shipped): Uses a single browsing session to capture pages visited, HAR/capture files, and response samples.
    • Crowd-Sniff (Pending): Uses npm SDKs and GitHub code search to analyze source tiers and frequency counts.

    Archival and Publishing

    • The archive step copies the discovery/ directory to $PRESS_MANUSCRIPTS/<api>/<run-id>/discovery/.
    • The publish package command includes the discovery directory in the package if it exists. The absence of a discovery/ directory is normal for non-discovery CLIs and is not treated as an error.
  11. Understand the Printing Press Pipeline paths

    main

    The Printing Press offers two ways to generate a CLI for an API:

    1. Fast Path (/printing-press skill): Runs the entire generation flow end-to-end in a single session. It produces a CLI and an MCP server and reports the result immediately.
    2. Managed Path (printing-press pipeline): A 9-phase pipeline that breaks the work into discrete, inspectable steps. This path allows users to stop, resume, re-run, or inspect specific phases. Each phase has its own plan file, artifacts directory, and quality gates.

    Both paths aim for the same quality standard.