Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

legends-cloudflare

release checks python dns license

Zero-dependency Cloudflare DNS, cutover audit, and hash-locked record change CLI (legends-cloudflare) for coding agents: audit zones and assigned nameservers, snapshot complete paginated DNS inventories, preview single-record changes with automatic orange-cloud proxy and TTL preservation, enforce SHA-256 plan locks with immediate API readback, and attach source-cited DNS migration runbooks to legends-empire.

Agent Handoff

Install or update legends-cloudflare via cto-legends (https://github.com/avalonreset/cto-legends): run `cto-legends install legends-cloudflare --apply`, then `cto-legends handoff legends-cloudflare` and follow the returned JSON recipe to verify `legends-cloudflare doctor`.

Three Pillars: Zone audit & drift diffing, Cutover & proxy safety gates, SHA-256 locks & Empire vault

Why legends-cloudflare exists

Letting an AI agent edit live Cloudflare DNS records with improvised curl calls or ad-hoc dashboard clicks is one of the fastest ways to take down production traffic or break domain email delivery:

  1. Silent orange-cloud proxy and custom TTL resets: In Cloudflare's API, sending a naive replacement payload without carrying forward existing metadata routinely turns off orange-cloud edge proxying, exposes origin server IPs, or resets custom TTL and MX priority values.
  2. Accidental destruction of sibling TXT, MX, and round-robin records: Production domains often hold multiple SPF/DKIM/ACME TXT verification entries, multiple MX mail servers, or round-robin A records on the same hostname. A script that filters by hostname and loops over matches can wipe out sibling records in seconds.
  3. Blind writes over concurrent zone drift: Applying a DNS change from stale chat history without re-checking the live zone right before writing can overwrite an ACME certificate challenge or a teammate's hotfix, while assuming an HTTP response means worldwide cutover success hides broken authoritative state.

legends-cloudflare wraps the official Cloudflare DNS API in a preview-first, hash-locked change engine that pairs naturally with legends-hetzner, legends-coolify, and legends-empire. Every single-record change (A, AAAA, CNAME, TXT, MX, NS) begins as a zero-write preview that snapshots the live before-state, preserves unspecified proxy and TTL fields, and outputs a deterministic sha256 plan hash. Nothing touches Cloudflare until you explicitly pass --apply --confirm-zone <zone> --confirm-plan <sha256>.

Ask in plain english

Once cto-legends is installed, you ask your coding agent in plain english. It snapshots the zone inventory, builds a zero-write change plan with proxy and TTL preservation, waits for your confirmation, and verifies the live readback:

Say the job in plain words

Architecture: hash-locked DNS plans and cutover safety gates

How hash-locked DNS plans and cutover safety gates work

1. Zone audit, nameserver inspection, and fail-closed pagination

Before planning any domain migration or server cutover, legends-cloudflare gives your agent a bounded, read-only inspection surface:

  • Fixed-origin HTTPS transport with redirect refusal (legends_cloudflare/api.py): Every request is locked to https://api.cloudflare.com/client/v4/zones... with ProxyHandler({}) and NoRedirect enforced so bearer tokens are never forwarded across HTTP redirects or ambient proxies. Raw provider error bodies are sanitized so secrets never leak into logs.
  • Complete paginated inventory with duplicate & truncation guards: zones and records iterate across all API pages (per_page=50) and fail closed if total_pages metadata is truncated, if pagination ends early, or if a concurrent zone edit causes duplicate record IDs across pages.

2. Cutover safety gates, proxy preservation, and SHA-256 plan locks

Every subcommand in legends-cloudflare separates read-only discovery and zero-write plan generation from confirmed single-record writes:

Surface legends-cloudflare Subcommands What It Does
Runtime & Resource Checks doctor, doctor --live, resources Offline Python 3.11+ readiness check (doctor), live zone-list token verification (doctor --live), and packaged recipe + knowledge-pack path resolution (resources).
Zone & Nameserver Audit zones, nameservers --zone <zone> Lists accessible zones (id, name, status, name_servers) and inspects assigned Cloudflare nameservers for registrar cutover planning.
Paginated DNS Inventory records --zone <zone> [--name <name>] [--type <type>] Returns complete, normalized DNS record snapshots (id, type, name, content, ttl, proxied, priority, comment, tags, settings, modified_on).
Preview-First Record Upsert upsert --zone <zone> --name <name> --type <type> --content <val> Validates IPv4/IPv6 and ASCII/punycode hostnames offline, preserves existing proxied, ttl, and priority settings when omitted, and returns a zero-write JSON plan (writes_sent: 0) with a sha256 digest.
Hash-Confirmed Cutover Write upsert ... --apply --confirm-zone <zone> --confirm-plan <sha256> Re-fetches the live record before writing to refuse mid-cutover drift, executes a targeted PATCH or POST, and performs an immediate GET readback to verify every updated and preserved attribute.
Exact-ID Guarded Delete delete --zone <zone> --name <name> --type <type> --record-id <id> Refuses multi-record set deletion by requiring the exact 32-character hexadecimal --record-id for both preview and --apply, then confirms via readback that the target ID is absent while sibling records remain intact.

3. Pre-change rollback snapshots, authoritative readback, and legends-empire vault pack

  • Pre-change rollback snapshots (plan.before): Every upsert and delete plan embeds the full before snapshot (id, type, name, content, ttl, proxied, priority, comment, tags, settings, modified_on) alongside the proposed payload and sha256 hash so operators have the exact pre-change state required to roll back a cutover.
  • Attachable legends-empire knowledge pack (knowledge/cloudflare/pack.json): Ships with a legends.knowledge-pack/v1 operational library and wiki/index.md covering least-privilege token scoping, full-zone DNS migrations, DNSSEC DS coordination, authoritative vs recursive lookup checks, and private change-receipt templates (templates/change-receipt.md).

Raw API calls vs legends-cloudflare

Comparison: Raw API calls & dashboard edits vs Hash-locked DNS & edge engine // legends-cloudflare

Quick start

# 1. Verify offline runtime health and packaged knowledge resources
legends-cloudflare doctor
legends-cloudflare resources

# 2. Check live token reachability, accessible zones, and assigned nameservers
legends-cloudflare doctor --live
legends-cloudflare zones
legends-cloudflare nameservers --zone example.com
legends-cloudflare records --zone example.com

# 3. Preview a single-record DNS update (zero writes sent; preserves proxy & TTL)
legends-cloudflare upsert --zone example.com --name www --type A --content 192.0.2.10

# 4. Apply the reviewed plan using its exact zone name and SHA-256 preview hash
legends-cloudflare upsert --zone example.com --name www --type A --content 192.0.2.10 \
  --apply --confirm-zone example.com --confirm-plan SHA256_FROM_PREVIEW

# 5. Preview and apply an exact-ID record deletion (protects sibling TXT/MX records)
legends-cloudflare delete --zone example.com --name old --type A --record-id EXACT_32_CHAR_RECORD_ID
legends-cloudflare delete --zone example.com --name old --type A --record-id EXACT_32_CHAR_RECORD_ID \
  --apply --confirm-zone example.com --confirm-plan SHA256_FROM_PREVIEW

Reference

Knowledge vault, DNS migration runbooks, and legends-empire integration

Start at wiki/index.md or attach the versioned knowledge pack at knowledge/cloudflare/pack.json (legends.knowledge-pack/v1). Attach into a legends-empire vault or read it directly as plain Markdown.

Agent setup (via cto-legends) and standalone installation

Agent setup (via cto-legends)

The module recipe is docs/AGENT-RECIPE.md. The vendored skills/cto-legends/SKILL.md is an unchanged copy of the central cto-legends router. Do not register a separate Cloudflare skill.

Run cto-legends handoff legends-cloudflare to inspect the installed recipe and readiness checks, or run cto-legends run legends-cloudflare -- doctor. For a standalone checkout:

python -m pip install .
legends-cloudflare doctor
legends-cloudflare resources

Load CLOUDFLARE_API_TOKEN from your secret manager into the process environment (Zone:Read and DNS:Read for inspection; DNS:Edit only for approved writes on selected zones). The CLI never auto-loads .env files or accepts tokens as command-line arguments.

Repository layout, verification, and scope boundaries
Operator / Agent
  -> legends-cloudflare CLI (doctor, resources, zones, nameservers, records, upsert, delete)
  -> Plan builder (before-state snapshot + proposed payload + SHA-256 digest, writes_sent=0)
  -> Explicit confirmation (--apply --confirm-zone --confirm-plan) + pre-write drift re-check
  -> Cloudflare DNS API PATCH/POST/DELETE + immediate GET readback verification
python -m unittest discover -s tests -v
python scripts/check_release.py

Supported record writes: A, AAAA, CNAME, TXT, MX, and NS. This module does not transfer registrar ownership, change registrar nameservers, deploy Cloudflare Workers, manage tunnels, or run unreviewed bulk DNS imports. Exit codes: 0 completed inspection, preview, or verified change; 1 operational failure; 2 invalid CLI syntax. A failed write or readback can mean remote state changed: inspect live zone state before retrying, as no automatic retry or blind rollback occurs.

Contributing, security, and license

This is an independent community project built on the official Cloudflare API and is not affiliated with or endorsed by Cloudflare. See CONTRIBUTING.md, SUPPORT.md, PRIVACY.md, CODE_OF_CONDUCT.md, and SECURITY.md.

MIT License. See LICENSE, NOTICE, and THIRD_PARTY_NOTICES.md.

Start here

Paste the agent handoff block at the top of this page into your coding agent, let it wire the cto-legends router skill, and speak your task in plain English.

Running a company and not a terminal? Founders and operators who want this way of working applied directly to their own business stack have one route: message Avalon Reset at cto-legends.com/dm or start with a 48-hour diagnostic at cto-legends.com/home#home-offer. The desk is async, so the conversation starts the moment you write and nobody forces you onto a sales call.

Want this way of working applied to your own stack? Message Avalon Reset at cto-legends.com/dm

GitHub Star List: The complete cto-legends collection on one page. Bookmark or star the router and every module from a single GitHub list.

Specification & benchmarks on cto-legends.com:

Releases

Packages

Contributors

Languages