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

@cli-schema/spec

v0.2.0

Published

TypeScript types, meta-schema, and validator for the CLI Schema specification (https://github.com/cli-schema/cli-schema)

Downloads

6,043

Readme

@cli-schema/spec

TypeScript types, the vendored meta-schema, and a validator for the CLI Schema specification v1 — the open standard for describing command-line interfaces in a language-agnostic, machine-readable way.

This is the only package in the cli-schema-js monorepo with no CLI-framework dependency. It defines the shape of a CLI Schema document; @cli-schema/commander is what actually produces one from a real CLI.

Quickstart

npm install @cli-schema/spec
import { validate, SCHEMA_VERSION, type CliSchema } from '@cli-schema/spec'

const doc: CliSchema = {
  schemaVersion: SCHEMA_VERSION,
  name: 'mytool',
  version: '1.0.0',
}

const result = validate(doc)
if (!result.valid) throw new Error(JSON.stringify(result.errors, null, 2))

That's the minimum: a document only needs schemaVersion, name, and version to be valid — everything else (commands, parameters, environment, intent, ...) is optional enrichment.

Purpose

CLI help text is written for humans, completion scripts are hand-authored per shell, and AI agents guess flags. CLI Schema fixes this by defining one JSON document format that describes a program's commands, parameters, intent, auth requirements, environment dependencies, and output capabilities — so agents, IDEs, shell-completion generators, and docs tooling can all read the same document instead of re-deriving it.

@cli-schema/spec is the compile-time and runtime contract for that format: the types you build a document against, and the validator you check it with before trusting it.

Features

  • Full v1 type coverage — every object in the spec has a corresponding TypeScript interface: CliSchema (root), Command, Namespace, Parameter, Constraint, Intent, Output, Environment, EnvVar, ConfigFile, DefaultHandler, Shortcut, Deprecation.
  • The normative meta-schema, vendoredschema/cli-schema.meta-schema.json from the spec repo, re-exported at @cli-schema/spec/meta-schema.json for tools that want the raw JSON Schema directly (e.g. to validate in a non-JS pipeline, or feed to a codegen tool).
  • A ready-to-use validatorvalidate() / assertValid(), backed by ajv's 2020-12 dialect support. No need to wire up ajv yourself.
  • inferIntentFromHttp — a small pure helper for CLIs that wrap HTTP APIs: derives a reasonable {@link Intent} from an HTTP verb (GET/HEAD → safe & idempotent, PUT → idempotent, DELETE → destructive & idempotent, POST/PATCH → unset, since their semantics are endpoint-specific).
  • Vendor extensions typed — every object that permits x- prefixed fields (spec §14) is typed to accept them ([extension: \x-${string}`]: unknown), so x-my-tool: {...}type-checks withoutas any`.

Usage

Building a document by hand

The types double as documentation of the format — reach for the spec itself for full field semantics, but a well-populated document looks like:

import type { CliSchema } from '@cli-schema/spec'

const doc: CliSchema = {
  schemaVersion: 1,
  name: 'gh',
  version: '2.45.0',
  description: 'GitHub CLI — bring GitHub to your terminal',
  requiresAuth: true,
  authCommands: ['auth login', 'auth logout'],
  reservedMetaCommands: ['__schema'],
  commands: [
    {
      name: 'status',
      summary: 'Print information about relevant issues, pull requests, and notifications',
      intent: { destructive: false, idempotent: true, requiresAuth: true },
    },
  ],
  namespaces: [
    {
      segment: 'repo',
      commands: [
        {
          name: 'delete',
          path: ['repo'],
          parameters: [
            { role: 'positional', name: 'repository', type: 'string', required: true },
            { role: 'confirmationSkip', name: 'yes', type: 'boolean', required: false },
          ],
          intent: { destructive: true, idempotent: true, scope: 'global', requiresConfirmation: true },
        },
      ],
    },
  ],
}

In practice you'll usually generate this from a live CLI rather than write it by hand — see @cli-schema/commander.

Validating an untrusted document

Per spec §15, consumers should treat schema documents as untrusted input:

import { validate, assertValid } from '@cli-schema/spec'

const { valid, errors } = validate(untrustedDoc)
// errors is an ajv ErrorObject[] — empty when valid

assertValid(untrustedDoc) // throws with a formatted message if invalid

Reading the raw meta-schema

import metaSchema from '@cli-schema/spec/meta-schema.json' with { type: 'json' }

Useful if you want to validate documents with your own ajv instance, a different validator entirely, or a non-JS tool.

Deriving intent from an HTTP verb

import { inferIntentFromHttp } from '@cli-schema/spec'

inferIntentFromHttp('DELETE') // { destructive: true, idempotent: true, scope: 'global' }
inferIntentFromHttp('POST')   // undefined — annotate explicitly, semantics vary per endpoint

Related packages

License

MIT