2026-12-05 ~7 min read Rust · Windows · Agent Harness RSS

What Microsoft FreeHand (arXiv:2612.02442) Got Right About Minimal Harnesses—And Why Native Windows Still Needs Deterministic Primitives

Comparing microsoft/FreeHand's single-bash, zero-MCP-schema-tax findings with xgbtxy/ap v2.94.0's pure-Rust Windows-native substrate (Win32 Job Objects, SQLite FTS5 sieve/recall, and Hashline AST edits)—including honest trade-offs and negative controls.

Canonical English edition · Toggle 中文 above for a concise Chinese executive summary and localized navigation. Every benchmark, CI run (47465666416), and source path cited below is publicly verifiable.

Reading Microsoft Research's FreeHand (arXiv:2612.02442) is refreshing if you spend real hours wiring coding agents to actual repositories.

Instead of piling on 20+ specialized tools, prescriptive planner loops, and forced auto-compaction thresholds, FreeHand's runtime prompt (src/freehand/prompt.md) fits in roughly 200 words (~0.35K tokens) and hands a frontier model one bash tool, an editable {transcript_path}, and a turn-by-turn cost/context meter. Across 11 settings spanning five benchmarks (Terminal-Bench 4, Terminal-Bench Science, Agents' Last Exam, OSWorld 2.1, and AutomationBench) with GPT-6-astra, Claude Opus 5.5, and Gemini 4 Carbon, that minimal design beat first-party harnesses by 5.1 points on average at 49% lower cost.

I like building from a simple premise: technology has fewer real walls than ever today—papers, compilers, and specs are right in front of us, so the fun part is testing good ideas locally and shipping clean primitives where gaps remain. Looking closely at FreeHand's codebase and our own pure-Rust agent toolkit xgbtxy/ap (v2.94.0, MIT; CI & Benchmarks green on main run 47465666416), two ideas stand out immediately: FreeHand and ap converge on the exact same diagnosis of context bloat, while solving opposite halves of the stack.

1. Where FreeHand and ap Agree Completely

CLI-First Beats Eager MCP Schema Tax

In src/freehand/mcp.py, FreeHand makes a deliberate architectural choice:

"Freehand gives the model one tool, bash, and that does not change here. A session whose person has set up MCP servers is told their names and these two commands in its first message; the model lists a server's tools when it wants them and calls one like any other command. No tool schema is in the context until the model asks for it."

That mirrors what we measured auditing 101,108 coding-agent tool-call traces while building xgbtxy/ap. Exposing dozens of JSON tool schemas up front taxes every single turn—even when the agent only needs git, rg, or a targeted test run. In ap, the CLI is the primary interface (ap orient, ap search, ap read --symbol, ap sieve, ap splice, ap recall, ap guard, ap baton), while ap mcp remains purely optional for MCP-only hosts that lack a shell.

Keep Raw Noise Out of the Context Window

Both projects start from the same observation: dumping uncurated terminal output and bloated instruction files into the prompt ruins frontier-model reasoning long before you hit the hard context limit.

2. Where the Two Designs Diverge: Outer Harness vs. Inner Substrate

FreeHand simplifies the outer loop (Python standard-library runtime, minimal prompt, single bash tool). ap hardens the inner tool substrate inside a single statically linked pure-Rust binary (7 crates, 6 compiled Tree-sitter grammars, embedded SQLite FTS5) so the model does not waste turns fighting raw files, truncated logs, or OS process quirks.

Layer microsoft/FreeHand (Outer Harness) xgbtxy/ap v2.94.0 (Inner Substrate)
Tool Interface Single bash tool + lazy on-demand MCP CLI Direct CLI-first (ap orient/sieve/splice/recall); optional ap mcp
Windows Process Control POSIX os.killpg(SIGKILL) + fcntl.flock (Native Windows: coming soon) Native Windows binary + ap-winjob Win32 Job Object tree kill
Large Log Output truncate_middle at 40,000 chars; manual transcript pruning Pre-context SQLite FTS5 digest (-95.9% on 597-line cargo test) + lossless search/peek
Rules & Edits ~200-word runtime prompt; Unix sed/python/grep inside bash 0.33ms BM25 ap recall (10k rules) + ap splice --hashline atomic AST rollback
Target Sweet Spot Frontier models on macOS, Linux, and WSL2 Native Windows + Unix; tightens smaller/cheaper model reliability too

A. Native Windows (ap-winjob) vs. POSIX-Only killpg ("Native Windows: coming soon")

FreeHand's README.md currently notes:

"Supported platforms: macOS and Linux. The CLI and web interface also run in Linux under WSL2. Native Windows: coming soon."

Inspecting src/freehand/runtime/agent.py shows why: tool_bash executes bash -lc, terminates timed-out or interrupted commands via POSIX os.killpg(p.pid, signal.SIGKILL), and guards session state with fcntl.flock (falling back to a no-op when fcntl is None).

On native Windows, killing a parent shell without Win32 process-tree containment frequently leaves orphaned compilers, test runners, or file-locking daemons alive after a timeout. xgbtxy/ap ships native Windows binaries out of the box and pairs ap exec with ap-winjob, binding spawned command trees into Win32 Job Objects so timeouts tear down the entire child tree deterministically with zero orphaned processes.

B. Out-of-Context FTS5 Sieving (ap sieve) vs. Middle-Truncation at 40K Chars

When a bash command produces huge output in FreeHand (src/freehand/runtime/agent.py), truncate_middle caps the returned transcript text at tool_output_max_chars (default 40,000 characters) while saving the full file on disk—leaving the model to manually prune transcript.json later if context swells.

ap sieve filters before output ever enters the context window:

  • ap sieve run -- <cmd> compresses noisy test/build logs into a deterministic signal digest (on the 597-line cargo test failure log in xgbtxy/ap-harness-lite v1.1.0, shrinking 32,258 B down to 1,307 B—a 95.9% cut while preserving buried assertion frames).
  • Every byte of the verbatim output stays indexed in an embedded SQLite FTS5 store, so the model can query ap sieve search or ap sieve peek --lines on demand instead of guessing what was clipped out of the middle.

C. Budgeted Micro-Rules (ap recall) and Content-Hashed AST Edits (ap splice --hashline)

FreeHand leaves file editing and rule recall to whatever Unix utilities (sed, python, grep) the model scripts inside bash. That works well with frontier models, yet brittle line-number edits and giant AGENTS.md files still cause avoidable retries.

In ap:

  • ap recall replaces monolithic always-on rule files with sub-millisecond FTS5/BM25 retrieval (0.33ms over 10,000 rules in v2.94.0), injecting only the 1–3 rules matching the current file path or command.
  • ap splice --hashline reads enclosing Tree-sitter AST symbols tagged with short content hashes and applies --stdin --test --rollback-on-test-fail atomically. Across our empirical Windows 11 traces (101,108 calls) and 80 merged upstream OSS PRs, moving these checks into the binary substrate delivered 1.52x–2.36x end-to-end speedups, 36.7%–83.3% token-waste reduction, and 62.5% -> 100.0% mutation-kill improvement.

3. Honest Trade-Offs and Negative Controls

No single design wins everywhere, and both codebases document clear boundaries:

Both FreeHand and ap publish explicit failure boundaries and negative controls:
  1. Model-tier sensitivity (FreeHand's own negative result): FreeHand explicitly warns that its minimal harness is built for frontier models. On Terminal-Bench 4, the trend reversed with smaller models—first-party harnesses beat FreeHand with GPT-6 Sol (34.9% vs. 29.2%), Claude Sonnet 5.5 (41.6% vs. 34.9%), and DeepSeek V4.1 Flash (28.9% vs. 23.8%). Deterministic guardrails in ap help bridge that reliability gap when running smaller or cheaper models.
  2. Trust boundary: FreeHand intentionally ships no sandbox and no approval prompt (docs/security.md), running commands directly with your permissions unless you wrap it in a container or VM.
  3. When ap is overhead (built-in negative controls):
    • Tiny outputs (<1.2 KB stdout): Wrapping a 70-byte git status -s output adds wrapper metadata (+48 B in ap bench's built-in negative control). Run git status -s directly or pass ap exec --raw.
    • Small files (<80 lines): Just read the file directly instead of invoking AST symbol slicing.
    • MCP-only clients: Only load ap mcp when the host truly has no shell; otherwise direct CLI calls save every schema token.

4. They Compose Better Together Than Alone

If you are on macOS, Linux, or WSL2 and want to test FreeHand's Bitter-Lesson loop, you don't have to choose between the two philosophies. Keep FreeHand as the minimal single-bash outer harness, and drop the static ap binary inside its PATH so the model's bash calls get FTS5 log sieving, content-hashed AST edits, and sub-millisecond rule recall for free. And if you work natively on Windows today without waiting for WSL2, ap + ap-harness-lite (v1.1.0) bring those same deterministic primitives straight to Win32 via ap-winjob.

Using ap Inside a Minimal Single-Shell Loop (Native Windows or POSIX)
# 1. Run noisy test suite inside Win32 Job Object / FTS5 sieve
ap sieve run -- cargo test

# 2. Inspect only the buried failure frames without 40K middle-truncation
ap sieve search "panicked at"

# 3. Apply a content-hashed symbol edit with atomic rollback on test failure
ap splice view src/lib.rs --hashline
ap splice apply --hashline --stdin --test --rollback-on-test-fail

# 4. Retrieve only the 1-3 rules matching the touched path (0.33ms BM25)
ap recall match --query "src/lib.rs"

Explore the Artifacts & Benchmarks

How are you splitting work between your agent harness and your local CLI tools right now? Feel free to open a GitHub Issue or compare notes on X (@yan179539549809).