Reference implementation for the Phoenix Architecture. Work in progress. aicoding.leaflet.pub/
ai coding crazy

docs: add README for open source launch

+176
+176
README.md
··· 1 + # Phoenix VCS 2 + 3 + **Regenerative version control that compiles intent to working software.** 4 + 5 + Phoenix takes a specification written in plain language, extracts structured requirements, and generates a working application — database, API, validation, and UI — with full traceability from every line of spec to every line of generated code. 6 + 7 + ``` 8 + spec/todos.md (40 lines) → phoenix bootstrap → working app 9 + ``` 10 + 11 + ## What it does 12 + 13 + Write what you want in a markdown spec: 14 + 15 + ```markdown 16 + ## Tasks 17 + 18 + - A task has a title, a priority (urgent, high, normal, low), and an optional due date 19 + - Users can create tasks by providing at least a title 20 + - Users can mark a task as complete or reopen a completed task 21 + - Users can filter tasks by status, project, or priority 22 + - Overdue tasks must be visually highlighted 23 + ``` 24 + 25 + Phoenix compiles this through a pipeline: 26 + 27 + ``` 28 + Spec → Clauses → Canonical Requirements → Implementation Units → Generated Code 29 + ``` 30 + 31 + Each transformation is tracked. Change one line in the spec and Phoenix knows exactly which code needs to regenerate — and which doesn't. 32 + 33 + ## Quick start 34 + 35 + ```bash 36 + # Install 37 + git clone https://github.com/chad/phoenix.git 38 + cd phoenix 39 + npm install 40 + npm run build 41 + 42 + # Create a project with the sqlite-web-api architecture 43 + mkdir my-app && cd my-app 44 + mkdir spec 45 + 46 + # Write your spec 47 + cat > spec/app.md << 'EOF' 48 + # My App 49 + 50 + ## Items 51 + 52 + - An item has a name and a quantity 53 + - Users can create, view, update, and delete items 54 + - Name must not be empty 55 + EOF 56 + 57 + # Generate 58 + npx phoenix init --arch=sqlite-web-api 59 + npx phoenix bootstrap 60 + 61 + # Run 62 + npm install 63 + npm run dev 64 + # → http://localhost:3000 65 + ``` 66 + 67 + ## Architecture targets 68 + 69 + Phoenix doesn't just generate code — it compiles to an **architecture**. The architecture target defines the runtime, frameworks, patterns, and conventions. The spec defines *what*, the architecture defines *how*. 70 + 71 + The first built-in target is `sqlite-web-api`: 72 + - **HTTP**: [Hono](https://hono.dev) 73 + - **Database**: [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) 74 + - **Validation**: [Zod](https://zod.dev) 75 + - **Pattern**: Route modules with shared DB, migration system, Zod schemas 76 + 77 + New architectures can be added by creating a single file in `src/architectures/`. The pipeline doesn't change — only the compilation target. 78 + 79 + ## The pipeline 80 + 81 + ``` 82 + ┌──────────┐ ┌──────────┐ ┌──────────────┐ ┌──────┐ ┌───────────┐ 83 + │ Spec │ → │ Clauses │ → │ Canonical │ → │ IUs │ → │ Generated │ 84 + │ (markdown)│ │ (parsed) │ │ Requirements │ │ │ │ Code │ 85 + └──────────┘ └──────────┘ └──────────────┘ └──────┘ └───────────┘ 86 + 87 + ◄──────────── Provenance edges track every transformation ───────┘ 88 + ``` 89 + 90 + - **Spec ingestion**: Parses markdown into content-addressed clauses with semantic hashes 91 + - **Canonicalization**: Extracts typed requirements (REQUIREMENT, CONSTRAINT, INVARIANT, DEFINITION, CONTEXT) with confidence scores and relationship edges 92 + - **IU planning**: Groups requirements into Implementation Units with risk tiers, contracts, and boundary policies 93 + - **Code generation**: LLM generates real implementations guided by architecture-specific prompts and few-shot examples, with typecheck-and-retry 94 + - **Selective invalidation**: Change one spec line → only the dependent subtree regenerates 95 + 96 + ## Visualization 97 + 98 + ```bash 99 + npx phoenix inspect 100 + ``` 101 + 102 + Opens an interactive pipeline visualizer in your browser. Click the **Spec** tab to see your spec text with hover highlighting — click any line to trace its path through clauses → canonical nodes → IUs → generated files. 103 + 104 + ## CLI 105 + 106 + ```bash 107 + phoenix init [--arch=NAME] # Initialize a project 108 + phoenix bootstrap # Full pipeline: ingest → canonicalize → plan → generate 109 + phoenix ingest [--verbose] # Ingest spec changes (shows diff before applying) 110 + phoenix diff # Show clause-level diffs 111 + phoenix canonicalize # Extract canonical requirements 112 + phoenix regen [--iu=ID] # Regenerate code (all or specific IU) 113 + phoenix status # Trust dashboard 114 + phoenix inspect # Interactive pipeline visualization 115 + ``` 116 + 117 + ## Examples 118 + 119 + ### [todo-app](examples/todo-app/) 120 + 121 + A Todoist-style task manager generated from a [user-centric spec](examples/todo-app/spec/todos.md). Features: 122 + - Tasks with priorities, due dates, projects, completion tracking 123 + - Projects with colors and active task counts 124 + - Filtering by status, priority, and project 125 + - Stats summary with completion percentage 126 + - Full web UI with sidebar, forms, filters 127 + - REST API for integration with external tools 128 + 129 + All generated from ~40 lines of behavioral requirements. 130 + 131 + ### [phoenix-self](examples/phoenix-self/) 132 + 133 + Phoenix specifying itself. The [PRD](PRD.md) decomposed into 6 specs covering ingestion, canonicalization, implementation, integrity, operations, and platform. Used to stress-test the canonicalization pipeline on real-world complexity. 134 + 135 + ### Other examples 136 + 137 + - [settle-up](examples/settle-up/) — Expense splitting with debt simplification 138 + - [pixel-wars](examples/pixel-wars/) — Real-time multiplayer territory game 139 + - [tictactoe](examples/tictactoe/) — Multiplayer game with matchmaking 140 + - [taskflow](examples/taskflow/) — Task management with analytics 141 + 142 + ## How it works under the hood 143 + 144 + ### Canonicalization 145 + 146 + Every spec sentence is scored against 5 canonical types using a keyword rubric with configurable weights. The resolution engine deduplicates nodes via token Jaccard similarity, infers typed edges (constrains, refines, defines, invariant_of), and builds a hierarchical graph. The pipeline was optimized through 32 automated experiments (autoresearch-style) across 18 gold-standard specs. 147 + 148 + ### Code generation 149 + 150 + The LLM receives a structured prompt with: 151 + 1. Canonical requirements, constraints, invariants, and definitions for the IU 152 + 2. Architecture-specific system prompt (import rules, patterns, conventions) 153 + 3. Few-shot code examples showing the exact patterns to follow 154 + 4. Related context from other spec sections 155 + 5. Sibling module mount paths (so the web UI knows where the API lives) 156 + 157 + If generation fails or doesn't typecheck, the system retries with error feedback. If that fails, it falls back to architecture-aware stubs that still produce valid, mountable modules. 158 + 159 + ### Drift detection 160 + 161 + Phoenix tracks a manifest of every generated file's content hash. `phoenix status` compares the working tree against the manifest and flags any unlabeled manual edits. This is how Phoenix knows if you've modified generated code and need to either promote the change to a spec requirement or add a waiver. 162 + 163 + ## Status 164 + 165 + Alpha. The core pipeline works end-to-end — spec to working app with full traceability. The `sqlite-web-api` architecture target generates functional CRUD APIs with web UIs from behavioral specs. 166 + 167 + What's next: 168 + - More architecture targets (Express + Postgres, Cloudflare Workers + D1, CLI apps) 169 + - Smarter IU planner (merge cross-cutting concerns into parent resources) 170 + - Selective regeneration from spec edits (the pipeline supports it, the UX needs work) 171 + - Test generation and evidence collection 172 + - Multi-file spec projects with cross-references 173 + 174 + ## License 175 + 176 + MIT