architecture

A design guide for ocli, a TypeScript command-line tool that turns OpenAPI descriptions into commands for calling web APIs. It explains how settings, cached API descriptions, command search, and HTTP requests fit together.

In plain words
What is it for?
Use it when developing, reviewing, or debugging ocli features such as API profiles, OpenAPI loading, command filtering, command search, or HTTP request handling.
Why use it?
It gives developers one clear map of how the tool works, so changes can be made without guessing which component is responsible.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/evilfreelancer/openapi-to-cli/architecture
Clone the repo
git clone --depth 1 https://github.com/EvilFreelancer/openapi-to-cli

Made for: Cursor.

Per session 1,404 This file is loaded in full into every session.
When invoked 1,404 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01404 $0.01404
Opus 5 $0.00702 $0.00702
Sonnet 5 $0.00281 $0.00281
Haiku 4.5 $0.00140 $0.00140

Measured yesterday against content hash 373afaac64a5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

architecture scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/architecture.mdc · 91 lines

How it starts

The opening of the file, as written. The whole thing — 91 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Architecture of openapi-to-cli (ocli)

ocli is a TypeScript/Node CLI that converts OpenAPI/Swagger specs into runtime CLI commands. No code generation: at every invocation it loads a cached spec and builds command definitions on the fly.

Data flow

ocli profiles add <name> --api-base-url ... --openapi-spec ...
       |
       v
ConfigLocator -> .ocli/ dir (global or local)
       |
       v
ProfileStore  -> profiles.ini (read/write/select)
       |
       v
OpenapiLoader -> fetches spec, caches under .ocli/specs/<profile>.json
       |
       v
OpenapiToCommands -> parses spec, applies include/exclude filters,
                     builds CliCommand[] (name, method, path, options, body schema)
       |
       v
CommandSearch (BM25)  -> ranks commands by NL query or regex
       |
       v
cli.ts (yargs) -> resolves profile + spec, dispatches: profiles | use | commands | <toolName>
       |
       v
HttpClient (axios)    -> performs the real HTTP request to API_BASE_URL

Components (mapping to src/)

  • config.ts - ConfigLocator. Finds .ocli/ (global ~/.ocli/, local in CWD), resolves profiles.ini paths.
  • profile-store.ts - ProfileStore, Profile. Reads/writes profiles.ini, tracks current profile, validates fields.
  • openapi-loader.ts - OpenapiLoader. Loads spec from URL or local file, caches it to .ocli/specs/<profile>.json, refreshes on demand. Resolves external $ref across multi-file specs.
  • openapi-to-commands.ts - OpenapiToCommands, CliCommand, CliCommandOption. Walks the spec, applies include/exclude filters, expands path-level params, resolves local $ref, builds command names with optional prefix, expands enum/default/nullable/oneOf schema hints for --help.
  • command-search.ts - CommandSearch. BM25 over (name, method, path, description, options[].name), plus regex fallback. Same engine used by both ocli commands and any future agent skill.
  • command-args.ts - findUnknownFlags, acceptsFreeFormBody, formatUnknownFlagsError. Validates parsed flags of a dynamic command against CliCommand.options, suggests the closest declared name, and keeps the free-form body passthrough for body-capable operations whose spec declares no body.
  • bm25.ts - tokenizer + BM25 scorer, no I/O.
  • cli.ts - ocli entry point. yargs command tree: profiles add|remove|list, use, commands, and dynamic per-spec commands. Builds the axios request from a CliCommand + parsed args; injects auth, custom headers, server URL overrides.
  • version.ts - generated by scripts/generate-version.js during prebuild. Do not edit by hand.

Read the full file on GitHub · 91 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 91 lines · 1,404 tokens per session scan A 373afaac64a5

Subscribe to this mod's changes

architecture is a cursor rule published in the GitHub repository EvilFreelancer/openapi-to-cli (256 stars, last pushed 11d ago), licensed MIT. It adds 1,404 tokens to every session, about $0.0070 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.