# System Architecture ## Overview Multi-agent AI development system with Claude Code as orchestrator and pluggable execution backends. ## High-Level Architecture ``` ┌─────────────────────────────────────────────────────────────┐ │ User │ └──────────────────┬──────────────────────────────────────────┘ │ │ /dev, /gh-implement, etc. ▼ ┌─────────────────────────────────────────────────────────────┐ │ Claude Code (Orchestrator) │ │ ┌─────────────────────────────────────────────────────────┐│ │ │ - Planning & context gathering ││ │ │ - Requirements clarification ││ │ │ - Task breakdown ││ │ │ - Verification & reporting ││ │ └─────────────────────────────────────────────────────────┘│ └──────────────────┬──────────────────────────────────────────┘ │ │ via codeagent-wrapper ▼ ┌─────────────────────────────────────────────────────────────┐ │ Codeagent-Wrapper (Execution Layer) │ │ ┌──────────────────────────────────────────────────────────┤ │ │ Backend Interface │ │ ├──────────────┬──────────────┬──────────────┐ │ │ │ Codex │ Claude │ Gemini │ │ │ │ Backend │ Backend │ Backend │ │ │ └──────────────┴──────────────┴──────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────────────┤ │ │ Features: │ │ │ - Multi-backend execution │ │ │ - JSON stream parsing │ │ │ - Session management │ │ │ - Parallel task execution │ │ │ - Timeout handling │ │ └──────────────────────────────────────────────────────────┘ └──────────────────┬──────────────────────────────────────────┘ │ │ CLI invocations ▼ ┌─────────────────────────────────────────────────────────────┐ │ AI CLI Backends │ │ ┌──────────────┬──────────────┬──────────────┐ │ │ │ Codex CLI │ Claude CLI │ Gemini CLI │ │ │ │ │ │ │ │ │ │ Code editing │ Reasoning │ Fast proto │ │ │ └──────────────┴──────────────┴──────────────┘ │ └─────────────────────────────────────────────────────────────┘ ``` ## Component Architecture ### 1. Orchestrator Layer (Claude Code) **Responsibilities:** - User interaction and requirements gathering - Context analysis and exploration - Task planning and breakdown - Workflow coordination - Verification and reporting **Key Workflows:** ``` /dev ├── Requirements clarification (AskUserQuestion) ├── Codex analysis (Task tool → Explore agent) ├── Dev plan generation (Task tool → dev-plan-generator) ├── Parallel execution (codeagent-wrapper --parallel) ├── Coverage validation (≥90%) └── Completion summary /gh-implement ├── Issue analysis (gh issue view) ├── Clarification (if needed) ├── Development (codeagent-wrapper or /dev) ├── Progress updates (gh issue comment) └── PR creation (gh pr create) ``` ### 2. Execution Layer (Codeagent-Wrapper) **Architecture:** ```go ┌─────────────────────────────────────────────────────────┐ │ Main Entry Point │ │ - Parse CLI arguments │ │ - Detect mode (new/resume/parallel) │ │ - Select backend │ └──────────────────┬──────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ Backend Selection │ │ func SelectBackend(name string) Backend │ │ ┌──────────────┬──────────────┬──────────────┐ │ │ │ CodexBackend │ ClaudeBackend│ GeminiBackend│ │ │ └──────────────┴──────────────┴──────────────┘ │ └──────────────────┬──────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ Executor │ │ func RunCodexTask(cfg *Config) (string, error) │ │ ┌──────────────────────────────────────────────────────┤ │ │ 1. Build command args via Backend.BuildArgs() │ │ │ 2. Start process with timeout │ │ │ 3. Stream stdout/stderr │ │ │ 4. Parse JSON stream via ParseJSONStream() │ │ │ 5. Extract session ID │ │ │ 6. Handle signals (SIGINT, SIGTERM) │ │ └──────────────────────────────────────────────────────┘ └──────────────────┬──────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ Parser │ │ func ParseJSONStream(r io.Reader) (string, string) │ │ ┌──────────────────────────────────────────────────────┤ │ │ Detects format: │ │ │ - Codex: {"type":"thread.started","thread_id":...} │ │ │ - Claude: {"type":"...","subtype":"result"} │ │ │ - Gemini: {"type":"...","role":"assistant"} │ │ │ │ │ │ Extracts: │ │ │ - Agent messages │ │ │ - Session IDs │ │ └──────────────────────────────────────────────────────┘ └─────────────────────────────────────────────────────────┘ ``` **Backend Interface:** ```go type Backend interface { Name() string Command() string BuildArgs(cfg *Config, targetArg string) []string } // Codex: codex e --skip-git-repo-check -C --json // Claude: claude -p --dangerously-skip-permissions --output-format stream-json --verbose // Gemini: gemini -o stream-json -y -p ``` **Key Files:** - `main.go` - Entry point and orchestration - `config.go` - CLI argument parsing - `backend.go` - Backend interface and implementations - `executor.go` - Process execution and stream handling - `parser.go` - JSON stream parsing (multi-format) - `logger.go` - Async logging with ring buffer - `utils.go` - Helper functions ### 3. Hooks System **Architecture:** ``` ┌─────────────────────────────────────────────────────────┐ │ Claude Code Events │ │ UserPromptSubmit │ PostToolUse │ Stop │ └──────────────────┬──────────────────────────────────────┘ │ │ reads ▼ ┌─────────────────────────────────────────────────────────┐ │ .claude/settings.json │ │ { │ │ "hooks": { │ │ "UserPromptSubmit": [ │ │ { │ │ "hooks": [ │ │ { │ │ "type": "command", │ │ "command": "$CLAUDE_PROJECT_DIR/hooks/..." │ │ } │ │ ] │ │ } │ │ ] │ │ } │ │ } │ └──────────────────┬──────────────────────────────────────┘ │ │ executes ▼ ┌─────────────────────────────────────────────────────────┐ │ Hook Scripts │ │ ┌────────────────────────────────────────────────────┐ │ │ │ skill-activation-prompt.sh │ │ │ │ - Reads skills/skill-rules.json │ │ │ │ - Matches user prompt against triggers │ │ │ │ - Injects skill suggestions │ │ │ └────────────────────────────────────────────────────┘ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ pre-commit.sh │ │ │ │ - Validates staged files │ │ │ │ - Runs tests │ │ │ │ - Formats code │ │ │ └────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────┘ ``` ### 4. Skills System **Structure:** ``` skills/ ├── codex/ │ └── SKILL.md # Codex CLI integration ├── codeagent/ │ └── SKILL.md # Multi-backend wrapper ├── gemini/ │ └── SKILL.md # Gemini CLI integration └── skill-rules.json # Auto-activation rules ``` **skill-rules.json Format:** ```json { "rules": [ { "trigger": { "pattern": "implement|build|create feature", "type": "regex" }, "skill": "codeagent", "priority": 1, "suggestion": "Use codeagent skill for code implementation" } ] } ``` ## Data Flow ### Example: /dev Workflow ``` 1. User: /dev "add user authentication" │ ▼ 2. Claude Code: │ ├─ Clarifies requirements (AskUserQuestion) │ ├─ Analyzes codebase (Explore agent) │ └─ Generates dev-plan.md │ ▼ 3. Claude Code invokes: codeagent-wrapper --parallel <