Canadian AI

Canadian AI — Research Framework

Grammar Is All You Need

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

Stop paying the inference bill twice.

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

01 / 08The task

Same refactor, two approaches

A single refactoring task, run two ways — a traditional harness on top, GIRL below.

0%

Fewer tokens / task

8.2k → 2.1k end-to-end

0×

Inference pass

down from 2× speculative

Tokens per refactor task

Claude Codeharness baseline
0
Codexharness baseline
0
GIRLCanadian AI
0

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

When AI writes and then rewrites, you pay the inference provider twice.

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

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

Reversible Pipeline

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

Six Reversible Primitives

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

Adapter Architecture

Tool

Purpose

Tier

Tree-sitter

Parse & AST traversal

Primary

LSP

Symbol lookup & references

Primary

Codemod

Transformation execution

Primary

MCP

Capability negotiation

Primary

Semgrep

Pattern matching & fixes

Secondary

ast-grep

AST queries & rewrites

Secondary

Git

Checkpoints & rollback

Primary

Comby

Structural search fallback

Fallback

Empirical Validation — 2024–2026

0%

Token Reduction

Cursor Dynamic Context

0%

Portal Efficiency Gain

Cloudflare Code Mode

0%

MCP Token Savings

agentgateway