crafter station / gov-tech · v0.6.1

Mapping SUNAT,
making it agent-ready

Agent-first CLI for Peru's tax authority. CPE emission (UBL 2.1 + XAdES + SOAP), SIRE filing, GRE shipping notices, REST OAuth APIs, RHE/F616 — all under one binary.

$ bun add -g @crafter/sunat-cli

# Install globally
$ bun add -g @crafter/sunat-cli

# Introspect schema (agents self-serve)
$ sunat-cli schema cpe-factura --output json
{ "command": "cpe factura emit", "fields": {...} }

# Always dry-run first
$ sunat-cli cpe factura preview --params @factura.json
{ "dryRun": true, "hash": "sha256:...", "validacion": {"ok": true} }

# Ship it — UBL 2.1 + XAdES + SOAP, end-to-end
$ sunat-cli cpe factura emit --params @factura.json --yes
 Aceptado · CDR 0000 · F001-1234
61%
Agent-ready
9
SUNAT domains
283
Tests passing
0
CAPTCHAs

Everything SUNAT, one command

CPE Emission (Factura, Boleta, NC, ND)

UBL 2.1 + XAdES-BES + SOAP directo a SUNAT. End-to-end verified against beta.

$ sunat-cli cpe factura emit \
  --params '{"serie":"F001",...}' --yes

GRE Remitente (Guía Modal 02)

REST API + JWT. Tracker idempotente, retries con backoff.

$ sunat-cli cpe gre emit \
  --params @guia.json --yes

SIRE RVIE + RCE

Propuesta de ventas/compras, ticket polling, descarga ZIP, importar via TUS 1.0.0.

$ sunat-cli sire rvie propuesta \
  --periodo 202504 --yes

Resumen Diario + Baja

Boletas <S/700 batched, comunicación de baja con ticket polling.

$ sunat-cli cpe resumen send \
  --fecha 2026-04-29 --yes

RHE + F616 (personas naturales)

Browser login without CAPTCHA. RHE in batch, F616 mensual read headless from the declaration API.

$ sunat-cli f616 declare --json '{"periodo":"2026-03"}'

OS Keychain Secrets

Store cert passwords and clave SOL in the macOS/Linux keychain. Hidden prompt keeps secrets out of shell history and env vars.

$ sunat-cli keychain set CPE_CERT_PASSWORD
# prompts without echo

Multi-Emisor Profiles

Manage several RUC from one machine. Set a profile per emisor, switch with one command.

$ sunat-cli cpe profile use acme

Schema Introspection

Agents self-serve field definitions at runtime. 25+ schemas exposed.

$ sunat-cli schema cpe-factura
# Returns JSON schema of all fields

Padrón RUC + Consulta CPE

REST OAuth2 client_credentials. Padrón sync incremental, lookup local sub-ms.

$ sunat-cli api consulta \
  --tipo 01 --serie F001 --numero 123

Tipo de Cambio SBS

Scrape diario, cache local, fallback a fecha hábil previa.

$ sunat-cli tipo-cambio --fecha hoy
# {compra: 3.752, venta: 3.758}

Headless after one login

The F616 declaration form is a single-page app over a JSON API. Instead of driving the DOM on every run, the CLI opens a browser once to capture a session token (the IdCache), then closes it.

From there, f616 periodo and f616 oficios read the API directly, headless, for the lifetime of that token. No CAPTCHA to solve, no form fields to fight.

  1. 1
    Capture
    Open the browser once, log in, grab the session token, close it.
  2. 2
    Read headless
    Query the declaration API behind the form with the cached token, no browser running.
  3. 3
    Refresh on expiry
    When the token ages out, capture again. Everything in between stays headless.
61%

SUNAT mapped & agent-ready

Per-domain breakdown of how much of each SUNAT surface is wrapped, validated against the beta endpoint, and exposed as an agent-callable command. Green = shipped & verified. Yellow = partial. Orange/Red = shaped or needs production credentials.

REST APIs (Consulta CPE, Padrón, Tipo Cambio)
shipped
90%
RHE + F616 (personas naturales)
shipped
95%
CPE Factura / Boleta / NC / ND
shipped
85%
Resumen Diario + Comunicación de Baja
shipped
80%
SIRE (RVIE Ventas + RCE Compras)
shipped, partial
70%
GRE Remitente + Transportista
modal 02 only
50%
CPE void T3 (intent-token)
shaped
30%
Drivers (mock, sunat-direct, facturador, PSE/OSE)
2 of 5
40%
Producción end-to-end (live)
untested
10%

What's shipping next

Agent DX first

Following Justin Poehnelt's "Rewrite Your CLI for AI Agents" principles and the agentskills.io specification. The agent is not a trusted operator.

--json payloads over flags
--dry-run for all mutations
--output json by default
Schema introspection at runtime
Input hardening against hallucinations
SKILL.md per agentskills.io spec