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:
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:
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-linecargo testfailure log inxgbtxy/ap-harness-litev1.1.0, shrinking32,258 Bdown to1,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 searchorap sieve peek --lineson 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 recallreplaces monolithic always-on rule files with sub-millisecond FTS5/BM25 retrieval (0.33msover 10,000 rules inv2.94.0), injecting only the 1–3 rules matching the current file path or command.ap splice --hashlinereads enclosing Tree-sitter AST symbols tagged with short content hashes and applies--stdin --test --rollback-on-test-failatomically. Across our empirical Windows 11 traces (101,108calls) and 80 merged upstream OSS PRs, moving these checks into the binary substrate delivered1.52x–2.36xend-to-end speedups,36.7%–83.3%token-waste reduction, and62.5% -> 100.0%mutation-kill improvement.
3. Honest Trade-Offs and Negative Controls
No single design wins everywhere, and both codebases document clear boundaries:
ap publish explicit failure boundaries and negative controls:
- 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 withGPT-6 Sol(34.9%vs.29.2%),Claude Sonnet 5.5(41.6%vs.34.9%), andDeepSeek V4.1 Flash(28.9%vs.23.8%). Deterministic guardrails inaphelp bridge that reliability gap when running smaller or cheaper models. - 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. - When
apis overhead (built-in negative controls):- Tiny outputs (
<1.2 KBstdout): Wrapping a 70-bytegit status -soutput adds wrapper metadata (+48 Binap bench's built-in negative control). Rungit status -sdirectly or passap exec --raw. - Small files (
<80lines): Just read the file directly instead of invoking AST symbol slicing. - MCP-only clients: Only load
ap mcpwhen the host truly has no shell; otherwise direct CLI calls save every schema token.
- Tiny outputs (
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.
# 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
- Core Pure-Rust Binary (
v2.94.0, MIT; green CI run47465666416):github.com/xgbtxy/ap - MIT Starter Kit (
v1.1.0, includes offline token auditor & 24/24 CI tests):github.com/xgbtxy/ap-harness-lite/releases/tag/v1.1.0 - Interactive Benchmark Estimator & Sieve Playground (80 merged PRs · 3 Verified IETF errata):
xgbtxy.github.io - FreeHand Paper & Repository:
arxiv.org/abs/2612.02442·github.com/microsoft/FreeHand - Support Open-Source Maintenance (USDC / USDT · BNB Smart Chain BEP20):
/tip.html
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).