AGENTS.md Β· diff
git:20260219.cf095ad to git:20260308.a992b7e
10 added, 0 removed. Audit A to A.
# CodeFRAME Development Guidelines (v2)
Last updated: 2026-02-19
**Status: Phase 1 β
| Phase 2 β
| Phase 2.5 β
| Phase 3 In Progress**
This repo completed an **in-place v2 refactor** ("strangler rewrite"). The result is a **headless, CLI-first Golden Path** with all UI/server layers as optional adapters.
If you are an agent working in this repo: **do not improvise architecture**. Follow the documents listed below.
---
## π¦Primary Contract (MUST FOLLOW)
1) **Golden Path**: `docs/GOLDEN_PATH.md`
The only workflow we build until it works end-to-end.
2) **Refactor Plan**: `docs/REFACTOR_PLAN_FOR_AGENT.md`
Step-by-step refactor instructions.
3) **Command Tree + Module Mapping**: `docs/CLI_WIREFRAME.md`
The authoritative map from CLI commands β core modules/functions.
4) **Agent Implementation**: `docs/AGENT_IMPLEMENTATION_TASKS.md`
Tracks the agent system components (all complete).
5) **Strategic Roadmap**: `docs/V2_STRATEGIC_ROADMAP.md`
5-phase plan: CLI completion β Server layer β Web UI β Multi-agent β Advanced features.
**Rule 0:** If a change does not directly support Golden Path, do not implement it.
---
## Current Architecture (v2)
- **Core-first**: Domain logic lives in `codeframe/core/` (headless, no FastAPI imports)
- **CLI-first**: Golden Path works **without any running FastAPI server**
- **Adapters**: LLM providers in `codeframe/adapters/llm/`
- **Server/UI optional**: FastAPI and UI are thin adapters over core
- **Default engine**: ReAct (observe β think β act loop) β legacy plan engine available via `--engine plan`
### v1 Legacy
- FastAPI server + WebSockets + React/Next.js dashboard retained for reference
- Do not build toward v1 patterns
---
## Repository Structure
```
codeframe/
βββ core/ # Headless domain + orchestration (NO FastAPI imports)
β βββ react_agent.py # ReAct agent (default engine) - observe-think-act loop
β βββ tools.py # Tool definitions for ReAct agent (7 tools)
β βββ editor.py # Search-replace file editor with fuzzy matching
β βββ agent.py # Legacy plan-based agent (--engine plan)
β βββ planner.py # LLM-powered implementation planning (plan engine)
β βββ executor.py # Code execution engine with rollback (plan engine)
β βββ context.py # Task context loader with relevance scoring
β βββ tasks.py # Task management with depends_on field
β βββ blockers.py # Human-in-the-loop blocker system
β βββ runtime.py # Run lifecycle management
β βββ conductor.py # Batch orchestration with worker pool
β βββ dependency_graph.py # DAG operations and execution planning
β βββ gates.py # Verification gates (ruff, pytest, BUILD)
β βββ state_machine.py # Task status transitions
β βββ ...
βββ adapters/
β βββ llm/ # LLM provider adapters
β βββ base.py # Protocol + ModelSelector + Purpose enum
β βββ anthropic.py # Anthropic Claude provider
β βββ mock.py # Mock provider for testing
βββ cli/
β βββ app.py # Typer CLI entry + subcommands
βββ ui/ # FastAPI server (Phase 2 - thin adapter over core)
β βββ server.py # FastAPI app with OpenAPI configuration
β βββ models.py # Pydantic request/response models
β βββ dependencies.py # Shared dependencies (workspace, auth)
β βββ routers/ # API route handlers (15 modules)
βββ lib/ # Shared utilities
βββ auth/ # Authentication
βββ config/ # Configuration
βββ server/ # Legacy server code (reference only)
web-ui/ # Next.js frontend (Phase 3)
βββ src/
β βββ app/ # Next.js App Router pages
β βββ components/ # React components
β β βββ ui/ # Shadcn/UI base components
β β βββ workspace/ # Workspace view components
β β βββ prd/ # PRD view components
β β βββ tasks/ # Task board components
β β βββ execution/ # Execution monitor components
β βββ hooks/ # Custom React hooks (SSE, task streams)
β βββ lib/ # API client, utilities
β βββ types/ # TypeScript type definitions
βββ __tests__/ # Jest unit tests
βββ __mocks__/ # Test mocks
tests/ # Python tests
βββ core/ # Core module tests
βββ adapters/ # Adapter tests
```
---
## Architecture Rules (non-negotiable)
### 1) Core must be headless
`codeframe/core/**` must NOT import FastAPI, WebSocket frameworks, HTTP request/response objects, or UI modules.
### 2) CLI must not require a server
Golden Path commands must work from the CLI with **no server running**.
### 3) Agent state transitions flow through runtime
- Agent manages its own `AgentState` (IDLE, PLANNING, EXECUTING, BLOCKED, COMPLETED, FAILED)
- Runtime handles all `TaskStatus` transitions (BACKLOG, READY, IN_PROGRESS, DONE, BLOCKED, FAILED)
- Agent does NOT call `tasks.update_status()` β runtime does this based on agent state
### 4) Legacy can be read, not depended on
Do NOT import legacy UI/server modules into core. Do NOT "fix the UI" during Golden Path work.
### 5) Keep commits runnable
`codeframe --help` must work at all times. Avoid breaking the repo with large renames/moves.
---
## Agent System
### Engine Selection
| Engine | Flag | Pattern | Best For |
|--------|------|---------|----------|
| **ReAct** (default) | `--engine react` | Observe β Think β Act loop | Most tasks, adaptive execution |
| **Plan** (legacy) | `--engine plan` | Plan all steps β Execute sequentially | Well-defined, predictable tasks |
### ReAct Agent Tools (7)
`read_file`, `edit_file`, `create_file`, `run_command`, `run_tests`, `search_codebase`, `list_files`
+ ### Stall Detection
+ If the agent makes no tool calls for a configurable duration, the stall monitor kills execution and creates a blocker.
+
+ | Setting | Default | Description |
+ |---------|---------|-------------|
+ | `--stall-timeout` CLI flag | 300s | Seconds without a tool call before agent is considered stalled (0 = disabled) |
+ | `agent_budget.stall_timeout_s` in `.codeframe/config.yaml` | 300 | Same, configured via project config |
+
+ On stall: a blocker is created with context about the stall, and the task transitions to BLOCKED.
+
### Model Selection
- **PLANNING** β claude-sonnet-4-20250514 (complex reasoning)
- **EXECUTION** β claude-sonnet-4-20250514 (balanced)
- **GENERATION** β claude-haiku-4-20250514 (fast/cheap)
---
## Commands (v2 CLI)
### Python
```bash
uv run pytest # Run all tests
uv run pytest tests/core/ # Core module tests only
uv run ruff check . # Linting
```
### CLI (Golden Path)
```bash
# Workspace
cf init <repo> --detect # Initialize + auto-detect tech stack
cf status
# PRD
cf prd add <file.md>
cf prd generate # Interactive AI-guided PRD creation
# Tasks
cf tasks generate # Generate from PRD via LLM
cf tasks list [--status READY]
# Work execution
cf work start <task-id> --execute # ReAct engine (default)
cf work start <task-id> --execute --engine plan # Legacy plan engine
cf work start <task-id> --execute --verbose # With detailed output
cf work follow <task-id> # Stream real-time output
cf work stop <task-id> # Cancel stale run
cf work resume <task-id> # Resume blocked work
cf work diagnose <task-id> # AI-powered diagnosis
# Batch execution
cf work batch run --all-ready --strategy parallel
cf work batch run --strategy auto --retry 3
# Blockers, review, checkpoints
cf blocker list / answer <id> "..."
cf review
cf checkpoint create "name"
# Environment & PR
cf env check / doctor
cf pr create / status / merge
```
### Frontend
```bash
cd web-ui && npm test # Jest unit tests
cd web-ui && npm run dev # Dev server at http://localhost:3000
```
---
## Web UI (Phase 3)
### Tech Stack
- **Next.js 16** with App Router
- **Shadcn/UI** (Nova preset) with gray color scheme
- **Hugeicons** (`@hugeicons/react`) β never use lucide-react
- **Tailwind CSS** for styling
- **SSE hooks** (`useEventSource`, `useTaskStream`) for real-time streaming
### Views
| View | Route | Status |
|------|-------|--------|
| Workspace | `/` | β
Complete (#335) |
| PRD | `/prd` | β
Complete (#330) |
| Task Board | `/tasks` | β
Complete (#331, #340) |
| Execution Monitor | `/execution/[taskId]` | In Progress |
| Blockers | β | Planned |
| Review & Commit | β | Planned |
### Task Board Features (#331, #340)
- 6-column Kanban: Backlog β Ready β In Progress β Blocked β Failed β Done
- Search & filter with debounced input and status pill toggles
- Batch execution: select tasks, choose strategy, execute
- Bulk stop: stop selected IN_PROGRESS tasks with confirmation dialog
- Bulk reset: reset FAILED/DONE tasks back to READY with confirmation dialog
- Task detail modal: metadata, dependencies, estimated hours, action buttons
- View Execution: IN_PROGRESS tasks navigate to `/execution/{taskId}`
- Per-task loading states during stop/reset operations
- WCAG 2.1 keyboard navigation
### Key Frontend Patterns
- All API endpoints require `workspace_path` query parameter
- Types in `web-ui/src/types/index.ts`, API client in `web-ui/src/lib/api.ts`
- SSE hooks: `useEventSource.ts` (generic) + `useTaskStream.ts` (typed execution events)
- Test mocks for `@hugeicons/react` in `web-ui/__mocks__/@hugeicons/react.js`
---
## Server Layer (Phase 2)
**Pattern**: Thin adapter over core β server routes delegate to `core.*` modules.
```
CLI (typer) ββ¬ββ core.* βββ adapters.*
β
Server (fastapi) ββ
```
- **15 v2 router modules** covering tasks, PRD, blockers, workspace, batches, streaming, auth, and more
- **API key auth** with scopes (read/write/admin)
- **Rate limiting** configurable per-endpoint
- **SSE streaming** at `/api/v2/tasks/{id}/stream`
- **OpenAPI docs** at `/docs` (Swagger) and `/redoc`
---
## Documentation Navigation
### Authoritative (v2)
- `docs/GOLDEN_PATH.md` β CLI-first workflow contract
- `docs/REFACTOR_PLAN_FOR_AGENT.md` β Step-by-step refactor instructions
- `docs/CLI_WIREFRAME.md` β Command β module mapping
- `docs/AGENT_IMPLEMENTATION_TASKS.md` β Agent system components
- `docs/V2_STRATEGIC_ROADMAP.md` β 5-phase plan
- `docs/REACT_AGENT_ARCHITECTURE.md` β ReAct agent deep-dive
### Legacy (v1 reference only)
- `SPRINTS.md`, `sprints/`, `specs/`, `CODEFRAME_SPEC.md`
- v1 feature docs (context/session/auth/UI state management)
---
## What NOT to do (common agent failure modes)
- Don't add new HTTP endpoints to support the CLI
- Don't require `codeframe serve` for CLI workflows
- Don't implement UI concepts (tabs, panels, progress bars) inside core
- Don't redesign auth, websockets, or UI state management
- Don't add multi-providers/model switching features before Golden Path works
- Don't "clean up the repo" as a goal β only refactor to enable Golden Path
- Don't update task status from agent.py β let runtime handle transitions
---
## Practical Working Mode for Agents
When implementing anything, do this loop:
1. Read `docs/GOLDEN_PATH.md` and confirm the change is required
2. Find the command in `docs/CLI_WIREFRAME.md`
3. Implement core functionality in `codeframe/core/`
4. Call it from Typer command in `codeframe/cli/`
5. Emit events + persist state
6. Keep it runnable. Commit.
If you are unsure which direction to take, default to:
- simpler state
- fewer dependencies
- smaller surface area
- core-first, CLI-first
---
## Testing
```bash
uv run pytest # All Python tests
uv run pytest -m v2 # v2 tests only
cd web-ui && npm test # Frontend Jest tests
```
Convention: Mark new v2 tests with `@pytest.mark.v2` or `pytestmark = pytest.mark.v2`.