Skip to content
alex-j-bPublic

About

🧬 autocli builds editable site CLIs from recorded browser traffic.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

autocli logo

🧬 autocli

Build editable site CLIs from recorded browser traffic.

Turn a mitmproxy flow capture into a standalone Python CLI workspace with commands, fixtures, processors, goldens, tests, and a refinement skill for your coding agent.

Python 3.12+ uv License Repository


Table of Contents

🧭 What is autocli?

autocli is a factory for building per-site command-line tools from recorded browser traffic.

It compiles a mitmproxy flow capture into a standalone Python workspace. The generated workspace is intentionally editable: it gives you the first draft of commands, fixtures, request processors, response processors, goldens, tests, and a workspace-local runtime. From there, the normal flow is to refine the generated CLI shape with AI assistance until it feels like a real user-facing tool.

πŸ“‹ Requirements

  • Python 3.12+
  • uv

⚑ Get Started

Install autocli from the repository:

uv tool install autocli --from git+https://github.com/alex-j-b/autocli.git

Or, while developing locally:

uv tool install --editable .

Record browser traffic with mitmweb, filter it down to the requests you want to keep, and export the selected flows to capture.flow.

Build a workspace from a mitmproxy capture:

autocli build capture.flow --output-dir <workspace_cli>

Then refine and run the generated CLI:

cd <workspace_cli>

# Use skills/build-cli/SKILL.md with your coding assistant to finalize the CLI shape.

uv tool install --editable .
uv run pytest -q commands/<command-id>/tests/test_command.py
<workspace_cli> --help

πŸ” Workflow

1. Record a capture

Use mitmweb, mitmproxy's browser-based UI, to record and inspect browser traffic.

First-time setup: after mitmweb is running and your browser is using it as an HTTP(S) proxy, open http://mitm.it and install/trust the mitmproxy CA certificate for your OS/browser. This is required to decrypt HTTPS traffic; see mitmproxy's certificate docs.

Typical macOS workflow:

  1. Start mitmweb, limiting capture to the target host (e.g. amazon.com):

    mitmweb --listen-host 127.0.0.1 --listen-port 8080 --web-host 127.0.0.1 --web-port 8081 --allow-hosts '(^|\.)amazon\.com:443$'
  2. Route Wi-Fi web traffic through mitmproxy:

    networksetup -setwebproxy "Wi-Fi" 127.0.0.1 8080 && networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 8080 && networksetup -setwebproxystate "Wi-Fi" on && networksetup -setsecurewebproxystate "Wi-Fi" on
  3. Open the mitmweb UI at http://127.0.0.1:8081, perform the browser actions you want to turn into CLI commands, then filter out unrelated flows.

  4. In mitmweb, choose File -> Save filtered and save the result as capture.flow.

  5. When finished, disable the macOS proxy settings for Wi-Fi.

    networksetup -setwebproxy "Wi-Fi" 127.0.0.1 8080 && networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 8080 && networksetup -setwebproxystate "Wi-Fi" off && networksetup -setsecurewebproxystate "Wi-Fi" off

2. Build a workspace

Generate a new workspace from a flow capture.

autocli build capture.flow --output-dir <workspace_cli>

3. Refine the generated CLI

Use skills/build-cli/SKILL.md with your coding assistant to review generated commands, rename or merge noisy captures, shape arguments and output contracts, implement processors, and approve goldens.

autocli build prints the path to the generated refinement skill.

That refinement workflow is designed to:

  • inspect generated commands and fixtures
  • identify duplicates and awkward capture-derived names
  • reshape the CLI around user-facing concepts and propose it for approval
  • implement each command one by one, including processors/pre.py and processors/post.py
  • update goldens and run focused tests until the final command set is accepted
  • approve or give feedback on each command

4. Test and run

Run generated contract tests, inspect help output, and execute live commands when needed.

The installed CLI name is set from the output directory name, normalized to kebab-case, and stored in [tool.autocli].executable_name. You can customize it with --executable-name my-cli.

For example, --output-dir my-workspace-cli creates a workspace that installs a my-workspace-cli executable after running:

uv tool install --editable .

πŸ“¦ Generated Workspace

Every generated workspace includes:

<workspace_cli>/
β”œβ”€β”€ pyproject.toml                  # Workspace metadata and installed CLI name
β”œβ”€β”€ <site_module>/                  # Generated runtime and test helpers
β”œβ”€β”€ skills/
β”‚   └── build-cli/
β”‚       └── SKILL.md                # Refinement workflow for your coding agent
└── commands/
    └── <command-id>/
        β”œβ”€β”€ command.yaml            # Command metadata, request mapping, completion flag
        β”œβ”€β”€ fixtures/
        β”‚   └── <case-id>/          # Representative captured request/response fixture
        β”œβ”€β”€ goldens/                # Approved post-processed output
        β”œβ”€β”€ processors/
        β”‚   β”œβ”€β”€ pre.py              # Request shaping
        β”‚   └── post.py             # Output shaping
        └── tests/
            └── test_command.py     # Generated offline contract test

The first build must target an empty output directory. Later runs into the same generated workspace are append-only: new command trees are added, and existing ones are left in place.

πŸ§ͺ Generated Workspace Behavior

Generated workspaces are editable CLI projects. They contain the generated runtime, command definitions, fixtures, processors, tests, and local agent guidance needed to refine a site-specific CLI.

Command lifecycle

  • Generated command names, arguments, and output shapes are a first pass, not the final UX.
  • Every generated command starts incomplete and is hidden from normal CLI discovery.
  • Running a command's generated contract test updates its completion flag.
  • Only completed commands are registered in normal CLI help and execution.
  • --raw returns the unprocessed response body.

Testing and replay

  • Generated tests stay offline: they call the generated CLI with --replay, which uses fixture responses instead of making network calls.
  • --replay is only available when AUTOCLI_TEST_MODE=true.

Live authentication

  • Session-sensitive headers are stripped from generated fixtures and command definitions.
  • For normal live runs, store browser-session headers in the system keyring with <workspace_cli> auth store-headers.
  • The generated CLI reads those keyring headers at runtime and merges only session-sensitive headers into live requests.
  • PLAYWRIGHT_HEADERS_JSON is only a generated CLI runtime override. Use it for temporary manual runs or CI when the keyring is unavailable.
  • If both are present, PLAYWRIGHT_HEADERS_JSON takes precedence over the keyring.

⌨️ Command Reference

Build a workspace

autocli build capture.flow --output-dir <workspace_cli>

Build with a custom executable name

autocli build capture.flow --output-dir <workspace_cli> --executable-name my-cli

Inspect the finalized CLI

cd <workspace_cli>
uv tool install --editable .
<workspace_cli> --help
<workspace_cli> <command path> --help

Run a command live

cd <workspace_cli>
<workspace_cli> <command path>

Run a generated contract test

cd <workspace_cli>
uv run pytest -q commands/<command-id>/tests/test_command.py

πŸ› οΈ Develop autocli

uv run pytest -q
uv tool install --editable .

About

🧬 autocli builds editable site CLIs from recorded browser traffic.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages