Preface: Two Residues, One System
Why neither frozen code nor unconstrained agent loops survive complex production work — and what happens when we separate compile-time expansion from deterministic runtime.
Most production AI discussions trap teams inside a false binary.
On one side sits classic deterministic software. Every route, parser, schema check, and state transition is authored by hand and deployed through manual engineering releases. It is cheap, fast, and auditable — right up until the day reality shifts. A distributor rearranges an invoice PDF, an upstream accounting endpoint renames a tax field, or an operator adds a deposit exception for a new hospitality venue. The software keeps running, but its assumptions are suddenly stale.
On the other side sits the unconstrained agent loop. Give a frontier reasoning model a bundle of tools, dump an operator manual into its system prompt, and ask it to improvise a multi-step workflow on every event. That shines in interactive chat and unfamiliar debugging. Inside unattended back-office operations, however, conversational models exhibit what Diogo Almeida describes as being “Einstein 95 percent of the time, and Mr. Bean 5 percent of the time.” A 5% silent mistake rate — a misread credit-note sign, a skipped deduplication check, or a malformed payload posted twice — creates real financial damage.
Freshware rejects both extremes by recognizing that “build” and “run” belong at different meta-levels.
Three Meta-Levels Instead of One Chat Loop
In Matthew Flatt’s landmark work on Scheme and Racket macros (“Composable and Compilable Macros: You Want It When?”), he argued that macro expansion and runtime execution must occupy cleanly separated phases. Letting expansion-time logic leak arbitrarily into runtime creates fragile, unreadable systems.
Modern agent harnesses commit that exact phase error in reverse: they embed the macro expander (a heavy frontier reasoning model) directly inside the runtime inner loop on every single request.
Freshware restores phase separation across three explicit tiers:
| Meta-Level | Compiler Analogy | What Lives Here | Who / What Executes It | Cadence |
|---|---|---|---|---|
| Phase 2 · Intent & Threads | High-level DSL & rationale | Plain-English playbooks, user requests, broken-API escalation threads, docs/specs/, docs/standards/, decisions.jsonl | Humans + alignment sessions distilled by spec-extract | Days / on drift |
| Phase 1 · Compile & Verify | Macro expansion + typecheck + CEGIS | LLM synthesizer expanding intent into rulebooks/adapters + Gate 1 static invariants + Gate 2 golden dry-runs + Gate 3 shadow checks | Sandboxed compiler inside pi-durable + deterministic oracles | Minutes (event-driven) |
| Phase 0 · Smart Software Runtime | Expanded residual program | Deterministic state transitions, locks, arithmetic — calling pure code (< 1 ms), System One decision gates (~350 ms), or focused extractors only where needed | Deterministic control flow + calibrated classifiers (zero chat loops) | Milliseconds |
How Seven Engineering Disciplines Lock Together
Rather than inventing a brand-new vocabulary from thin air, Freshware discovers that seven existing engineering traditions each solved one coordinate of this three-phase machine — and hit a wall precisely where the next tradition starts. Filter the synthesis matrix below to inspect how each discipline maps into Phase 2, Phase 1, or Phase 0.
Where Every Software Discipline Fits Inside Freshware
| Discipline & Figures | Phase | What It Solves | Blind Spot Alone | Role in Freshware |
|---|---|---|---|---|
| Domain-Driven Design (DDD) Eric Evans | Phase 2 · Intent | Ubiquitous Language, Bounded Contexts, Aggregate Invariants, Anti-Corruption Layers (ACLs). | Static noun boundaries fracture when external environments drift faster than release cycles. | Spatial coordinate system: Bounded Contexts become modular spec packs; ACLs isolate Tier 2 adapters. |
| Behavior-Driven Development (BDD) Dan North, Gojko Adzic | Phase 2 · Intent | Specification by Example — shared concrete scenarios uniting domain operators and engineers. | Step-definition glue rots into brittle test upkeep and omits chaotic, unanticipated failures. | Behavioral oracles: annotated plain-English playbooks plus Golden Pins without test-glue boilerplate. |
| Pre-Build Alignment Skills Matt Pocock, Maggie Appleton | Phase 2 · Intent | Structured exploration (/wayfinder), interrogation (/grill-with-docs + CONTEXT.md), vertical tickets, TDD seams. | Traditionally ends once a pull request merges instead of re-entering when runtime reality shifts. | Front door to Phase 2: prevents zero-alignment PR collapse and refreshes specs whenever threads reopen. |
| Residuality Theory Barry O’Reilly, Stuart Kauffman | Phase 2 · Intent | Hyperliminal systems, random stressor simulation, attractors, contagion analysis, and the Incidence Matrix. | Born as a human workshop practice; lacked an automated loop to recompile stressed edges safely. | Architectural Residue: verifies which boundaries actually stop contagion and defines invariants that must survive. |
| Spec & Decision Extraction session-spec-verify + pi-durable | Phase 1 · Compile | Dual ground truth (diffs = what, transcripts = why), append-only decisions.jsonl, person-only Tier 0 overrides. | Needs explicit mutation tiers and automated runtime triggers to drive self-healing outside manual CLI runs. | Memory & Governance (Knowledge): persists extracted constraints in SQLite and blocks compiler tampering on mounted oracles. |
| Scheme Macros & Futamura Projections Matthew Flatt, Yoshihiko Futamura | Phase 1 · Compile | Phase separation ("You Want It When?"), syntactic towers, partial evaluation into fast residual programs. | Classical partial evaluators assume formal grammar inputs rather than messy human intent or drifting PDFs. | Computational Residue: expands high-level specs into checked runtime code/rulebooks once per structural delta. |
| Smart Software & System One Models Diogo Almeida, typed judgment APIs | Phase 0 · Runtime | Sub-second calibrated binary/choice/ordinal conditionals inside deterministic code ("fourth semantic logic gate"). | Static model weights still misclassify confidently (e.g., 0.98 wrong answer); code must enforce policy and bailouts. | Fast Phase 0 execution: zero open-ended chat loops in production; bailout guards escalate ambiguous cases safely. |
Showing all 7 foundational disciplines across 3 meta-levels.
How to Use This Workbook
Every chapter in this edition lives as a primary, manually editable .mdx file under src/content/chapters/. Prose and live interactive workbenches sit side by side, backed by a real executable @earendil-works/pi-durable SQLite harness in src/experiments/pi-durable/.
Because the central engineering question is how we develop, specify, and extract constraints safely enough for autonomous compilation, Chapters 01 through 03 dig deeply into alignment workflows, Residuality stressor modeling, holdout oracle isolation, and zero-copy conflict forks before Chapters 04 through 06 cover Futamura lowering, outage-vs-drift classification, and the complete 20-chapter blueprint.