ctx-cc 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/commands/help.md CHANGED
@@ -4,16 +4,16 @@ description: Show CTX commands and usage guide
4
4
  ---
5
5
 
6
6
  <objective>
7
- Display the CTX 2.2 command reference.
7
+ Display the CTX 2.3 command reference.
8
8
 
9
9
  Output ONLY the reference content below. Do NOT add project-specific analysis.
10
10
  </objective>
11
11
 
12
12
  <reference>
13
- # CTX 2.2 Command Reference
13
+ # CTX 2.3 Command Reference
14
14
 
15
15
  **CTX** (Continuous Task eXecution) - Smart workflow orchestration for Claude Code.
16
- 8 commands. PRD-driven. Smart routing. Debug loop until 100% fixed.
16
+ 8 commands. PRD-driven. Design-first. Smart routing. Debug loop until 100% fixed.
17
17
 
18
18
  ## Quick Start
19
19
 
@@ -24,7 +24,17 @@ Output ONLY the reference content below. Do NOT add project-specific analysis.
24
24
  4. /ctx pause Checkpoint when needed
25
25
  ```
26
26
 
27
- ## What's New in 2.2
27
+ ## What's New in 2.3
28
+
29
+ - **Design System Integration** - Full brand + UI design workflow
30
+ - **ctx-designer Agent** - WCAG 2.2 AA, W3C tokens, Figma MCP, Gemini
31
+ - **Story Types** - feature, brand, design, fix, refactor
32
+ - **3 Options Pattern** - Always present A/B/C for design decisions
33
+ - **Visual Approval Gates** - Mood board → Direction → Prototype → Final
34
+ - **BRAND_KIT.md** - Visual foundation with W3C design tokens
35
+ - **EAA 2025 Ready** - European Accessibility Act compliance
36
+
37
+ ## What's in 2.2
28
38
 
29
39
  - **Front-Loaded Approach** - Gather ALL info upfront, execute autonomously
30
40
  - **PRD.json** - Requirements contract with user stories
@@ -131,6 +141,47 @@ Loop (max 5 attempts):
131
141
  | Substantive | Real code, not stub? | No TODOs, no placeholders |
132
142
  | Wired | Imported and used? | Trace imports |
133
143
 
144
+ ## Design Workflow
145
+
146
+ CTX handles visual work with dedicated agents and approval gates.
147
+
148
+ ### Story Types
149
+ | Type | Agent | Purpose |
150
+ |------|-------|---------|
151
+ | feature | ctx-executor | Standard implementation |
152
+ | brand | ctx-designer | BRAND_KIT.md + tokens |
153
+ | design | ctx-designer | UI components/pages |
154
+ | fix | ctx-debugger | Bug fixes |
155
+ | refactor | ctx-executor | Code improvements |
156
+
157
+ ### Design Approval Gates
158
+ ```
159
+ Mood Board → Direction (A/B/C) → Prototype → Final
160
+ ```
161
+ Each gate requires user approval before proceeding.
162
+
163
+ ### 3 Options Pattern
164
+ All design decisions present:
165
+ - **Option A**: Conservative (safe, proven)
166
+ - **Option B**: Balanced (recommended)
167
+ - **Option C**: Bold (distinctive)
168
+
169
+ ### WCAG 2.2 AA Compliance
170
+ | Criterion | Requirement |
171
+ |-----------|-------------|
172
+ | 2.4.11 | Focus not obscured |
173
+ | 2.5.7 | Drag alternatives |
174
+ | 2.5.8 | 24x24px targets |
175
+ | 3.3.8 | Accessible auth |
176
+
177
+ ### W3C Design Tokens
178
+ ```
179
+ tokens/
180
+ ├── primitive.tokens.json # Raw values
181
+ ├── semantic.tokens.json # Purpose aliases
182
+ └── component.tokens.json # Component-specific
183
+ ```
184
+
134
185
  ## Key Design Principles
135
186
 
136
187
  ### Atomic Planning (2-3 Tasks Max)
@@ -151,13 +202,14 @@ Prevents context degradation. Big work = multiple phases.
151
202
  | 30-50% | Good | Continue |
152
203
  | 50%+ | Degrading | Auto-checkpoint |
153
204
 
154
- ## 5 Specialized Agents
205
+ ## 6 Specialized Agents
155
206
 
156
207
  | Agent | When spawned |
157
208
  |-------|--------------|
158
209
  | ctx-researcher | During planning (ArguSeek + ChunkHound) |
159
210
  | ctx-planner | After research |
160
- | ctx-executor | During execution |
211
+ | ctx-executor | During execution (feature stories) |
212
+ | ctx-designer | During execution (brand/design stories) |
161
213
  | ctx-debugger | When debugging |
162
214
  | ctx-verifier | During verification |
163
215
 
@@ -166,6 +218,8 @@ Prevents context degradation. Big work = multiple phases.
166
218
  - **ArguSeek**: Web research during planning
167
219
  - **ChunkHound**: Semantic code search (`uv tool install chunkhound`)
168
220
  - **Playwright/DevTools**: Browser verification for UI
221
+ - **Figma MCP**: Design context extraction and screenshots
222
+ - **Gemini Design**: Image generation and UI code generation
169
223
 
170
224
  ## Directory Structure
171
225
 
@@ -178,21 +232,48 @@ Prevents context degradation. Big work = multiple phases.
178
232
  ├── phases/{story_id}/ # Per-story data
179
233
  │ ├── RESEARCH.md # ArguSeek + ChunkHound results
180
234
  │ ├── PLAN.md # Tasks mapped to acceptance criteria
181
- └── VERIFY.md # Verification report
235
+ ├── VERIFY.md # Verification report
236
+ │ ├── MOOD_BOARD.md # Design references (design stories)
237
+ │ └── DESIGN_BRIEF.md # Design decisions (design stories)
182
238
  ├── checkpoints/ # Auto-checkpoints
183
239
  ├── debug/ # Debug screenshots
184
240
  └── verify/ # Verification screenshots
241
+
242
+ project/
243
+ ├── BRAND_KIT.md # Visual foundation (brand stories)
244
+ └── tokens/ # W3C design tokens
245
+ ├── primitive.tokens.json
246
+ ├── semantic.tokens.json
247
+ └── component.tokens.json
185
248
  ```
186
249
 
187
250
  ## PRD.json Structure
188
251
 
189
252
  ```json
190
253
  {
254
+ "brand": {
255
+ "hasBrandKit": false,
256
+ "personality": ["professional", "modern"],
257
+ "euMarket": true
258
+ },
259
+ "design": {
260
+ "wcagLevel": "AA",
261
+ "eaaCompliance": true,
262
+ "tokenFormat": "w3c"
263
+ },
191
264
  "stories": [
192
265
  {
193
266
  "id": "S001",
194
- "title": "User login",
195
- "acceptanceCriteria": ["User can log in with email", "..."],
267
+ "type": "brand",
268
+ "title": "Establish brand kit",
269
+ "acceptanceCriteria": ["BRAND_KIT.md exists", "tokens/ populated"],
270
+ "passes": false
271
+ },
272
+ {
273
+ "id": "S002",
274
+ "type": "design",
275
+ "title": "Login page",
276
+ "acceptanceCriteria": ["WCAG 2.2 AA compliant", "All states implemented"],
196
277
  "passes": false
197
278
  }
198
279
  ],
@@ -211,5 +292,5 @@ npx ctx-cc --force
211
292
  ```
212
293
 
213
294
  ---
214
- *CTX 2.2 - PRD-driven, story-verified, debug loop until 100% fixed*
295
+ *CTX 2.3 - PRD-driven, design-first, story-verified, debug loop until 100% fixed*
215
296
  </reference>
package/commands/init.md CHANGED
@@ -1,15 +1,16 @@
1
1
  ---
2
2
  name: ctx:init
3
- description: Initialize CTX project with STATE.md, PRD.json, and secure credentials
3
+ description: Initialize CTX project with STATE.md, PRD.json, design context, and secure credentials
4
4
  ---
5
5
 
6
6
  <objective>
7
- Initialize a new CTX 2.2 project. Front-loads ALL information gathering so execution runs autonomously with minimal interruption.
7
+ Initialize a new CTX 2.3 project. Front-loads ALL information gathering so execution runs autonomously with minimal interruption.
8
8
 
9
9
  Creates:
10
10
  - `.ctx/STATE.md` - Execution state
11
- - `.ctx/PRD.json` - Requirements contract
11
+ - `.ctx/PRD.json` - Requirements contract with design context
12
12
  - `.ctx/.env` - Secure credentials (gitignored)
13
+ - `BRAND_KIT.md` - Visual foundation (if design work needed)
13
14
  </objective>
14
15
 
15
16
  <philosophy>
@@ -21,10 +22,13 @@ Creates:
21
22
  3. Credentials for testing → .ctx/.env
22
23
  4. URLs and endpoints → .ctx/.env
23
24
  5. Constitution/rules → PRD.json constitution
25
+ 6. Design context → PRD.json brand/design sections
26
+ 7. Visual requirements → Brand personality, mood, inspirations
24
27
 
25
28
  **Then execute autonomously:**
26
29
  - Minimal user interruption during execution
27
30
  - Only ask user for architecture decisions (Rule 4)
31
+ - Only ask user for design approvals at gates
28
32
  - Use stored credentials for browser verification
29
33
  - Deliver complete, verified project
30
34
  </philosophy>
@@ -192,7 +196,57 @@ DATABASE_URL=
192
196
  - Warn user: "Credentials stored in .ctx/.env - NEVER commit this file"
193
197
  - Verify .gitignore is in place before proceeding
194
198
 
195
- ## Step 10: Link STATE.md to PRD
199
+ ## Step 10: Gather Design Context
200
+
201
+ **"Does this project need visual/UI work?"**
202
+
203
+ If yes, gather brand context:
204
+
205
+ **Brand Personality:**
206
+ - "What 3-5 adjectives describe the desired brand feel?"
207
+ - "Any brands you admire visually?" (inspirations)
208
+ - "Any visual styles to AVOID?" (anti-inspirations)
209
+
210
+ **Existing Assets:**
211
+ - "Do you have existing brand assets?" (logo, colors, fonts)
212
+ - "Figma file link?" (optional but recommended)
213
+
214
+ **Accessibility Requirements:**
215
+ - "Target market includes EU?" (EAA 2025 compliance)
216
+ - "WCAG level needed?" (default: 2.2 AA)
217
+
218
+ **Mode Support:**
219
+ - "Dark mode needed?" (light-only or light+dark)
220
+
221
+ Store in PRD.json `brand` section:
222
+ ```json
223
+ {
224
+ "brand": {
225
+ "hasBrandKit": false,
226
+ "personality": ["professional", "trustworthy", "modern"],
227
+ "visualMood": "Clean, minimal, with subtle warmth",
228
+ "inspirations": ["Stripe", "Linear"],
229
+ "antiInspirations": ["flashy", "cluttered"],
230
+ "existingAssets": ["logo.svg"],
231
+ "darkModeRequired": true,
232
+ "euMarket": true
233
+ },
234
+ "design": {
235
+ "wcagLevel": "AA",
236
+ "eaaCompliance": true,
237
+ "tokenFormat": "w3c",
238
+ "figmaFileKey": null,
239
+ "breakpoints": { "mobile": 375, "tablet": 768, "desktop": 1440 }
240
+ }
241
+ }
242
+ ```
243
+
244
+ **Story Type Assignment:**
245
+ - If no brand kit exists and UI work needed → Create brand story first (type: "brand")
246
+ - For each UI component/page → Create design story (type: "design")
247
+ - For backend/logic work → Create feature story (type: "feature")
248
+
249
+ ## Step 11: Link STATE.md to PRD
196
250
  Update STATE.md to reference current story:
197
251
  - **Current Story**: S001 - {{title}}
198
252
 
@@ -202,15 +256,15 @@ The user will run `/ctx` to begin the research + planning phase.
202
256
 
203
257
  <output_format>
204
258
  ```
205
- [CTX 2.2] Initialized
259
+ [CTX 2.3] Initialized
206
260
 
207
261
  Project: {{name}}
208
262
  Stack: {{language}} + {{framework}}
209
263
  Directory: .ctx/
210
264
 
211
265
  PRD: {{story_count}} stories
212
- S001: {{story_1_title}} ⬜
213
- S002: {{story_2_title}} ⬜
266
+ S001: [{{type}}] {{story_1_title}} ⬜
267
+ S002: [{{type}}] {{story_2_title}} ⬜
214
268
  ...
215
269
 
216
270
  Constitution:
@@ -218,6 +272,14 @@ Constitution:
218
272
  Always: {{count}}
219
273
  Never: {{count}}
220
274
 
275
+ Design Context:
276
+ Brand Kit: {{exists | needs creation}}
277
+ Personality: {{adjectives}}
278
+ WCAG Level: 2.2 {{level}}
279
+ EAA 2025: {{required | not required}}
280
+ Dark Mode: {{yes | no}}
281
+ Figma: {{linked | not linked}}
282
+
221
283
  Credentials:
222
284
  App URL: {{configured | not set}}
223
285
  Test User: {{configured | not set}}
@@ -228,6 +290,8 @@ Integrations:
228
290
  ArguSeek: ready
229
291
  ChunkHound: {{indexed | not found}}
230
292
  Browser Testing: {{ready | needs credentials}}
293
+ Figma MCP: {{ready | not configured}}
294
+ Gemini Design: {{ready | not configured}}
231
295
 
232
296
  Ready for autonomous execution.
233
297
  Next: Run /ctx to start planning for S001
@@ -241,6 +305,9 @@ Next: Run /ctx to start planning for S001
241
305
  - [ ] PRD.json created with user stories
242
306
  - [ ] Constitution defined (user or defaults)
243
307
  - [ ] All stories have acceptance criteria
308
+ - [ ] Stories assigned correct type (feature/brand/design)
309
+ - [ ] Design context gathered (if UI work needed)
310
+ - [ ] Brand story created first (if no BRAND_KIT.md)
244
311
  - [ ] .ctx/.env created with credentials (if provided)
245
312
  - [ ] ChunkHound index attempted
246
313
  - [ ] Status set to "initializing"
@@ -0,0 +1,169 @@
1
+ ---
2
+ name: ctx:map-codebase
3
+ description: Comprehensive codebase analysis using 4 parallel mapper agents. Run before starting a new project on existing code.
4
+ ---
5
+
6
+ <objective>
7
+ Analyze an existing codebase comprehensively using 4 specialized parallel agents.
8
+
9
+ This command is essential for "brownfield" projects where CTX is being added to existing code.
10
+ It produces documentation that informs all future planning and execution.
11
+ </objective>
12
+
13
+ <usage>
14
+ ```
15
+ /ctx map-codebase # Full analysis with all 4 mappers
16
+ /ctx map-codebase --tech # Only tech stack analysis
17
+ /ctx map-codebase --arch # Only architecture analysis
18
+ /ctx map-codebase --quality # Only quality analysis
19
+ /ctx map-codebase --concerns # Only concerns analysis
20
+ /ctx map-codebase --refresh # Force re-analysis (ignore cache)
21
+ ```
22
+ </usage>
23
+
24
+ <parallel_agents>
25
+
26
+ ## The 4 Mapper Agents
27
+
28
+ ```
29
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
30
+ │ TECH │ │ ARCH │ │ QUALITY │ │ CONCERNS │
31
+ │ MAPPER │ │ MAPPER │ │ MAPPER │ │ MAPPER │
32
+ │ │ │ │ │ │ │ │
33
+ │ Stack │ │ Patterns │ │ Test cov │ │ Security │
34
+ │ Frameworks │ │ Data flow │ │ Lint status │ │ Tech debt │
35
+ │ Dependencies│ │ Modules │ │ Type safety │ │ Performance │
36
+ │ Versions │ │ Entry pts │ │ Code smells │ │ Risks │
37
+ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
38
+ │ │ │ │
39
+ ▼ ▼ ▼ ▼
40
+ TECH.md ARCH.md QUALITY.md CONCERNS.md
41
+ │ │ │ │
42
+ └────────────────┴────────────────┴────────────────┘
43
+
44
+
45
+ SUMMARY.md
46
+ ```
47
+
48
+ All 4 agents run in PARALLEL for speed, then results are synthesized.
49
+
50
+ </parallel_agents>
51
+
52
+ <workflow>
53
+
54
+ ## Step 1: Check Prerequisites
55
+
56
+ - Ensure we're in a git repository (or at least a code directory)
57
+ - Check for existing analysis in `.ctx/codebase/`
58
+ - If exists and not `--refresh`: Show cached results
59
+
60
+ ## Step 2: Spawn Parallel Mappers
61
+
62
+ Spawn all 4 agents simultaneously using Task tool:
63
+
64
+ ```
65
+ Task(subagent_type="ctx-tech-mapper", prompt="Analyze tech stack...", run_in_background=true)
66
+ Task(subagent_type="ctx-arch-mapper", prompt="Analyze architecture...", run_in_background=true)
67
+ Task(subagent_type="ctx-quality-mapper", prompt="Analyze quality...", run_in_background=true)
68
+ Task(subagent_type="ctx-concerns-mapper", prompt="Analyze concerns...", run_in_background=true)
69
+ ```
70
+
71
+ ## Step 3: Wait for Completion
72
+
73
+ Use TaskOutput to wait for all 4 mappers:
74
+ - Each mapper writes its output to `.ctx/codebase/{TYPE}.md`
75
+ - Collect results as they complete
76
+ - Show progress to user
77
+
78
+ ## Step 4: Synthesize Results
79
+
80
+ After all mappers complete, create SUMMARY.md:
81
+ - Executive summary of findings
82
+ - Key metrics
83
+ - Recommendations for CTX workflow
84
+ - Suggested first phase
85
+
86
+ ## Step 5: Update State
87
+
88
+ - Create/update `.ctx/codebase/` directory
89
+ - Store analysis timestamp
90
+ - Link from STATE.md
91
+
92
+ </workflow>
93
+
94
+ <output_structure>
95
+
96
+ ```
97
+ .ctx/codebase/
98
+ ├── TECH.md # Tech stack analysis
99
+ ├── ARCH.md # Architecture analysis
100
+ ├── QUALITY.md # Quality metrics
101
+ ├── CONCERNS.md # Security, performance, tech debt
102
+ ├── SUMMARY.md # Executive summary
103
+ └── metadata.json # Analysis timestamp, versions
104
+ ```
105
+
106
+ </output_structure>
107
+
108
+ <output_format>
109
+ ```
110
+ [CTX] Codebase Analysis
111
+
112
+ Spawning 4 parallel mappers...
113
+ [■■■■■■■■■■] TECH ✓ 12s
114
+ [■■■■■■■■■■] ARCH ✓ 15s
115
+ [■■■■■■■■■■] QUALITY ✓ 18s
116
+ [■■■■■■■■■■] CONCERNS ✓ 14s
117
+
118
+ Synthesizing results...
119
+
120
+ ═══════════════════════════════════════════════════════
121
+ CODEBASE SUMMARY
122
+ ═══════════════════════════════════════════════════════
123
+
124
+ Tech Stack:
125
+ Language: TypeScript (92%), JavaScript (8%)
126
+ Framework: Next.js 14, React 18
127
+ Database: PostgreSQL + Prisma
128
+ Testing: Jest, Playwright
129
+
130
+ Architecture:
131
+ Pattern: Monolith with modular structure
132
+ Entry: src/app/page.tsx, src/server/index.ts
133
+ Modules: 12 feature modules
134
+ API Style: REST + Server Actions
135
+
136
+ Quality:
137
+ Test Coverage: 67%
138
+ Type Safety: Strong (strict mode)
139
+ Lint Status: 12 warnings, 0 errors
140
+ Code Smells: 3 files need attention
141
+
142
+ Concerns:
143
+ Security: 2 medium issues (see CONCERNS.md)
144
+ Performance: N+1 query in users module
145
+ Tech Debt: Auth module needs refactor
146
+
147
+ Recommendations:
148
+ 1. Address security issues before new features
149
+ 2. Improve test coverage to 80%
150
+ 3. Refactor auth module
151
+
152
+ Saved to: .ctx/codebase/
153
+
154
+ Next: Run /ctx init to start project with this context
155
+ ```
156
+ </output_format>
157
+
158
+ <when_to_use>
159
+ **Always run before:**
160
+ - Adding CTX to an existing codebase
161
+ - Starting major refactoring work
162
+ - Onboarding to unfamiliar codebase
163
+ - Security or quality audit
164
+
165
+ **Can skip when:**
166
+ - Greenfield project (no existing code)
167
+ - Small utility or script
168
+ - Analysis already done and code unchanged
169
+ </when_to_use>
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: ctx:map
3
+ description: Build or rebuild the repository map for intelligent code understanding
4
+ ---
5
+
6
+ <objective>
7
+ Build a token-optimized map of the codebase that enables all CTX agents to understand project structure, symbols, and dependencies.
8
+
9
+ This is the foundation for intelligent code operations.
10
+ </objective>
11
+
12
+ <usage>
13
+ ```
14
+ /ctx map # Build/rebuild repository map
15
+ /ctx map --expand # Generate expanded map (8k tokens)
16
+ /ctx map --stats # Show map statistics only
17
+ /ctx map --refresh # Force full rebuild (ignore cache)
18
+ ```
19
+ </usage>
20
+
21
+ <workflow>
22
+
23
+ ## Step 1: Check Existing Map
24
+
25
+ Read `.ctx/REPO-MAP.json` if exists:
26
+ - If fresh (< 1 hour old) and no git changes: Skip rebuild, show stats
27
+ - If stale or files changed: Incremental update
28
+ - If `--refresh` flag: Full rebuild
29
+
30
+ Check git for changes:
31
+ ```bash
32
+ git diff --name-only HEAD~10 2>/dev/null || echo "no-git"
33
+ ```
34
+
35
+ ## Step 2: Spawn Mapper Agent
36
+
37
+ Spawn `ctx-mapper` agent to build the map:
38
+ - Pass project root
39
+ - Pass token budget (2000 default, 8000 if --expand)
40
+ - Pass list of changed files (for incremental)
41
+
42
+ ## Step 3: Validate Output
43
+
44
+ Ensure mapper produced:
45
+ - `.ctx/REPO-MAP.json` - Valid JSON
46
+ - `.ctx/REPO-MAP.md` - Non-empty markdown
47
+ - `.ctx/repo-map-cache.json` - Cache file
48
+
49
+ ## Step 4: Report Results
50
+
51
+ </workflow>
52
+
53
+ <output_format>
54
+ ```
55
+ [CTX] Repository Map
56
+
57
+ Project: {{name}}
58
+ Stack: {{stack}}
59
+
60
+ Statistics:
61
+ Files: {{file_count}}
62
+ Symbols: {{symbol_count}}
63
+ Lines: {{line_count}}
64
+ Languages: {{language_breakdown}}
65
+
66
+ Entry Points:
67
+ {{entry_points}}
68
+
69
+ Top Referenced:
70
+ 1. {{symbol}} ({{refs}} refs)
71
+ 2. {{symbol}} ({{refs}} refs)
72
+ 3. {{symbol}} ({{refs}} refs)
73
+
74
+ Map Tokens: {{token_count}}/{{budget}}
75
+ Cache: {{cache_status}}
76
+
77
+ Saved to: .ctx/REPO-MAP.md
78
+ ```
79
+ </output_format>
80
+
81
+ <integration>
82
+ The repository map is automatically:
83
+ - Loaded by ctx-researcher before research
84
+ - Loaded by ctx-planner before planning
85
+ - Loaded by ctx-executor before execution
86
+ - Used to identify relevant files for any task
87
+ - Updated incrementally when files change
88
+ </integration>
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: ctx:profile
3
+ description: Switch between model profiles (quality/balanced/budget) for cost optimization
4
+ ---
5
+
6
+ <objective>
7
+ Switch between pre-configured model profiles to optimize for quality or cost.
8
+
9
+ Profiles control which models are used for each phase of the CTX workflow.
10
+ </objective>
11
+
12
+ <usage>
13
+ ```
14
+ /ctx profile # Show current profile
15
+ /ctx profile quality # Use best models (highest cost)
16
+ /ctx profile balanced # Use balanced models (default)
17
+ /ctx profile budget # Use fastest models (lowest cost)
18
+ ```
19
+ </usage>
20
+
21
+ <profiles>
22
+
23
+ ## Quality Profile
24
+ **Use when**: Critical production code, complex architecture, security-sensitive
25
+
26
+ | Phase | Model | Why |
27
+ |-------|-------|-----|
28
+ | Research | Opus | Deep understanding needed |
29
+ | Discussion | Opus | Nuanced question formulation |
30
+ | Planning | Opus | Best architectural decisions |
31
+ | Execution | Opus | Highest quality code |
32
+ | Debugging | Opus | Complex root cause analysis |
33
+ | Verification | Sonnet | Good enough for checks |
34
+ | Mapping | Sonnet | Reliable parsing |
35
+ | Quick | Sonnet | Still good quality |
36
+
37
+ **Estimated cost**: ~3x balanced profile
38
+
39
+ ## Balanced Profile (Default)
40
+ **Use when**: Most development work, good balance of speed and quality
41
+
42
+ | Phase | Model | Why |
43
+ |-------|-------|-----|
44
+ | Research | Opus | Worth investing in understanding |
45
+ | Discussion | Sonnet | Good enough for questions |
46
+ | Planning | Opus | Worth investing in architecture |
47
+ | Execution | Sonnet | Good code quality |
48
+ | Debugging | Sonnet | Reliable debugging |
49
+ | Verification | Haiku | Fast checks sufficient |
50
+ | Mapping | Haiku | Fast parsing |
51
+ | Quick | Haiku | Speed prioritized |
52
+
53
+ **Estimated cost**: Baseline
54
+
55
+ ## Budget Profile
56
+ **Use when**: Prototyping, learning, non-critical code, cost-sensitive
57
+
58
+ | Phase | Model | Why |
59
+ |-------|-------|-----|
60
+ | Research | Sonnet | Acceptable understanding |
61
+ | Discussion | Sonnet | Good enough |
62
+ | Planning | Sonnet | Acceptable plans |
63
+ | Execution | Sonnet | Decent code |
64
+ | Debugging | Sonnet | Usually works |
65
+ | Verification | Haiku | Fast is fine |
66
+ | Mapping | Haiku | Fast parsing |
67
+ | Quick | Haiku | Maximum speed |
68
+
69
+ **Estimated cost**: ~0.4x balanced profile (60% savings)
70
+
71
+ </profiles>
72
+
73
+ <workflow>
74
+
75
+ ## Step 1: Read Current Config
76
+
77
+ Read `.ctx/config.json`:
78
+ - If doesn't exist: Copy from template, set balanced as default
79
+ - Get current `activeProfile`
80
+
81
+ ## Step 2: Handle Command
82
+
83
+ If no argument:
84
+ - Show current profile and routing table
85
+
86
+ If profile name provided:
87
+ - Validate: must be `quality`, `balanced`, or `budget`
88
+ - Update `activeProfile` in config.json
89
+ - Show new routing table
90
+
91
+ ## Step 3: Update Config
92
+
93
+ Write updated config to `.ctx/config.json`
94
+
95
+ </workflow>
96
+
97
+ <output_format>
98
+ ```
99
+ [CTX] Model Profile: {{profile}}
100
+
101
+ Current Routing:
102
+ Research: {{model}} ({{costTier}})
103
+ Discussion: {{model}} ({{costTier}})
104
+ Planning: {{model}} ({{costTier}})
105
+ Execution: {{model}} ({{costTier}})
106
+ Debugging: {{model}} ({{costTier}})
107
+ Verification: {{model}} ({{costTier}})
108
+ Mapping: {{model}} ({{costTier}})
109
+ Quick: {{model}} ({{costTier}})
110
+
111
+ Estimated Cost: {{multiplier}}x baseline
112
+
113
+ Saved to: .ctx/config.json
114
+ ```
115
+ </output_format>
116
+
117
+ <integration>
118
+ All CTX agents check config.json before spawning subagents:
119
+ 1. Determine task type (research, planning, etc.)
120
+ 2. Look up routing table for model
121
+ 3. Use Task tool with `model` parameter
122
+
123
+ Example:
124
+ ```
125
+ Task(
126
+ prompt: "Research authentication patterns",
127
+ subagent_type: "ctx-researcher",
128
+ model: "opus" // from config routing
129
+ )
130
+ ```
131
+ </integration>