Understanding Trellis Through Kubernetes
If you’re familiar with Kubernetes, this document will help you quickly grasp Trellis’s design philosophy.
Table of Contents
- K8s Core Concepts Overview
- Trellis and K8s Analogy
- Reconciliation Mechanism Deep Dive
- Complete Workflow
- Why This Design
1. K8s Core Concepts Overview
1.1 Imperative vs Declarative
Imperative: Describe “how to do it”| Dimension | Imperative | Declarative |
|---|---|---|
| Focus | Process (How) | Result (What) |
| Executor | User orchestrates each step | System auto-reconciles |
| Idempotency | Requires extra handling | Naturally idempotent |
| Error Recovery | Requires user intervention | Self-healing |
1.2 Control Loop
The core of K8s is the Control Loop:2. Trellis and K8s Analogy
2.1 Architecture Mapping
2.2 Core Component Mapping
| Kubernetes | Trellis | Description |
|---|---|---|
| YAML Manifest | Task Directory | Declares desired state |
| Controller | Dispatch | Orchestrates phase execution |
| Reconciliation Loop | Ralph Loop | Loops until verification passes |
| Pod/Container | Agent | Actual execution unit |
| ConfigMap | jsonl + Hook | Injects config/context |
| Actual State | Final Code | Product after reconciliation |
2.3 Key Insight
K8s solves: Infrastructure complexity — Uses declarative to abstract away details, Controller handles reconciliation. Trellis solves: AI development uncertainty — Uses declarative to define expectations (prd.md + guidelines), Ralph Loop handles reconciliation. Common ground:- Users only declare “what they want”, don’t worry about “how to do it”
- System continuously reconciles until actual state matches desired
- Auto-repairs when deviations occur
Next, Chapter 3 details the reconciliation mechanism (Hook + Ralph Loop), and Chapter 4 expands on the complete workflow (Phase 1-4).
3. Reconciliation Mechanism Deep Dive
Trellis reconciliation is achieved through two mechanisms working together: Hook Injection and Ralph Loop.3.1 Hook Injection
Timing: Automatically triggered each time a Subagent is called Function: Injects file contents referenced in jsonl into the Agent’s context- Prevents context overload (Context Rot) — Only injects what’s needed for current phase
- Traceable — jsonl records what context each task used
- Decoupled — Agent doesn’t need to search, focuses on execution
3.2 Ralph Loop
Essence: A programmatic quality gate that intercepts Agent stop requests and forces continuation if verification fails. Trigger timing: When Check Agent attempts to stop Flow:- Programmatic verification is reliable — lint pass means pass, doesn’t depend on AI’s judgment
- Configurable — Different projects can configure different verification commands
- Prevents infinite loops — Max 5 iterations, then force allow
- Complex architectural issues or logic bugs may require human intervention
- Depends on guideline quality; unclear guidelines lead to limited check effectiveness
4. Complete Workflow
4.1 Phase Overview
4.2 Exception Path
If Check Agent reports unfixable issues, Dispatch can call Debug Agent for deep analysis. This is not the default flow, but exception handling.5. Why This Design
5.1 One-Click Complete Workflow
/trellis:start or /trellis:parallel (Claude Code only) launches with one click, AI completes the entire flow:
5.2 Continuous Accumulation of Development Guidelines
5.3 Preventing Context Rot
Too much context causes LLM to:- Distraction — Gets sidetracked by irrelevant information
- Confusion — Information contradicts itself
- Clash — Old and new information conflict
- implement phase: Requirements + related code
- check phase: Development guidelines
- finish phase: Pre-commit checklist
5.4 Programmatic Quality Control
5.5 Traceability
| Record | Content |
|---|---|
| jsonl | What context each task used |
| workspace | Work content of each session |
| task.json | Complete task lifecycle |
Summary
| Concept | K8s | Trellis |
|---|---|---|
| Desired State | YAML Manifest | Task Directory (prd.md + jsonl) |
| Execution Unit | Pod/Container | Agent |
| Reconciliation Loop | Controller | Dispatch + Ralph Loop |
| Config Injection | ConfigMap | Hook + jsonl |
| Final Product | Running Pods | Compliant Code |