|
| 1 | +--- |
| 2 | +status: planned |
| 3 | +created: '2025-11-26' |
| 4 | +tags: |
| 5 | + - ai-agents |
| 6 | + - workflow |
| 7 | + - automation |
| 8 | + - cli |
| 9 | + - integration |
| 10 | + - parallel-development |
| 11 | +priority: high |
| 12 | +created_at: '2025-11-26T06:25:37.182Z' |
| 13 | +related: |
| 14 | + - 118-parallel-spec-implementation |
| 15 | + - 072-ai-agent-first-use-workflow |
| 16 | + - 110-project-aware-agents-generation |
| 17 | +--- |
| 18 | + |
| 19 | +# AI Coding Agent Integration for Automated Spec Orchestration |
| 20 | + |
| 21 | +> **Status**: 📅 Planned · **Priority**: High · **Created**: 2025-11-26 |
| 22 | +
|
| 23 | +**Project**: lean-spec |
| 24 | +**Team**: Core Development |
| 25 | + |
| 26 | +## Overview |
| 27 | + |
| 28 | +Integrate AI coding agents (GitHub Copilot CLI, Claude Code, Gemini CLI, OpenChat, GitHub Coding Agent, etc.) directly into LeanSpec to automate spec implementation orchestration. Currently users manually manage agent sessions, branch creation, and spec status updates. This spec extends the parallel spec implementation work (spec 118) to enable seamless agent-driven development without manual coordination. |
| 29 | + |
| 30 | +**Problem**: |
| 31 | +- Users manually orchestrate AI agents to implement specs (copy context, manage branches, update status) |
| 32 | +- No unified interface across different agent types (CLI-based vs cloud-based) |
| 33 | +- Parallel spec implementation (spec 118) requires manual worktree management |
| 34 | +- Agent sessions are disconnected from spec lifecycle (status, dependencies, completion) |
| 35 | + |
| 36 | +**Goals**: |
| 37 | +1. Unified interface to dispatch specs to various AI coding agents |
| 38 | +2. Automatic environment setup (branches, worktrees) based on spec requirements |
| 39 | +3. Bi-directional sync between agent progress and spec status |
| 40 | +4. Support both CLI agents (local) and cloud agents (GitHub Coding Agent) |
| 41 | +5. Enable parallel spec implementation with minimal manual coordination |
| 42 | + |
| 43 | +## Design |
| 44 | + |
| 45 | +### Supported Agent Types |
| 46 | + |
| 47 | +**CLI-Based Agents (Local)**: |
| 48 | +- GitHub Copilot CLI (`gh copilot`) |
| 49 | +- Claude Code (Anthropic) |
| 50 | +- Gemini CLI (Google) |
| 51 | +- Aider |
| 52 | +- Continue.dev |
| 53 | + |
| 54 | +**Cloud-Based Agents**: |
| 55 | +- GitHub Coding Agent (creates PRs automatically) |
| 56 | +- Future: Other cloud coding services |
| 57 | + |
| 58 | +### Architecture |
| 59 | + |
| 60 | +``` |
| 61 | +┌─────────────────────────────────────────────────────────────┐ |
| 62 | +│ LeanSpec CLI / MCP │ |
| 63 | +├─────────────────────────────────────────────────────────────┤ |
| 64 | +│ Agent Orchestrator │ |
| 65 | +│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ |
| 66 | +│ │ CLI Adapter │ │Cloud Adapter │ │ Status Sync │ │ |
| 67 | +│ │ (local exec) │ │ (API/GH) │ │ (webhooks) │ │ |
| 68 | +│ └──────────────┘ └──────────────┘ └──────────────┘ │ |
| 69 | +├─────────────────────────────────────────────────────────────┤ |
| 70 | +│ Environment Manager │ |
| 71 | +│ • Git worktree creation (parallel specs) │ |
| 72 | +│ • Branch strategy enforcement │ |
| 73 | +│ • Context injection (spec content → agent prompt) │ |
| 74 | +└─────────────────────────────────────────────────────────────┘ |
| 75 | +``` |
| 76 | + |
| 77 | +### Proposed Commands |
| 78 | + |
| 79 | +```bash |
| 80 | +# Dispatch a spec to an AI agent |
| 81 | +lean-spec agent run <spec> [--agent <type>] [--parallel] |
| 82 | + |
| 83 | +# Examples: |
| 84 | +lean-spec agent run 045 --agent claude # Use Claude Code locally |
| 85 | +lean-spec agent run 045 --agent gh-coding # Use GitHub Coding Agent (cloud) |
| 86 | +lean-spec agent run 045 --agent copilot # Use GitHub Copilot CLI |
| 87 | +lean-spec agent run 045 # Use default agent from config |
| 88 | + |
| 89 | +# Run multiple specs in parallel (extends spec 118) |
| 90 | +lean-spec agent run 045 047 048 --parallel # Creates worktrees, dispatches agents |
| 91 | + |
| 92 | +# Check agent status |
| 93 | +lean-spec agent status [<spec>] |
| 94 | + |
| 95 | +# Configure default agent |
| 96 | +lean-spec config set default-agent claude |
| 97 | +``` |
| 98 | + |
| 99 | +### MCP Tool Extensions |
| 100 | + |
| 101 | +```typescript |
| 102 | +// New MCP tools for agent orchestration |
| 103 | +mcp_lean-spec_agent_run // Dispatch spec to agent |
| 104 | +mcp_lean-spec_agent_status // Check agent progress |
| 105 | +mcp_lean-spec_agent_list // List available agents |
| 106 | +``` |
| 107 | + |
| 108 | +### Workflow Integration |
| 109 | + |
| 110 | +**Single Spec → Agent**: |
| 111 | +```bash |
| 112 | +lean-spec agent run 045 --agent claude |
| 113 | +# 1. Updates spec status to in-progress |
| 114 | +# 2. Creates feature branch (feature/045-dashboard) |
| 115 | +# 3. Injects spec content as agent context |
| 116 | +# 4. Launches agent with appropriate prompt |
| 117 | +# 5. Monitors for completion (optional webhook/polling) |
| 118 | +# 6. Updates spec status on completion |
| 119 | +``` |
| 120 | + |
| 121 | +**Parallel Specs → Agents (extends spec 118)**: |
| 122 | +```bash |
| 123 | +lean-spec agent run 045 047 048 --parallel --agent claude |
| 124 | +# 1. Creates .worktrees/ for each spec |
| 125 | +# 2. Updates all specs to in-progress |
| 126 | +# 3. Dispatches agent to each worktree (separate sessions) |
| 127 | +# 4. Monitors all sessions |
| 128 | +# 5. Reports completion status |
| 129 | +``` |
| 130 | + |
| 131 | +**Cloud Agent (GitHub Coding Agent)**: |
| 132 | +```bash |
| 133 | +lean-spec agent run 045 --agent gh-coding |
| 134 | +# 1. Creates GitHub issue from spec (if not exists) |
| 135 | +# 2. Triggers GitHub Coding Agent via API |
| 136 | +# 3. Agent creates branch + PR automatically |
| 137 | +# 4. LeanSpec monitors PR status via webhooks |
| 138 | +# 5. Updates spec status when PR merged |
| 139 | +``` |
| 140 | + |
| 141 | +### Configuration |
| 142 | + |
| 143 | +```yaml |
| 144 | +# .leanspec/config.yaml |
| 145 | +agents: |
| 146 | + default: claude |
| 147 | + |
| 148 | + claude: |
| 149 | + type: cli |
| 150 | + command: claude |
| 151 | + context-template: | |
| 152 | + Implement the following spec: |
| 153 | + --- |
| 154 | + {spec_content} |
| 155 | + --- |
| 156 | + Create the implementation in this worktree. |
| 157 | + |
| 158 | + gh-coding: |
| 159 | + type: cloud |
| 160 | + provider: github |
| 161 | + # Uses GitHub App or PAT for API access |
| 162 | + |
| 163 | + copilot: |
| 164 | + type: cli |
| 165 | + command: gh copilot suggest |
| 166 | +``` |
| 167 | +
|
| 168 | +## Plan |
| 169 | +
|
| 170 | +- [ ] Research agent APIs and CLI interfaces (Claude Code, Copilot CLI, Gemini CLI) |
| 171 | +- [ ] Design agent adapter interface (abstract common operations) |
| 172 | +- [ ] Implement CLI agent adapter (exec-based, stdin/stdout) |
| 173 | +- [ ] Implement GitHub Coding Agent adapter (API-based) |
| 174 | +- [ ] Create `lean-spec agent run` command |
| 175 | +- [ ] Integrate with worktree creation (spec 118) |
| 176 | +- [ ] Add spec status auto-update on agent events |
| 177 | +- [ ] Implement `lean-spec agent status` for monitoring |
| 178 | +- [ ] Add MCP tools for agent orchestration |
| 179 | +- [ ] Document agent setup for each supported provider |
| 180 | +- [ ] Create example workflows in docs |
| 181 | + |
| 182 | +## Test |
| 183 | + |
| 184 | +**Verification Criteria**: |
| 185 | + |
| 186 | +- [ ] Can dispatch a spec to Claude Code and have it start implementation |
| 187 | +- [ ] Can dispatch a spec to GitHub Coding Agent and receive PR |
| 188 | +- [ ] Parallel dispatch creates proper worktrees and isolated sessions |
| 189 | +- [ ] Spec status updates automatically on agent completion |
| 190 | +- [ ] Agent configuration is flexible and extensible |
| 191 | +- [ ] MCP tools work for AI-to-AI orchestration |
| 192 | + |
| 193 | +**Integration Tests**: |
| 194 | + |
| 195 | +- [ ] End-to-end: spec → agent → implementation → PR → status update |
| 196 | +- [ ] Parallel: 3 specs → 3 agents → 3 worktrees → all complete |
| 197 | +- [ ] Failure handling: agent error → spec status reflects failure |
| 198 | + |
| 199 | +## Notes |
| 200 | + |
| 201 | +**Open Questions**: |
| 202 | +- How to handle agent authentication (API keys, OAuth)? |
| 203 | +- Should we support custom agent prompts per spec/project? |
| 204 | +- How to handle long-running agents (timeout, checkpoints)? |
| 205 | +- Priority: CLI agents first (simpler) or cloud agents first (more powerful)? |
| 206 | + |
| 207 | +**Research Needed**: |
| 208 | +- Claude Code CLI interface and automation options |
| 209 | +- GitHub Coding Agent API (triggering, status checking) |
| 210 | +- Gemini CLI capabilities |
| 211 | +- Aider integration patterns |
| 212 | + |
| 213 | +**Related Work**: |
| 214 | +- Spec 118: Git worktrees for parallel development (foundation) |
| 215 | +- Spec 072: AI agent first-use workflow (onboarding) |
| 216 | +- Spec 110: Project-aware AGENTS.md generation (context) |
| 217 | + |
| 218 | +**Alternatives Considered**: |
| 219 | +- IDE-only integration (VS Code tasks) - too narrow |
| 220 | +- Shell scripts only - not portable, hard to maintain |
| 221 | +- Full orchestration platform - too complex for LeanSpec's lean philosophy |
0 commit comments