All posts

Can AI-Assisted Writing Work at 35,000 Feet? Designing Emit: A Git-Like, Air-Gapped Local Workbench for EmDash CMS

It is a midnight red-eye flight: roughly six hours from Tokyo Narita to Bangkok Suvarnabhumi. The dinner trays have long been cleared, and the cabin lights are dimmed to a sleepy twilight.

I would love to picture myself in a spacious, lie-flat Business Class suite, casually sipping a glass of welcome champagne while effortlessly tapping away on a pristine keyboard.

The reality, of course, is starkly different. I am wedged deep in Economy Class, my knees firmly pinned against the back of the seat in front of me—a seat whose occupant had zero hesitation about slamming their backrest into full recline the millisecond the seatbelt sign clicked off. My battered laptop teeters unsteadily on a cramped, vibrating tray table.

At 35,000 feet, without in-flight Wi-Fi and completely severed from the internet, all I wanted was to open my editor, converse with my AI writing assistants (Cursor, Claude Code), pull contextual references from thirteen years of past blog posts, and write.

To satisfy this stubborn urge, I stepped away from the slick web dashboard of EmDash—a modern, high-performance headless CMS built on Astro and running on Cloudflare Workers, D1, and R2—and decided to build `emdash-emit`: a dedicated, CLI-based local workbench that hands full writing and syncing powers directly to the developer’s editor and AI agents.

...That said, let me be candid for a moment. While I wouldn't hesitate for a second to drop serious cash on an RTX 5090 if it were a justifiable business expense, I simply cannot justify dropping $7,000 on a maxed-out, 128GB Unified Memory MacBook monster just to spin up local LLMs at 35,000 feet. The cost-to-performance ratio just doesn't make sense for me.

Yet given the blistering pace of technology, we won’t have to wait long before genuinely capable AI models run smoothly on humble, everyday laptops without requiring exorbitant silicon. Rather than waiting for that hardware to arrive, I wanted to build the vessel—the tooling and workflow—beforehand.

What started as an eccentric desire for offline writing ultimately crystallized into an air-gapped, two-tier architecture.

And along the way, tackling the gritty realities of production infrastructure led to two major breakthroughs: completely defending against Cloudflare D1 billing blowups and reducing AI agent cognitive load to near zero.

Best of all, the machine currently benchmarked and happily chewing through thousands of assets in seconds isn’t an exotic workstation. It is a tiny Raspberry Pi 5 (16GB) running headless, quietly tucked away next to my home network patch panel beneath the main electrical breaker.

Here is the design log of how bringing Git’s battle-tested mental model into CMS architecture built a clear runway for human and AI collaboration.


Act 1: The Dreaded "N+1 Problem" and D1 Meter Anxiety

Act 1: The Dreaded "N+1 Problem" and D1 Meter Anxiety

When building a local-first CMS sync tool, the most intuitive first instinct is obvious: “Let’s just download every article, category, and tag down to a local SQLite database.” Having the entire universe of your blog offline sounds like paradise.

However, I imposed a strict architectural constraint from day one: I would interact purely with EmDash’s vanilla REST API, without building bespoke, cheating backend endpoints.

That constraint immediately collided with reality.

Under the hood, EmDash's default endpoints treat taxonomy relationships (categories and tags) separately from the core article payloads. Attempting a naive full-sync across a 13-year-old archive meant:

  1. Querying the paginated article list.
  2. Firing an individual sub-request for every single article ID to resolve its associated terms.

A textbook N+1 request nightmare.

When you run on Cloudflare D1, this isn't just an efficiency problem; it is a financial scare. D1 bills based on rows read. If every developer or sync invocation hammered the server with thousands of N+1 read cascades, you would vaporize your free tier in an afternoon and risk waking up to an unpleasant cloud bill.

"A naive full-sync will bankrupt the project. The infrastructure cannot survive it."

Our dream of total offline harmony hit a brick wall before writing a single post.


Act 2: When Intelligent AI Stumbles Over Incomplete Worlds

Act 2: When Intelligent AI Stumbles Over Incomplete Worlds

To dodge the N+1 trap, my second attempt was to implement a lightweight, paginated search with a strict hit-limit. The client would only fetch what was requested, querying the remote API on demand.

That introduced an entirely different, subtle failure mode with AI agents.

Modern coding agents like Cursor and Claude Code are remarkably capable. They rarely hallucinate out of thin air; they behave more like sharp, hyper-competent human junior engineers. But like any sharp assistant, they are vulnerable when handed incomplete information.

When search results were cut off by a hit-limit, the AI would inspect the truncated list, observe that an article or image wasn't present, and logically conclude: “It is not here. Therefore, it does not exist in this blog.” Being helpful and proactive, it would proceed to create a duplicate asset from scratch. The AI wasn't "going crazy"—it was making a rational decision based on a clipped horizon.

To patch this, I attempted to introduce epistemology into the protocol. I introduced flags like walkComplete: false to distinguish “not found within the truncated window” from “definitely does not exist on the remote server.”

The result? A disaster for cognitive load.

When faced with ambiguous, defensive warnings, the AI would either freeze up in indecision—wondering whether it should trust what it had or ask for clarification—or enter circular chains of cautious reasoning. Human users fared no better; being told “Showing partial results” just provoked the natural reaction: “Then show me everything!”

Defensive caveats and truncated views were a terrible developer experience for both carbon and silicon.

What an intelligent agent needed wasn't an essay on epistemological uncertainty. It needed an unambiguous runway with zero blind spots.


Act 3: "AI Already Understands Git 100%"

Act 3: "AI Already Understands Git 100%"

That led to an epiphany:

"What is the single architecture that every modern LLM understands with absolute, mathematically verified clarity?"

The answer was unequivocally Git.

Global LLMs have parsed countless petabytes of Git repositories, commit trees, working directories, staging areas, 3-way merges, and conflict markers. An AI agent doesn't need to be persuaded or prompted on how Git behaves—it understands Git intuitively down to its neural weights.

If we modeled our CMS synchronization tool precisely after Git’s mental model, the cognitive load on the AI would drop to near zero.

Guardrails in emit shouldn't be straightjackets designed to punish mistakes; they should function like runway guide lights, allowing the agent to accelerate at full throttle with complete confidence.

We scrapped the paginated search and pivoted to an Air-Gapped Two-Tier Architecture:

flowchart TD
    subgraph Cloud ["Cloud (Cloudflare / EmDash)"]
        RemoteDB[("D1 Database<br>(Thousands of Posts)")]
        R2Storage[("R2 Storage<br>(Thousands of Images)")]
    end

    subgraph Layer1 ["The Archive / Snapshot Layer (.git index & objects)"]
        LocalCache[("Local SQLite (.emit/cache.db)<br>Complete Catalog Index (0-HTTP)")]
        MediaCache["Immutable Media Cache (media/_cache/)<br>Pre-fetched Binaries"]
    end

    subgraph Layer2 ["The Staging Desk (Working Tree)"]
        ActiveMarkdown["Active Markdown (posts/)<br>Sliding Window (30 recent + drafts)"]
        ActiveMedia["Active Working Media (media/)<br>Materialized via Hardlink"]
        AIAgent["AI Agent / Editor<br>(Cursor, Claude Code, VS Code)"]
    end

    RemoteDB -.->|"Differential Snapshot (Seconds)"| LocalCache
    R2Storage -.->|"Pre-cache Assets"| MediaCache

    LocalCache -->|"0-HTTP Instant Search"| AIAgent
    MediaCache ===|"linkSync (Zero Disk Duplicate, 0.001s)"| ActiveMedia
    AIAgent <-->|"Focus Writing & Local Preview"| ActiveMarkdown

1. The Archive (Snapshot Layer) $\approx$ .git/ Objects & Index

Stored under .emit/cache.db (powered by Node’s built-in node:sqlite). It houses an indexed catalog of every single post and media asset across the site’s entire history, while media/_cache/ holds immutable downloaded image binaries.

Because metadata synchronization strips out heavy rich text bodies during index scans, pulling the diff takes mere seconds and generates virtually zero D1 row reads. Searches against this local archive are 100% offline, 0-HTTP, and exhaustive. The AI never wonders if an article exists—the whole catalog is right there.

2. The Staging Desk (Working Tree) $\approx$ Working Directory

This is where markdown files and images physically reside on your filesystem.

Rather than dumping 5,000 files into your workspace—which would flood the AI's context window, burn thousands of input tokens, and risk accidental cross-file contamination—the staging desk operates as a sliding window. By default, it only unfolds the latest 30 posts plus any active drafts.


Act 4: The Raspberry Pi 5 Benchmark & The "0.001s" Hardlink

Act 4: The Raspberry Pi 5 Benchmark & The "0.001s" Hardlink

With the architecture split into "The Archive" and "The Staging Desk", the practical performance numbers surprised even me.

1. Zero Duplicate Disk Space via Hardlinks (linkSync)

When an AI agent or a developer pulls an old post into the active workspace via emit pull <ID> --from-snapshot, how do we handle referenced media without duplicating hundreds of megabytes?

Emit links the file from media/_cache/ into media/ using OS-level hardlinks (`fs.linkSync`).

The target image materializes in the active working directory in 0.001 seconds, consuming 0 bytes of additional disk space. Image paths resolve seamlessly for local preview inside VS Code.

(And if running on Windows or across disparate filesystem mounts where hardlinks encounter constraints, Emit's multi-tiered fallback automatically switches to copyFileSync seamlessly).

2. Auditing 4,089 Media Items in 7.6 Seconds on a Raspberry Pi

Here is an authentic verification log from the production workspace running a diff against 764 articles and 4,089 images (approx. 1.0 GB):

📸 Snapshot captured (posts) (7610ms):
   • Articles: 764 cached (0 pruned, 0 single-GET(s))
   • Media:    4089 cached (0 pruned)
   • Terms:    45 categories, 58 tags (article terms: 0 fetched, 764 reused)
   • Media cache: 0 downloaded (0.00 MiB), 4079 skipped/existing.

While the very first snapshot requires walking through articles and resolving taxonomy relationships via the remote API (incurring an initial N+1 fetch), subsequent differential synchronizations are lightning-fast. Verifying 4,089 media records and 764 articles takes just 7.6 seconds, with 0 redundant API calls.

To avoid any misunderstanding: I am not claiming a Raspberry Pi 5 can replace a $7,000 MacBook Pro, nor am I running heavy local LLMs directly on the Pi.

The Raspberry Pi was enlisted here specifically as an unforgiving performance benchmark for the CMS data layer alone—measuring raw SQLite indexing, filesystem I/O, hardlinking, and differential syncing excluding AI model inference. While heavy local neural inference will naturally benefit from upcoming consumer-grade hardware and model quantization, the underlying CMS data plumbing shouldn't require brute-force luxury hardware. Proving that an inexpensive, credit-card-sized SBC can handle thousands of production assets effortlessly demonstrates just how lightweight and refined the local-first architecture truly is.

(And because it runs completely headless with no monitor or keyboard attached, it sits happily tucked away in the tight crawlspace beneath my home network breaker. Even with recent RAM pricing spikes making a 16GB Pi 5 cost around $100–$120, it remains infinitely more humble than a monster laptop). Thanks to clean, local-first differential indexing rather than wasteful brute-force cloud calls, even modest ARM hardware glides through the verification without breaking a sweat.

3. Git-Style 3-Way Merge for Safe Collaboration

When human writers make a quick copy edit in the web UI while an AI agent simultaneously refines text locally, naive sync tools will clobber one or the other.

Emit performs standard 3-Way Merges against the base revision. If an unresolvable collision occurs, it injects standard Git conflict markers (<<<<<<< LOCAL) into the Markdown file and halts push operations with non-zero exit codes. The AI agent immediately recognizes the markers, resolves the conflicting sentences, and re-pushes. No custom protocols, no confusion.


Act 5: Architecture Born from Practical Constraints

Act 5: Architecture Born from Practical Constraints

Reflecting on the journey:

  • EmDash's minimalist REST API forced us to respect N+1 costs.
  • Cloudflare D1's row-read billing forced us to eliminate repeated queries.
  • Intelligent AI agents demanded crystal-clear context rather than vague warnings.
  • The reality of hardware costs stopped us from relying on raw local brute force.

Navigating these real-world constraints produced an architecture that feels exceptionally right for this era: a local-first, air-gapped system where AI agents and humans operate seamlessly over the familiar mechanics of Git, while keeping cloud infrastructure costs virtually zero.

As local LLM execution continues to mature, we believe air-gapped, Git-aligned workspaces will become the standard paradigm for AI-assisted creative work.

If you are using Cursor, Claude Code, or VS Code and want a distraction-free, terminal-driven writing desk for EmDash, feel free to give Emit a spin:

Discussion

No comments yet