DEV Community

Cover image for Stop Burning API Tokens: Turn Browser & Local LLMs into a Safe Coding Agent with FS-XML
Доктор к
Доктор к

Posted on Edited on

Stop Burning API Tokens: Turn Browser & Local LLMs into a Safe Coding Agent with FS-XML

Most developers already use LLMs in a regular browser every day: Gemini (via Google AI Studio), Claude, ChatGPT, DeepSeek, or Qwen. They offer massive context windows that are often free or billed by message count rather than per-token input/output. The only catch? Browser chats can't touch your local disk.

On the flip side, if you switch to autonomous IDE agents (Cursor, Cline, Aider, etc.), three other headaches quickly pop up:

  1. Skyrocketing API Token Bills. The agent decides what to read, re-reads half the repo on every step, and enters retry loops when a patch fails. One heavy refactoring evening can burn a noticeable budget.
  2. Blind Edits. An agent can go off for 25 iterations, burn a million tokens, and head in the completely wrong direction—or fix a single button while silently rewriting a neighboring module.
  3. IDE Lock-in. If you’ve spent years mastering PyCharm, JetBrains tools, or Neovim, you shouldn't have to abandon your workflow for a VS Code fork just to get an AI assistant.

To solve this for my own workflow, I built FS-XML Interpreter—a lightweight, open-source desktop orchestrator that turns any browser chat (or local LLM) into a safe, semi-autonomous agent with a human in the loop, running smoothly right alongside your favorite IDE.

What FS-XML Is (and What It Isn't)

  • It is not an API proxy, an autonomous bash/shell agent, or a replacement for heavy agentic IDEs when you want full 40-step autonomy.
  • It is a local bridge between an LLM chat and your disk: you explicitly define Writable / Read-Only / Unmarked file permissions, generate a clean context dump, and apply XML patches from the model's response in 1 click through a sandbox with rollbacks and snapshots.
[ Your Project ] ──> (W / RO Permissions) ──> [ context_dump.txt ]
                                                       │
                                                       ▼
[ Browser / Local LLM ] ──> dump + task ──> [ Model XML Response ]
                                                       │
                                                       ▼
(Apply in 1 Click) ──────────────────────> [ Human Verification ]
      │
      ├──> Broke something? ──> [ File Rollback / Snapshot ]
      └──> Patch failed?    ──> [ 1-Click Copy Error + Actual File ]
Enter fullscreen mode Exit fullscreen mode

UI Screenshot


Why Custom FS-XML Tags Instead of unified diff or JSON?

Every engineer asks the same fair question: Why invent custom XML tags when unified diff and git apply already exist?

The answer comes down to a well-known LLM quirk: models are terrible at counting line numbers. (This is heavily documented by teams like Aider and Cline). When a model makes three edits in a single file via @@ -42,7 +42,9 @@, the second and third hunks suffer from line-number drift, and git apply simply fails.

Compare a broken classic diff:

--- a/src/auth/session.py
+++ b/src/auth/session.py
@@ -18,4 +18,4 @@ # <- model missed by 3 lines, patch rejected
 def is_expired(ts: int) -> bool:
-    return time.time() > ts
+    return time.time() >= ts
Enter fullscreen mode Exit fullscreen mode

With the content-addressed FS-XML format:

<fs_edit path="src/auth/session.py">
<fs_search>
def is_expired(ts: int) -> bool:
    return time.time() > ts
</fs_search>
<fs_replace>
def is_expired(ts: int) -> bool:
    return time.time() >= ts
</fs_replace>
</fs_edit>
Enter fullscreen mode Exit fullscreen mode
  • Why not JSON tool calls? Browser chats don't run your local tool-calling runtime—they output Markdown text. JSON inside Markdown breaks constantly due to \n escaping, nested quotes in code, and conversational fluff around the block. XML tags are human-readable in chat and trivial for a dedicated parser to extract.
  • Won't the XML parser break on HTML / Vue / JSX? FS-XML's own frontend is built in Vue 3. The fs_ prefix (<fs_create>, <fs_edit>, <fs_search>, <fs_replace>) is unique and doesn't collide with standard markup.

Money, Modularity, and Local Models

Even if you already pay $20/mo for Claude Pro or ChatGPT Plus, flat-rate web chats count messages rather than megabytes of re-read context. And if you run local models (via Ollama, vLLM, or LM Studio) or free tiers like Google AI Studio, context hygiene is critical: smaller models hallucinate drastically less when fed 3 relevant files instead of an entire repository.

By using the Black-Box Principle, once a module is finished and tested, you mark its implementation as Unmarked and keep only its interface/contract file as Read-Only. The model can build new features around it without wasting context or physically having permission to break working code.


Under the Hood: Architecture & 5 Engineering Pitfalls

The app is split into three clean layers:

  • core/ — Autonomous engine (CoreEngine parser, CommandRegistry, Sandbox, and handlers).
  • server/ — FastAPI + SQLite in WAL mode (projects, profiles, file permissions, execution history, and snapshots).
  • frontend/ + desktop_app.py — Vue 3 + TypeScript + TailwindCSS rendered in a native PyWebView window (plus a lightweight C# launcher FS-XML.exe for Windows).

Here are 5 real-world edge cases I had to solve in production:

1. Parser Collisions: When the Code Contains </fs_edit>

When I started using FS-XML to develop FS-XML itself, a Python file literally contained closing = "</fs_edit>". A naive regex parser happily terminated the command right in the middle of the file.
In core/engine.py, this is handled with three layers of protection: skipping narrative mentions without a path attribute, ignoring tags wrapped in string literal quotes ("..." or '...'), and a two-pass depth-aware scanner.

@staticmethod
def _is_quoted_literal_tag(raw_text: str, start: int, end: int) -> bool:
    if start > 0 and end < len(raw_text):
        prev_ch = raw_text[start - 1]
        next_ch = raw_text[end]
        if prev_ch in ('"', "'") and next_ch == prev_ch:
            return True
    return False
Enter fullscreen mode Exit fullscreen mode

2. Trailing Whitespace, Empty Search Blocks, and CRLF/LF Pain

  • Whitespace & \v / \f: If an exact match fails, a second pass strips trailing spaces per line—splitting strictly via split("\n") rather than splitlines() so vertical tabs inside string literals aren't broken.
  • Empty <fs_search>: In Python, "".replace("", new, 1) silently prepends code to the top of the file. Empty searches are explicitly rejected (full file overwrites use a dedicated marker).
  • Windows Line Endings: has_crlf = "\r\n" in original_content is captured before editing and preserved upon write to prevent \r\r\n corruption.

3. Intentional Threat Model (No Shell Access)

The lack of terminal execution is a deliberate security choice: the orchestrator physically cannot run rm -rf or exfiltrate .env variables via curl. Sandbox.resolve_safe_path blocks absolute paths and ../ traversal, while assert_write_permitted denies writes to READONLY or UNMARKED files.

4. Context Hygiene (.fsignore & Test Exclusion)

Supports a two-level ignore system (global + local .fsignore using .gitignore syntax), automatic binary exclusion, optional test-file stubbing (# [TEST FILE EXCLUDED - EXISTS ON DISK]), and an optional UNMARKED PROJECT STRUCTURE tree so the LLM knows paths without wasting tokens on contents.

5. Manual Edit Detection & 1-Click Error Recovery

  • Safe Rollbacks: Before rolling back a patch, the server checks if the file on disk matches new_snapshot in SQLite. If you edited the file manually in your IDE after applying the AI patch, rollback pauses and warns you instead of silently overwriting your code.
  • 1-Click Error Context: If a <fs_search> block misses, clicking the failed log copies both the failed patch attempt and the actual file from disk straight to your clipboard so the chat can immediately issue a corrected patch.

Check It Out

FS-XML Interpreter is completely free, open-source under Apache 2.0, covered by backend and frontend tests (pytest + vitest), and comes with a pre-compiled FS-XML.exe in the releases for Windows users who don't want to set up Python or Node.js.

(And if you prefer running strictly locally via API keys / Ollama without browser copy-pasting, check out my companion project Live-Context AI Chat which includes built-in FS-XML support).

How do you manage context and prevent your AI coding agents from going rogue? Let's discuss in the comments!

Top comments (0)