Canadian AI — Research Framework
A grammar-first framework for reliable, structure-aware program transformation in AI coding agents. Progressive capability loading, validation-first architecture, and seamless integration with existing tooling.
Design Principles
Grammar-First
AST / LSP — not regex
Type-Safe
Typed inputs & outputs
Reversible
Git checkpoints + patches
Sandboxed
E2B / Modal isolation
Minimal Surface
Six operations, no more
The Token Math
Traditional harnesses generate code, then spend a second full inference pass refactoring what they just wrote. GIRL plans the change once — loading capabilities on demand and working on the syntax tree — so one pass does the work of two.
Pipeline comparison — same task
two passes one pass0%
Fewer tokens / task
8.2k → 2.1k end-to-end
0×
Inference pass
down from 2× speculative
Tokens per refactor task
Illustrative per-task totals including generation. GIRL returns compact symbol handles instead of raw file blobs and loads operations only when needed.
0 tok
Capability context
vs 4,500 loaded upfront
The Real Cost of AI Refactoring
Search interest in refactoring has grown over 300% since 2019 — driven largely by teams cleaning up AI-generated code. The current loop: generate with an LLM, then pay a second full inference pass to refactor what the first pass produced. GIRL is designed to collapse that loop into one well-planned, structure-aware transformation.
“Refactoring queries on Google Trends have climbed steadily since 2021, peaking in 2025–2026 as AI code-generation adoption hit mainstream scale.”
Google Trends — 5 year view, 2021 – 2026
2×
Double inference spend
AI generates code, then pays inference again to refactor what it wrote — two full LLM passes for one net change.
96%
Token reduction possible
GIRL on-demand loading cuts baseline capability context from 4,500 tokens to ~200 — before the transformation even starts.
1 pass
Our goal
Structure-aware planning eliminates redundant generation. One well-planned pass replaces two expensive speculative ones.
Core Control Flow
Every transformation passes through a five-phase pipeline. Each phase produces immutable artifact handles — nothing is discarded, everything is revertible.
Pipeline — Click a node to expand
Minimal Operation Surface
Operation
Purpose
Returns
inspect_symbol
Resolve a symbol, its definition, references, and dependency neighbourhood
Symbol summary + handles
query_ast
Ask structural questions without reading whole files
AST-node summaries, selectors
plan_refactor
Produce a change plan with blast radius, strategy, validators
Plan object with checkpoints
apply_refactor
Execute one planned transformation step via AST/LSP/codemod
Patch set + provenance
run_validation
Run type-check, lint, unit/integration suites in sandbox
Validation report + artifacts
rollback
Restore workspace to prior checkpoint or inverse patch
Rollback confirmation + scope
Implementation
Tool
Purpose
Tier
Tree-sitter
Parse & AST traversal
LSP
Symbol lookup & references
Codemod
Transformation execution
MCP
Capability negotiation
Semgrep
Pattern matching & fixes
ast-grep
AST queries & rewrites
Git
Checkpoints & rollback
Comby
Structural search fallback
Empirical Validation — 2024–2026
0%
Token Reduction
Cursor Dynamic Context
0%
Portal Efficiency Gain
Cloudflare Code Mode
0%
MCP Token Savings
agentgateway