Automated Workflow — Linear Issue → Pull Request
1. Complexity Gate & Three-Tier Routing
Every task passes through a complexity gate before the agent chain runs:
Issue with labels ["plan"]
→ resolve_tier(labels) # checks for "premium"/"claude" override
→ if no override: classify_complexity(title, description)
→ routes to SIMPLE | MEDIUM | COMPLEX | PREMIUM
→ each agent gets its assigned providerTier Decision Table
| Tier | Trigger | PM | Architect | Coder | Reviewer | Healer |
|---|---|---|---|---|---|---|
| Simple | classifier | Ollama | Ollama | Ollama | Ollama | Ollama |
| Medium | classifier | DeepSeek | DeepSeek | DeepSeek | DeepSeek | DeepSeek |
| Complex | classifier | DeepSeek | o3-mini | o3-mini | o3-mini | DeepSeek |
| Premium | label | DeepSeek | Claude | Claude | Claude | DeepSeek |
Fallback Safety (Claude is NEVER used unless premium label is set)
| Primary | Falls back to |
|---|---|
| Ollama | DeepSeek → error |
| DeepSeek | error (Cheapest cloud — no further fallback) |
| o3-mini | DeepSeek → error |
| Claude | o3-mini → DeepSeek → error |
2. Tag-Based Two-Phase Trigger
Linear Issue created/updated with tag "plan" or "implement"
→ n8n webhook → POST /webhook to pipeline.py (Mac Studio)
→ projects.yaml lookup (team_id → repo, base_branch, trigger_labels)
→ complexity gate → Execute phase based on tag2. Phase: Plan (tag: "plan")
3. Phase: Implement (tag: "implement")
4. 6-Agent Chain
| Agent | Role | Input | Output | Default Provider |
|---|---|---|---|---|
| PM | Spec generation | Issue title + body | JSON: spec, acceptance_criteria, files, risk | Ollama (simple) / DeepSeek (medium+) |
| Architect | Technical planning | Spec + plan.md | JSON: file_plan, invariants, test_plan | Ollama / DeepSeek / o3-mini / Claude |
| Coder | Code generation | Plan | JSON: file contents + commands | Ollama / DeepSeek / o3-mini / Claude |
| Reviewer | Code review | Git diff | JSON: overall, issues, summary | Ollama / DeepSeek / o3-mini / Claude |
| Healer | Auto-fix | Diff + review issues | JSON: fixed files | Ollama / DeepSeek |
| Release | PR management | Branch, title, body | PR URL | Ollama / DeepSeek |
5. Multi-Repo Configuration
Edit projects.yaml to map Linear teams to GitHub repos:
yaml
projects:
healthtech:
linear_team_id: "TEAM_UUID_1"
github_repo: "org/healthtech"
trigger_labels:
plan: "plan"
implement: "implement"6. Cost Control
| Tier | Cloud Cost/Task | Monthly (60 tasks) |
|---|---|---|
| Simple (24 tasks) | $0 | $0 |
| Medium (24 tasks) | ~$0.01 | ~$0.24 |
| Complex (12 tasks) | ~$0.08 | ~$0.96 |
| Classification overhead | ~$0.001 | ~$0.06 |
| Total | ~$1.26 |
Claude Premium only activates when you tag an issue with premium or claude. At ~$0.30/task, using it for 5 tasks/month adds ~$1.50 — still well under $20.
7. Error Handling
| Failure | Retry | Escalation |
|---|---|---|
| LLM timeout | Tier-aware fallback chain | Telegram notify |
| Review blocked | — | Stop, notify human |
| Review changes_requested | Healer agent (max 3) | Human review via Telegram/PWA |
| Git push conflict | Rebase + retry | Telegram notify |
| All providers down | — | Grafana alert + Telegram |