|
1 | | -# CLAUDE.md - Claude Integrations |
2 | | - |
3 | | -## Project Overview |
4 | | - |
5 | | -Monorepo for all Claude AI browser and service integrations, plus AI workflow tools. |
6 | | - |
7 | | -## Components |
8 | | - |
9 | | -| Directory | Description | Stack | |
10 | | -|-----------|-------------|-------| |
11 | | -| firefox-lsp/ | LSP for Firefox via Marionette protocol | Elixir | |
12 | | -| firefox-mcp/ | MCP server for Firefox browser control | Deno/JS | |
13 | | -| gecko-browser-extension/ | Extension for Gecko browsers | JS/WebExtensions | |
14 | | -| gitlab-bridge/ | Claude ↔ GitLab integration | ReScript/Deno | |
15 | | -| mozilla-extension/ | Claude extension for Mozilla products | JS/WebExtensions | |
16 | | -| **model-router/** | **Auto-select Opus/Sonnet/Haiku by task** | **Rust (planned)** | |
17 | | - |
18 | | -## Build |
19 | | - |
20 | | -```bash |
21 | | -just --list # See all build recipes |
22 | | -just build-firefox-lsp # Build Firefox LSP |
23 | | -just build-firefox-mcp # Build Firefox MCP |
24 | | -just build-gecko-extension # Build Gecko extension |
25 | | -just build-gitlab-bridge # Build GitLab bridge |
26 | | -just build-mozilla-extension # Build Mozilla extension |
27 | | -``` |
28 | | - |
29 | | -## Model Router (NEW - Sonnet Task) |
30 | | - |
31 | | -### Purpose |
32 | | - |
33 | | -Auto-select the right Claude model (Opus/Sonnet/Haiku) based on task complexity, saving money on simple tasks and ensuring quality on complex ones. |
34 | | - |
35 | | -### Architecture |
36 | | - |
37 | | -``` |
38 | | -User prompt + repo context |
39 | | - ↓ |
40 | | -Haiku classifier (< 1 second, < $0.001) |
41 | | - ↓ |
42 | | -Classification: trivial | standard | complex |
43 | | - ↓ |
44 | | -Route to: |
45 | | - ├── Haiku: single-file edits, template creation, simple queries |
46 | | - ├── Sonnet: multi-file implementation, feature work, testing |
47 | | - └── Opus: architecture decisions, debugging, cross-repo design |
48 | | -``` |
49 | | - |
50 | | -### Classification Signals |
51 | | - |
52 | | -| Signal | Haiku | Sonnet | Opus | |
53 | | -|--------|-------|--------|------| |
54 | | -| Files affected | 1 | 2-5 | 5+ | |
55 | | -| Task type | rename, typo fix | add feature, implement | debug, design, architect | |
56 | | -| Prompt keywords | "fix typo", "rename", "update" | "add", "create", "implement" | "why", "how", "design", "debug" | |
57 | | -| Repo complexity (from CLAUDE.md) | Low | Medium | High | |
58 | | -| Error recovery needed | No | Maybe | Likely | |
59 | | -| Cross-repo awareness | No | No | Yes | |
60 | | - |
61 | | -### Implementation Plan (for Sonnet) |
62 | | - |
63 | | -1. **Create `model-router/` directory** in this repo |
64 | | -2. **Rust CLI tool** that: |
65 | | - - Reads the prompt from stdin or argument |
66 | | - - Reads `.claude/CLAUDE.md` from current directory for repo context |
67 | | - - Calls Haiku API to classify complexity (one fast API call) |
68 | | - - Outputs recommended model to stdout: `haiku`, `sonnet`, or `opus` |
69 | | -3. **Claude Code hook integration**: |
70 | | - - Pre-prompt hook reads model recommendation |
71 | | - - Switches model via `/model` command or API parameter |
72 | | -4. **Escalation logic**: |
73 | | - - If chosen model fails or stalls (detected by output quality heuristics) |
74 | | - - Automatically escalate: Haiku → Sonnet → Opus |
75 | | -5. **Cost tracking**: |
76 | | - - Log which model was used, tokens consumed, task outcome |
77 | | - - Weekly summary of cost savings vs always-using-Opus |
78 | | - |
79 | | -### Cargo.toml Sketch |
80 | | - |
81 | | -```toml |
82 | | -[package] |
83 | | -name = "model-router" |
84 | | -version = "0.1.0" |
85 | | -authors = ["Jonathan D.A. Jewell <jonathan.jewell@open.ac.uk>"] |
86 | | -license = "PMPL-1.0-or-later" |
87 | | - |
88 | | -[dependencies] |
89 | | -clap = { version = "4", features = ["derive"] } |
90 | | -reqwest = { version = "0.12", features = ["json"] } |
91 | | -serde = { version = "1", features = ["derive"] } |
92 | | -serde_json = "1" |
93 | | -tokio = { version = "1", features = ["full"] } |
94 | | -``` |
95 | | - |
96 | | -### Usage (Target) |
97 | | - |
98 | | -```bash |
99 | | -# Classify a task |
100 | | -echo "fix the typo in README.md" | model-router classify |
101 | | -# Output: haiku |
102 | | - |
103 | | -echo "implement the sweep subcommand for panic-attack" | model-router classify |
104 | | -# Output: sonnet |
105 | | - |
106 | | -echo "why is my system crashing and how should we architect the fix" | model-router classify |
107 | | -# Output: opus |
108 | | - |
109 | | -# With repo context |
110 | | -model-router classify --repo /path/to/repo "add authentication" |
111 | | -# Reads .claude/CLAUDE.md, factors in repo complexity |
112 | | -``` |
113 | | - |
114 | | -## Code Style |
115 | | - |
116 | | -- SPDX headers: `PMPL-1.0-or-later` |
117 | | -- Author: Jonathan D.A. Jewell <jonathan.jewell@open.ac.uk> |
118 | | -- Browser extensions use `MPL-2.0` fallback (store requirements) |
| 1 | +# CLAUDE.md - Claude Integrations |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Monorepo for all Claude AI browser and service integrations, plus AI workflow tools. |
| 6 | + |
| 7 | +## Components |
| 8 | + |
| 9 | +| Directory | Description | Stack | |
| 10 | +|-----------|-------------|-------| |
| 11 | +| firefox-lsp/ | LSP for Firefox via Marionette protocol | Elixir | |
| 12 | +| firefox-mcp/ | MCP server for Firefox browser control | Deno/JS | |
| 13 | +| gecko-browser-extension/ | Extension for Gecko browsers | JS/WebExtensions | |
| 14 | +| gitlab-bridge/ | Claude ↔ GitLab integration | ReScript/Deno | |
| 15 | +| mozilla-extension/ | Claude extension for Mozilla products | JS/WebExtensions | |
| 16 | +| **model-router/** | **Auto-select Opus/Sonnet/Haiku by task** | **Rust (planned)** | |
| 17 | + |
| 18 | +## Build |
| 19 | + |
| 20 | +```bash |
| 21 | +just --list # See all build recipes |
| 22 | +just build-firefox-lsp # Build Firefox LSP |
| 23 | +just build-firefox-mcp # Build Firefox MCP |
| 24 | +just build-gecko-extension # Build Gecko extension |
| 25 | +just build-gitlab-bridge # Build GitLab bridge |
| 26 | +just build-mozilla-extension # Build Mozilla extension |
| 27 | +``` |
| 28 | + |
| 29 | +## Model Router (NEW - Sonnet Task) |
| 30 | + |
| 31 | +### Purpose |
| 32 | + |
| 33 | +Auto-select the right Claude model (Opus/Sonnet/Haiku) based on task complexity, saving money on simple tasks and ensuring quality on complex ones. |
| 34 | + |
| 35 | +### Architecture |
| 36 | + |
| 37 | +``` |
| 38 | +User prompt + repo context |
| 39 | + ↓ |
| 40 | +Haiku classifier (< 1 second, < $0.001) |
| 41 | + ↓ |
| 42 | +Classification: trivial | standard | complex |
| 43 | + ↓ |
| 44 | +Route to: |
| 45 | + ├── Haiku: single-file edits, template creation, simple queries |
| 46 | + ├── Sonnet: multi-file implementation, feature work, testing |
| 47 | + └── Opus: architecture decisions, debugging, cross-repo design |
| 48 | +``` |
| 49 | + |
| 50 | +### Classification Signals |
| 51 | + |
| 52 | +| Signal | Haiku | Sonnet | Opus | |
| 53 | +|--------|-------|--------|------| |
| 54 | +| Files affected | 1 | 2-5 | 5+ | |
| 55 | +| Task type | rename, typo fix | add feature, implement | debug, design, architect | |
| 56 | +| Prompt keywords | "fix typo", "rename", "update" | "add", "create", "implement" | "why", "how", "design", "debug" | |
| 57 | +| Repo complexity (from CLAUDE.md) | Low | Medium | High | |
| 58 | +| Error recovery needed | No | Maybe | Likely | |
| 59 | +| Cross-repo awareness | No | No | Yes | |
| 60 | + |
| 61 | +### Implementation Plan (for Sonnet) |
| 62 | + |
| 63 | +1. **Create `model-router/` directory** in this repo |
| 64 | +2. **Rust CLI tool** that: |
| 65 | + - Reads the prompt from stdin or argument |
| 66 | + - Reads `.claude/CLAUDE.md` from current directory for repo context |
| 67 | + - Calls Haiku API to classify complexity (one fast API call) |
| 68 | + - Outputs recommended model to stdout: `haiku`, `sonnet`, or `opus` |
| 69 | +3. **Claude Code hook integration**: |
| 70 | + - Pre-prompt hook reads model recommendation |
| 71 | + - Switches model via `/model` command or API parameter |
| 72 | +4. **Escalation logic**: |
| 73 | + - If chosen model fails or stalls (detected by output quality heuristics) |
| 74 | + - Automatically escalate: Haiku → Sonnet → Opus |
| 75 | +5. **Cost tracking**: |
| 76 | + - Log which model was used, tokens consumed, task outcome |
| 77 | + - Weekly summary of cost savings vs always-using-Opus |
| 78 | + |
| 79 | +### Cargo.toml Sketch |
| 80 | + |
| 81 | +```toml |
| 82 | +[package] |
| 83 | +name = "model-router" |
| 84 | +version = "0.1.0" |
| 85 | +authors = ["Jonathan D.A. Jewell <jonathan.jewell@open.ac.uk>"] |
| 86 | +license = "PMPL-1.0-or-later" |
| 87 | + |
| 88 | +[dependencies] |
| 89 | +clap = { version = "4", features = ["derive"] } |
| 90 | +reqwest = { version = "0.12", features = ["json"] } |
| 91 | +serde = { version = "1", features = ["derive"] } |
| 92 | +serde_json = "1" |
| 93 | +tokio = { version = "1", features = ["full"] } |
| 94 | +``` |
| 95 | + |
| 96 | +### Usage (Target) |
| 97 | + |
| 98 | +```bash |
| 99 | +# Classify a task |
| 100 | +echo "fix the typo in README.md" | model-router classify |
| 101 | +# Output: haiku |
| 102 | + |
| 103 | +echo "implement the sweep subcommand for panic-attack" | model-router classify |
| 104 | +# Output: sonnet |
| 105 | + |
| 106 | +echo "why is my system crashing and how should we architect the fix" | model-router classify |
| 107 | +# Output: opus |
| 108 | + |
| 109 | +# With repo context |
| 110 | +model-router classify --repo /path/to/repo "add authentication" |
| 111 | +# Reads .claude/CLAUDE.md, factors in repo complexity |
| 112 | +``` |
| 113 | + |
| 114 | +## Code Style |
| 115 | + |
| 116 | +- SPDX headers: `PMPL-1.0-or-later` |
| 117 | +- Author: Jonathan D.A. Jewell <jonathan.jewell@open.ac.uk> |
| 118 | +- Browser extensions use `MPL-2.0` fallback (store requirements) |
0 commit comments