ctx-cc 3.3.8 → 3.4.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/ctx.md CHANGED
@@ -1,525 +1,667 @@
1
1
  ---
2
2
  name: ctx
3
- description: Smart router - understands natural language, detects intent, and guides users from first prompt. No commands to memorize.
3
+ description: Smart router - understands natural language, detects intent, and routes to the right workflow. No commands to memorize.
4
+ allowed-tools:
5
+ - Read
6
+ - Write
7
+ - Bash
8
+ - Glob
9
+ - Grep
10
+ - Task
11
+ - AskUserQuestion
12
+ - mcp__arguseek__research_iteratively
13
+ - mcp__arguseek__fetch_url
4
14
  ---
5
15
 
6
16
  <objective>
7
17
  CTX Smart Router - Conversational-first workflow orchestration.
8
18
 
9
- **Users don't need to know commands.** They just describe what they want, and CTX routes to the right workflow automatically.
19
+ **Users don't need to know commands.** They describe what they want, CTX routes automatically.
10
20
 
11
21
  ```
12
22
  User: "I want to build a todo app" → Routes to init
13
23
  User: "Fix the login bug" → Routes to debug
14
24
  User: "Is my app accessible?" → Routes to QA
15
- User: "What should I do next?" → Shows status + recommendation
25
+ User: "What should I do next?" → Shows status + routes to next action
16
26
  ```
17
27
  </objective>
18
28
 
19
- <workflow>
20
-
21
- ## Step 0: Intent Detection (ALWAYS RUNS FIRST)
22
-
23
- Before checking state, parse the user's natural language request.
29
+ <process>
24
30
 
25
- ### Intent Patterns
31
+ ## Step 0: Verify CTX Structure
26
32
 
27
- | User Says | Detected Intent | Route To |
28
- |-----------|-----------------|----------|
29
- | "build", "create", "make", "start new", "I want to..." | `new-project` | /ctx:init |
30
- | "fix", "bug", "broken", "not working", "error" | `debug` | /ctx:debug |
31
- | "test", "QA", "check", "accessible", "works?" | `qa` | /ctx:qa |
32
- | "review", "audit", "security", "ready?" | `review` | /ctx:verify |
33
- | "production", "prod ready", "production ready" | `production-ready` | Full audit → QA → fixes |
34
- | "study", "analyze", "understand", "learn", "explore" | `analyze` | /ctx:map-codebase |
35
- | "improve", "optimize", "better", "enhance" | `improve` | Analyze → suggest → fix |
36
- | "deploy", "ship", "publish", "release" | `ship` | /ctx:verify → ship |
37
- | "status", "progress", "where", "what's next" | `status` | /ctx:status |
38
- | "help", "how", "what can", "commands" | `help` | /ctx:help |
39
- | "plan", "design", "architect" | `plan` | /ctx:plan |
40
- | "continue", "next", "go", "do it" | `continue` | (read STATE.md) |
33
+ **MANDATORY FIRST STEP Execute before anything else:**
41
34
 
42
- ### Intent Detection Logic
35
+ ```bash
36
+ test -d .ctx && echo "exists" || echo "missing"
37
+ ```
43
38
 
44
- ```javascript
45
- function detectIntent(userMessage) {
46
- const msg = userMessage.toLowerCase();
39
+ Store result for routing decisions below.
47
40
 
48
- // New project signals
49
- if (msg.match(/\b(build|create|make|start|new|want to)\b.*\b(app|project|feature|site|api)\b/)) {
50
- return 'new-project';
51
- }
41
+ ## Step 1: Intent Detection
52
42
 
53
- // Debug signals
54
- if (msg.match(/\b(fix|bug|broken|error|crash|not working|fails?|issue)\b/)) {
55
- return 'debug';
56
- }
43
+ Parse the user's message to detect intent. This runs BEFORE checking state.
57
44
 
58
- // QA signals
59
- if (msg.match(/\b(test|qa|check|accessible|works|validate|verify all)\b/)) {
60
- return 'qa';
61
- }
45
+ **Detection rules (check in order):**
62
46
 
63
- // Production-ready signals
64
- if (msg.match(/\b(production|prod ready|production.?ready|make it ready)\b/)) {
65
- return 'production-ready';
66
- }
47
+ | Pattern | Intent | Route |
48
+ |---------|--------|-------|
49
+ | "build", "create", "make", "start new", "I want to..." + "app/project/feature" | `new-project` | /ctx:init |
50
+ | "fix", "bug", "broken", "not working", "error", "crash", "fails" | `debug` | Debug flow |
51
+ | "test", "QA", "check", "accessible", "works?", "validate" | `qa` | QA flow |
52
+ | "production", "prod ready", "production ready", "make it ready" | `production-ready` | Full audit pipeline |
53
+ | "study", "analyze", "understand", "learn", "explore", "what is this" | `analyze` | Map codebase |
54
+ | "improve", "optimize", "better", "enhance", "upgrade", "refactor" | `improve` | Analyze + suggest |
55
+ | "review", "audit", "security", "ready", "before deploy" | `review` | Verify flow |
56
+ | "deploy", "ship", "publish", "release", "push", "launch" | `ship` | Ship flow |
57
+ | "status", "progress", "where", "what's next", "current" | `status` | Status report |
58
+ | "help", "how", "what can", "commands", "guide" | `help` | Help guide |
59
+ | "continue", "next", "go", "do it" | `continue` | Read STATE.md |
67
60
 
68
- // Analyze/study signals
69
- if (msg.match(/\b(study|analyze|understand|learn|explore|what is this)\b/)) {
70
- return 'analyze';
71
- }
61
+ State detected intent for routing.
72
62
 
73
- // Improve signals
74
- if (msg.match(/\b(improve|optimize|better|enhance|upgrade|refactor)\b/)) {
75
- return 'improve';
76
- }
63
+ ## Step 2: Route Based on CTX Existence + Intent
77
64
 
78
- // Review signals
79
- if (msg.match(/\b(review|audit|security|ready|before deploy)\b/)) {
80
- return 'review';
81
- }
65
+ **If NO .ctx/ folder (new user):**
82
66
 
83
- // Ship signals
84
- if (msg.match(/\b(deploy|ship|publish|release|push|launch)\b/)) {
85
- return 'ship';
86
- }
67
+ Route by intent:
87
68
 
88
- // Status signals
89
- if (msg.match(/\b(status|progress|where|what.?s next|current)\b/)) {
90
- return 'status';
91
- }
69
+ ### Route A: New Project Intent
92
70
 
93
- // Help signals
94
- if (msg.match(/\b(help|how|what can|commands|guide)\b/)) {
95
- return 'help';
96
- }
71
+ If intent = `new-project`:
97
72
 
98
- // Continue signals (or no clear intent)
99
- return 'continue';
100
- }
101
73
  ```
74
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
75
+ Welcome to CTX!
76
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
77
+
78
+ I understood: "{{user_request}}"
79
+
80
+ You want to build something new. Let's set it up!
81
+
82
+ Starting project initialization...
83
+ ```
84
+
85
+ Then execute /ctx:init inline (don't tell user to run it separately).
86
+
87
+ ### Route B: Debug/Fix Intent (no .ctx/)
102
88
 
103
- ## Step 1: Check Project State
89
+ If intent = `debug`:
104
90
 
105
- Check if `.ctx/` folder exists:
91
+ ```
92
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
93
+ Welcome to CTX!
94
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
106
95
 
107
- ### If NO `.ctx/` folder (New User)
96
+ I understood: "{{problem_description}}"
108
97
 
109
- Based on detected intent:
98
+ You need to fix something. Let me understand the codebase first.
99
+ ```
110
100
 
111
- | Intent | Action |
112
- |--------|--------|
113
- | `new-project` | "Let's set up your project!" → Run /ctx:init flow |
114
- | `debug` | "Let me understand the codebase first." → Run /ctx:map → /ctx:debug |
115
- | `qa` | "I'll analyze the project first." → Run /ctx:map → /ctx:qa |
116
- | `production-ready` | "I'll audit everything and make it production ready." → Full pipeline below |
117
- | `analyze` | "Let me study this codebase." → Run /ctx:map-codebase |
118
- | `improve` | "I'll analyze and suggest improvements." → Run /ctx:map → analyze → suggest |
119
- | `continue` | Guide user: "What would you like to do with this project?" |
120
- | `help` | Show quick start guide |
101
+ **Step 1: Map codebase (parallel agents)**
121
102
 
122
- ### Production-Ready Pipeline
103
+ Spawn 4 mapper agents in parallel:
123
104
 
124
- When user says "make it production ready":
105
+ ```bash
106
+ mkdir -p .ctx/codebase
107
+ ```
125
108
 
126
109
  ```
127
- 1. /ctx:map-codebase → Deep analysis (4 parallel agents)
128
- 2. /ctx:qa → Full system QA (WCAG 2.1 AA)
129
- 3. Security audit → Check for vulnerabilities
130
- 4. Performance check → Find slow requests, large assets
131
- 5. Create fix tasks → Prioritized by severity
132
- 6. Execute fixes → With verification loop
133
- 7. Final verification → Three-level check
134
- 8. Report → Production readiness score
110
+ Task(prompt="Analyze codebase technology stack. Write findings to .ctx/codebase/TECH.md", subagent_type="ctx-tech-mapper", model="haiku", description="Map tech stack")
111
+ Task(prompt="Analyze codebase architecture. Write findings to .ctx/codebase/ARCH.md", subagent_type="ctx-arch-mapper", model="haiku", description="Map architecture")
112
+ Task(prompt="Analyze code quality patterns. Write findings to .ctx/codebase/QUALITY.md", subagent_type="ctx-quality-mapper", model="haiku", description="Map quality")
113
+ Task(prompt="Identify concerns and tech debt. Write findings to .ctx/codebase/CONCERNS.md", subagent_type="ctx-concerns-mapper", model="haiku", description="Map concerns")
135
114
  ```
136
115
 
137
- Output:
116
+ **Step 2: Initialize minimal state**
117
+
118
+ ```bash
119
+ cat > .ctx/STATE.md << 'EOF'
120
+ # CTX State
121
+
122
+ ## Status
123
+ debugging
124
+
125
+ ## Current Focus
126
+ {{problem_description}}
127
+
128
+ ## Context Budget
129
+ 5%
130
+ EOF
131
+ ```
132
+
133
+ **Step 3: Route to debug**
134
+
135
+ Go to **Debug Flow** below.
136
+
137
+ ### Route C: QA Intent (no .ctx/)
138
+
139
+ If intent = `qa`:
140
+
138
141
  ```
139
142
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
140
- PRODUCTION READINESS AUDIT
143
+ Welcome to CTX!
141
144
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
142
145
 
143
- Codebase Analysis: ✓ Complete
144
- ├── Tech: React 18, Node.js, PostgreSQL
145
- ├── Architecture: Clean, well-structured
146
- ├── Quality: 78% test coverage
147
- └── Concerns: 3 security issues, 5 performance issues
146
+ I understood: "{{qa_request}}"
148
147
 
149
- Full QA: Complete
150
- ├── Pages tested: 24
151
- ├── WCAG 2.1 AA: 92% compliant
152
- ├── Issues found: 12
153
- └── Critical: 2
148
+ You want to test the system. I'll analyze the project first.
149
+ ```
154
150
 
155
- Security Audit: Issues Found
156
- ├── SQL injection risk: 1
157
- ├── XSS vulnerability: 1
158
- └── Exposed secrets: 1
151
+ Map codebase (same as Route B Step 1), then go to **QA Flow** below.
159
152
 
160
- Performance: Issues Found
161
- ├── Slow API calls: 3
162
- ├── Large assets: 2
163
- └── Missing caching: Yes
153
+ ### Route D: Production-Ready Intent (no .ctx/)
164
154
 
165
- Fix Tasks Created: 8
166
- ├── Critical: 3 (security)
167
- ├── High: 5 (performance, a11y)
168
- └── Medium: 4
155
+ If intent = `production-ready`:
169
156
 
170
- Ready to fix? [Y] Fix all [C] Critical only [R] Review first
171
157
  ```
158
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
159
+ Welcome to CTX!
160
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
161
+
162
+ I understood: "{{request}}"
172
163
 
173
- **Output for new users:**
164
+ I'll audit everything and make it production ready.
174
165
  ```
175
- [CTX] Welcome! I see this is a new project.
176
166
 
177
- Based on your request, I'll help you {{detected_action}}.
167
+ Go to **Production-Ready Pipeline** below.
168
+
169
+ ### Route E: Analyze Intent (no .ctx/)
170
+
171
+ If intent = `analyze`:
178
172
 
179
- {{guided_next_step}}
180
173
  ```
174
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
175
+ Welcome to CTX!
176
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
181
177
 
182
- ### If `.ctx/` folder EXISTS
178
+ I understood: "{{request}}"
183
179
 
184
- Load configuration and state:
185
- - Read `.ctx/config.json` for profile settings
186
- - Read `.ctx/STATE.md` for current status
187
- - Check `.ctx/REPO-MAP.md` for codebase understanding
180
+ Let me study this codebase.
181
+ ```
188
182
 
189
- ## Step 2: Route Based on Intent + State
183
+ Go to **Map Codebase Flow** below.
190
184
 
191
- Combine detected intent with current state:
185
+ ### Route F: Help or Unknown Intent (no .ctx/)
186
+
187
+ ```
188
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
189
+ Welcome to CTX!
190
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
191
+
192
+ What would you like to do?
193
+
194
+ "Build something new" → I'll set up your project
195
+ "Fix a bug" → I'll debug the issue
196
+ "Test the app" → I'll run full QA
197
+ "Study the codebase" → I'll analyze the architecture
198
+
199
+ Just describe what you want!
200
+ ```
201
+
202
+ ---
203
+
204
+ **If .ctx/ folder EXISTS:**
205
+
206
+ ### Step 2.1: Load State
207
+
208
+ Read current state:
209
+
210
+ ```bash
211
+ cat .ctx/STATE.md
212
+ cat .ctx/config.json 2>/dev/null || echo "{}"
213
+ ```
214
+
215
+ Extract:
216
+ - `status`: Current workflow status
217
+ - `currentStory`: Active story ID
218
+ - `profile`: Model profile (quality/balanced/budget)
219
+
220
+ ### Step 2.2: Route by Intent + State
192
221
 
193
222
  | Intent | State | Action |
194
223
  |--------|-------|--------|
195
- | `new-project` | any | Warn if project exists, offer to add story |
196
- | `debug` | any | Route to /ctx:debug |
197
- | `qa` | any | Route to /ctx:qa |
198
- | `production-ready` | any | Run full production-ready pipeline |
199
- | `analyze` | any | Route to /ctx:map-codebase |
200
- | `improve` | any | Analyze → suggest improvements → create stories |
201
- | `status` | any | Show STATE.md summary |
202
- | `continue` | initializing | Run research phase |
203
- | `continue` | discussing | Run discussion phase |
224
+ | `new-project` | any | Warn project exists, offer to add story |
225
+ | `debug` | any | Go to Debug Flow |
226
+ | `qa` | any | Go to QA Flow |
227
+ | `production-ready` | any | Go to Production-Ready Pipeline |
228
+ | `analyze` | any | Go to Map Codebase Flow |
229
+ | `improve` | any | Analyze → suggest improvements |
230
+ | `status` | any | Show status report |
231
+ | `continue` | initializing | Research phase |
232
+ | `continue` | discussing | Discussion phase |
204
233
  | `continue` | executing | Execute current task |
205
- | `continue` | debugging | Resume debug session |
234
+ | `continue` | debugging | Resume debug |
206
235
  | `continue` | verifying | Run verification |
207
236
  | `continue` | paused | Resume from checkpoint |
208
237
 
209
- ## Step 3: Load Configuration
210
-
211
- Read `.ctx/config.json` for:
212
- - Active profile (quality/balanced/budget)
213
- - Model routing table
214
- - Git settings (autoCommit, commitPerTask)
215
- - Integration settings
216
-
217
- If config.json doesn't exist:
218
- - Copy from templates/config.json
219
- - Set balanced as default profile
220
-
221
- ## Step 4: Execute Routed Action
222
-
223
- Based on routing decision from Step 2:
224
-
225
- ### If status = "initializing"
226
- Route to: **Research Phase**
227
- 1. Check if REPO-MAP exists, if not run ctx-mapper
228
- 2. Use ArguSeek to research the project goal
229
- 3. Create atomic plan (2-3 tasks max)
230
- 4. Update STATE.md with plan
231
- 5. Set status = "discussing"
232
-
233
- ### If status = "discussing"
234
- Route to: **Discussion Phase**
235
- 1. Spawn ctx-discusser agent
236
- 2. Ask targeted questions about gray areas
237
- 3. Lock decisions in CONTEXT.md
238
- 4. Set status = "executing"
239
-
240
- ### If status = "executing"
241
- Route to: **Execute Current Task**
242
- 1. Read current task from STATE.md
243
- 2. Load REPO-MAP for context
244
- 3. Spawn ctx-executor agent (uses git-native workflow)
245
- 4. Execute task with deviation handling:
246
- - Auto-fix: bugs, validation, deps (95%)
247
- - Ask user: architecture decisions only (5%)
248
- 5. After task:
249
- - Run verification (build, tests, lint)
250
- - Auto-commit if config allows
251
- - If passes: mark done, update STATE.md
252
- - If fails: set status = "debugging"
253
-
254
- ### If status = "debugging"
255
- Route to: **Persistent Debug Loop**
256
- 1. Spawn ctx-debugger agent
257
- 2. Check for existing debug session (resume if exists)
258
- 3. Loop until fixed (max 10 attempts):
259
- - Analyze error
260
- - Form hypothesis
261
- - Apply fix
262
- - Verify (build + tests + browser if UI)
263
- - Record in persistent state
264
- - Take screenshot proof if browser test
265
- 4. If fixed: set status = "executing", continue
266
- 5. If max attempts: escalate with full report
267
-
268
- ### If status = "verifying"
269
- Route to: **Three-Level Verification**
270
- 1. Spawn ctx-verifier agent
271
- 2. Check all artifacts:
272
- - Level 1: Exists (file on disk?)
273
- - Level 2: Substantive (real code, not stub?)
274
- - Level 3: Wired (imported and used?)
275
- 3. Scan for anti-patterns (TODO, empty catch, placeholders)
276
- 4. Browser verification (if UI)
277
- 5. **DELIVERY GUARANTEE:**
278
- - If ALL pass: complete phase → COMPLETE
279
- - If ANY fail: set status = "debugging" → fix → verify again
280
- - Loop until 100% working or max attempts
281
- - NEVER mark complete with failures
282
-
283
- ### If status = "paused"
284
- Route to: **Resume**
285
- 1. Read checkpoint from `.ctx/checkpoints/`
286
- 2. Restore context (~2.5k tokens)
287
- 3. Set status to previous state
288
- 4. Continue workflow
289
-
290
- ## Step 5: Model Selection
291
-
292
- Based on current action and active profile:
293
-
294
- | Action | quality | balanced | budget |
295
- |--------|---------|----------|--------|
296
- | Research | opus | opus | sonnet |
297
- | Discussion | opus | sonnet | sonnet |
298
- | Planning | opus | opus | sonnet |
299
- | Execution | opus | sonnet | sonnet |
300
- | Debugging | opus | sonnet | sonnet |
301
- | Verification | sonnet | haiku | haiku |
302
- | Mapping | sonnet | haiku | haiku |
303
-
304
- Use Task tool with `model` parameter from routing table.
305
-
306
- ## Step 6: Context Budget Check
307
-
308
- After every action:
309
- - Calculate context usage
310
- - If > 40%: Prepare handoff notes
311
- - If > 50%: Auto-checkpoint, warn user
312
- - If > 60%: Create HANDOFF.md, spawn fresh agent
313
- - If > 70%: Force checkpoint
314
-
315
- ## Step 7: Git-Native Commit
316
-
317
- If task completed successfully AND config.git.autoCommit = true:
318
- 1. Stage modified files
319
- 2. Create commit with CTX format
320
- 3. Record commit hash in STATE.md
321
-
322
- ## Step 8: Update State
323
-
324
- Always update STATE.md after any action:
325
- - Current status
326
- - Progress
327
- - Recent commits
328
- - Recent decisions
329
- - Next action
330
- - Context usage
331
- </workflow>
238
+ </process>
332
239
 
333
- <state_transitions>
334
- ```
335
- initializing discussing (after research)
336
- discussing → executing (after decisions locked)
337
- executing debugging (if verification fails)
338
- executing → verifying (if all tasks done)
339
- debugging → executing (if fix works)
340
- debugging → ESCALATE (if max attempts fail)
341
- verifying → debugging (if any check fails) ← LOOP BACK
342
- verifying → COMPLETE (if ALL pass 100%) ← ONLY EXIT
343
- paused → (previous state)
240
+ <flows>
241
+
242
+ ## Debug Flow
243
+
244
+ **Step 1: Research the problem with ArguSeek**
344
245
 
345
- DELIVERY GUARANTEE LOOP:
346
- verifying ←→ debugging ←→ executing
347
-
348
- COMPLETE (only when 100% verified)
349
246
  ```
350
- </state_transitions>
247
+ mcp__arguseek__research_iteratively({
248
+ query: "{{problem_description}} {{tech_stack}} common causes solutions"
249
+ })
250
+ ```
351
251
 
352
- <new_commands>
353
- ## New in CTX 3.0
252
+ Store findings in memory.
354
253
 
355
- | Command | Purpose |
356
- |---------|---------|
357
- | `/ctx map` | Build repository map (REPO-MAP.md) |
358
- | `/ctx map-codebase` | Deep codebase analysis (4 parallel agents) |
359
- | `/ctx discuss [story]` | Run discussion phase for story |
360
- | `/ctx profile [name]` | Switch model profile |
361
- | `/ctx debug --resume` | Resume previous debug session |
362
- </new_commands>
254
+ **Step 2: Spawn debugger agent**
363
255
 
364
- <context_budget>
365
- | Usage | Quality | Action |
366
- |-------|---------|--------|
367
- | 0-30% | Peak | Continue |
368
- | 30-40% | Good | Continue |
369
- | 40-50% | Good | Prepare handoff |
370
- | 50-60% | Degrading | Auto-checkpoint |
371
- | 60-70% | Degrading | Create HANDOFF.md |
372
- | 70%+ | Poor | Force checkpoint |
373
- </context_budget>
256
+ ```
257
+ Task(prompt="
258
+ <problem>
259
+ {{problem_description}}
260
+ </problem>
261
+
262
+ <codebase_context>
263
+ {{.ctx/codebase/TECH.md content}}
264
+ {{.ctx/codebase/ARCH.md content}}
265
+ </codebase_context>
266
+
267
+ <research_findings>
268
+ {{ArguSeek results}}
269
+ </research_findings>
270
+
271
+ <instructions>
272
+ 1. Analyze the error
273
+ 2. Form hypothesis
274
+ 3. Apply minimal fix
275
+ 4. Verify (build + tests)
276
+ 5. If fixed: update STATE.md status to 'executing', commit fix
277
+ 6. If not fixed: log attempt, try next hypothesis (max 10 attempts)
278
+ </instructions>
279
+
280
+ Write debug progress to .ctx/DEBUG.md
281
+ ", subagent_type="ctx-debugger", model="sonnet", description="Debug {{problem}}")
282
+ ```
283
+
284
+ **Step 3: Update state and report**
374
285
 
375
- <output_format>
286
+ Read debugger output. Update STATE.md:
287
+
288
+ ```bash
289
+ # Update status based on outcome
290
+ ```
376
291
 
377
- ## For New Users (no .ctx/ folder)
292
+ **Step 4: Show next steps**
378
293
 
379
294
  ```
380
295
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
381
- Welcome to CTX!
296
+ [CTX] Debug Complete
382
297
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
383
298
 
384
- I understood: "{{user_request}}"
299
+ Status: {{fixed | still investigating}}
300
+ Attempts: {{count}}
301
+ Commit: {{hash if fixed}}
385
302
 
386
- {{intent_response}}
303
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
304
+ To continue with CTX, run: /ctx
305
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
306
+ ```
307
+
308
+ ---
387
309
 
388
- {{guided_action}}
310
+ ## QA Flow
311
+
312
+ **Step 1: Research QA best practices**
313
+
314
+ ```
315
+ mcp__arguseek__research_iteratively({
316
+ query: "{{tech_stack}} E2E testing WCAG 2.1 AA accessibility best practices 2025"
317
+ })
389
318
  ```
390
319
 
391
- **Intent Responses:**
320
+ **Step 2: Spawn QA agent**
392
321
 
393
- | Intent | Response |
394
- |--------|----------|
395
- | new-project | "You want to build something new. Let's set it up!" |
396
- | debug | "You need to fix something. Let me understand the codebase first." |
397
- | qa | "You want to test the system. I'll analyze the project first." |
398
- | status | "This is a new project. Would you like to start building?" |
399
- | help | (Show quick start guide) |
322
+ ```
323
+ Task(prompt="
324
+ <codebase_context>
325
+ {{.ctx/codebase/TECH.md content}}
326
+ </codebase_context>
327
+
328
+ <qa_focus>
329
+ {{qa_request or 'full system QA'}}
330
+ </qa_focus>
331
+
332
+ <research>
333
+ {{ArguSeek results}}
334
+ </research>
335
+
336
+ <instructions>
337
+ 1. Use Playwright for browser testing
338
+ 2. Use stable locators (getByRole, getByText, getByLabel)
339
+ 3. Test WCAG 2.1 AA: touch targets 44x44, alt text, form labels, contrast
340
+ 4. Test at 3 viewports: mobile (375px), tablet (768px), desktop (1280px)
341
+ 5. Capture screenshots of issues
342
+ 6. Write QA report to .ctx/QA-REPORT.md
343
+ </instructions>
344
+ ", subagent_type="ctx-qa", model="sonnet", description="QA testing")
345
+ ```
400
346
 
401
- ## For Existing Projects
347
+ **Step 3: Report results**
402
348
 
403
349
  ```
404
- [CTX] Status: {{status}}
405
- [CTX] Profile: {{profile}} ({{costTier}})
406
- [CTX] Action: {{action_taken}}
407
- [CTX] Commit: {{commit_hash}} (if auto-committed)
408
- [CTX] Next: {{next_action}}
409
- [CTX] Context: {{percent}}% ({{quality}})
350
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
351
+ [CTX] QA Complete
352
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
353
+
354
+ Pages tested: {{count}}
355
+ WCAG 2.1 AA: {{score}}%
356
+ Issues found: {{count}}
357
+ Critical: {{count}}
358
+ High: {{count}}
359
+ Medium: {{count}}
360
+
361
+ Report: .ctx/QA-REPORT.md
410
362
 
411
363
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
412
364
  To continue with CTX, run: /ctx
413
365
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
414
366
  ```
415
367
 
416
- ## CRITICAL: Continuation Reminder
368
+ ---
369
+
370
+ ## Production-Ready Pipeline
417
371
 
418
- **ALWAYS end every CTX response with this footer:**
372
+ Full audit for production readiness:
419
373
 
374
+ **Step 1: Map codebase (if not already mapped)**
375
+
376
+ ```bash
377
+ test -d .ctx/codebase && echo "mapped" || echo "needs_mapping"
420
378
  ```
421
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
422
- To continue with CTX, run: /ctx
423
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
379
+
380
+ If needs mapping, spawn 4 mapper agents (see Route B above).
381
+
382
+ **Step 2: Research production requirements**
383
+
384
+ ```
385
+ mcp__arguseek__research_iteratively({
386
+ query: "{{tech_stack}} production readiness checklist security performance 2025"
387
+ })
424
388
  ```
425
389
 
426
- This is essential because CTX commands only run for one turn. Without this reminder, users will continue chatting without CTX tracking their work.
390
+ **Step 3: Run full QA**
427
391
 
428
- ## Guided Prompts (When Intent Unclear)
392
+ Spawn ctx-qa agent (see QA Flow above).
429
393
 
430
- If user's intent is ambiguous, ask:
394
+ **Step 4: Security audit**
431
395
 
432
396
  ```
433
- I'm not sure what you'd like to do. Here are your options:
397
+ Task(prompt="
398
+ <codebase>
399
+ {{.ctx/codebase/TECH.md}}
400
+ {{.ctx/codebase/CONCERNS.md}}
401
+ </codebase>
402
+
403
+ <instructions>
404
+ Audit for:
405
+ - SQL injection
406
+ - XSS vulnerabilities
407
+ - Exposed secrets
408
+ - Auth/authz gaps
409
+ - Input validation
410
+
411
+ Write report to .ctx/SECURITY-AUDIT.md
412
+ </instructions>
413
+ ", subagent_type="ctx-auditor", model="sonnet", description="Security audit")
414
+ ```
434
415
 
435
- "Build something new" → I'll help you start a project
436
- "Fix a bug" → I'll debug the issue
437
- "Test the app" → I'll run full QA
438
- "Show status" → I'll show current progress
416
+ **Step 5: Performance check**
439
417
 
440
- What would you like to do?
441
418
  ```
442
- </output_format>
419
+ Task(prompt="
420
+ <codebase>
421
+ {{.ctx/codebase/TECH.md}}
422
+ {{.ctx/codebase/ARCH.md}}
423
+ </codebase>
424
+
425
+ <instructions>
426
+ Check for:
427
+ - Slow API calls (>500ms)
428
+ - Large assets (>500KB)
429
+ - Missing caching
430
+ - N+1 queries
431
+ - Memory leaks
432
+
433
+ Write report to .ctx/PERF-AUDIT.md
434
+ </instructions>
435
+ ", subagent_type="ctx-reviewer", model="sonnet", description="Performance check")
436
+ ```
443
437
 
444
- <examples>
438
+ **Step 6: Create fix tasks**
445
439
 
446
- ## Example Conversations
440
+ Read all reports, create prioritized fix list in .ctx/FIX-TASKS.md
447
441
 
448
- ### New User - Build Intent
442
+ **Step 7: Execute fixes**
443
+
444
+ For each critical/high fix:
445
+
446
+ ```
447
+ Task(prompt="
448
+ <fix>
449
+ {{fix_description}}
450
+ </fix>
451
+
452
+ <context>
453
+ {{relevant_code}}
454
+ </context>
455
+
456
+ <instructions>
457
+ 1. Apply minimal fix
458
+ 2. Verify (build + tests)
459
+ 3. Commit with descriptive message
460
+ </instructions>
461
+ ", subagent_type="ctx-executor", model="sonnet", description="Fix: {{fix_name}}")
449
462
  ```
450
- User: "I want to build a todo app with React"
451
463
 
452
- CTX: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
453
- Welcome to CTX!
454
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
464
+ **Step 8: Final verification**
465
+
466
+ Spawn ctx-verifier for three-level check.
467
+
468
+ **Step 9: Report**
455
469
 
456
- I understood: "build a todo app with React"
470
+ ```
471
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
472
+ PRODUCTION READINESS AUDIT
473
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
474
+
475
+ Codebase Analysis: ✓ Complete
476
+ Full QA: ✓ Complete (WCAG {{score}}%)
477
+ Security Audit: {{status}}
478
+ Performance: {{status}}
479
+
480
+ Issues Fixed: {{count}}
481
+ Remaining: {{count}}
482
+
483
+ Production Ready: {{YES | NO - reasons}}
484
+
485
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
486
+ To continue with CTX, run: /ctx
487
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
488
+ ```
457
489
 
458
- You want to build something new. Let's set it up!
490
+ ---
459
491
 
460
- I'll now:
461
- 1. Create your project structure
462
- 2. Research best practices for React todo apps
463
- 3. Create a plan with clear milestones
492
+ ## Map Codebase Flow
464
493
 
465
- [Starting project setup...]
494
+ **Step 1: Create structure**
466
495
 
467
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
468
- To continue with CTX, run: /ctx
469
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
496
+ ```bash
497
+ mkdir -p .ctx/codebase
470
498
  ```
471
499
 
472
- ### New User - Fix Intent
500
+ **Step 2: Spawn 4 mapper agents in parallel**
501
+
502
+ ```
503
+ Task(prompt="
504
+ Analyze the technology stack of this codebase.
505
+
506
+ Look for:
507
+ - package.json, Cargo.toml, go.mod, requirements.txt, etc.
508
+ - Framework detection (React, Next.js, FastAPI, etc.)
509
+ - Key dependencies and versions
510
+ - Build tools and scripts
511
+
512
+ Write comprehensive analysis to: .ctx/codebase/TECH.md
513
+ ", subagent_type="ctx-tech-mapper", model="haiku", description="Map tech stack")
514
+
515
+ Task(prompt="
516
+ Analyze the architecture of this codebase.
517
+
518
+ Look for:
519
+ - Directory structure
520
+ - Entry points
521
+ - Component boundaries
522
+ - Data flow patterns
523
+ - API structure
524
+
525
+ Write comprehensive analysis to: .ctx/codebase/ARCH.md
526
+ ", subagent_type="ctx-arch-mapper", model="haiku", description="Map architecture")
527
+
528
+ Task(prompt="
529
+ Analyze code quality patterns.
530
+
531
+ Look for:
532
+ - Testing patterns and coverage
533
+ - Error handling patterns
534
+ - Logging patterns
535
+ - Code style consistency
536
+ - Documentation quality
537
+
538
+ Write comprehensive analysis to: .ctx/codebase/QUALITY.md
539
+ ", subagent_type="ctx-quality-mapper", model="haiku", description="Map quality")
540
+
541
+ Task(prompt="
542
+ Identify concerns and technical debt.
543
+
544
+ Look for:
545
+ - TODO/FIXME comments
546
+ - Deprecated dependencies
547
+ - Security concerns
548
+ - Performance bottlenecks
549
+ - Accessibility gaps
550
+
551
+ Write comprehensive analysis to: .ctx/codebase/CONCERNS.md
552
+ ", subagent_type="ctx-concerns-mapper", model="haiku", description="Map concerns")
473
553
  ```
474
- User: "The login is broken"
475
554
 
476
- CTX: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
477
- Welcome to CTX!
478
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
555
+ **Step 3: Synthesize**
479
556
 
480
- I understood: "login is broken"
557
+ After all agents complete, create summary:
481
558
 
482
- You need to fix something. Let me understand the codebase first.
559
+ ```bash
560
+ cat > .ctx/codebase/SUMMARY.md << 'EOF'
561
+ # Codebase Summary
483
562
 
484
- I'll now:
485
- 1. Map your codebase structure
486
- 2. Find the login-related code
487
- 3. Start debugging
563
+ ## Tech Stack
564
+ {{from TECH.md}}
488
565
 
489
- [Analyzing codebase...]
566
+ ## Architecture
567
+ {{from ARCH.md}}
490
568
 
491
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
492
- To continue with CTX, run: /ctx
493
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
569
+ ## Quality
570
+ {{from QUALITY.md}}
571
+
572
+ ## Concerns
573
+ {{from CONCERNS.md}}
574
+ EOF
494
575
  ```
495
576
 
496
- ### Existing Project - Continue
577
+ **Step 4: Report**
578
+
497
579
  ```
498
- User: "continue"
580
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
581
+ [CTX] Codebase Mapped
582
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
583
+
584
+ Tech: {{stack}}
585
+ Architecture: {{pattern}}
586
+ Quality: {{assessment}}
587
+ Concerns: {{count}} identified
588
+
589
+ Files: .ctx/codebase/
590
+
591
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
592
+ To continue with CTX, run: /ctx
593
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
594
+ ```
595
+
596
+ ---
597
+
598
+ ## Status Report
599
+
600
+ Read and display current state:
499
601
 
500
- CTX: [CTX] Status: executing
501
- [CTX] Profile: balanced (1x cost)
502
- [CTX] Story: S002 - User Authentication
503
- [CTX] Task: 2/3 - Implement login form validation
504
- [CTX] Action: Executing task...
602
+ ```bash
603
+ cat .ctx/STATE.md
604
+ ls -la .ctx/phases/ 2>/dev/null | wc -l
605
+ ```
505
606
 
506
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
507
- To continue with CTX, run: /ctx
508
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
509
607
  ```
608
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
609
+ [CTX] Status
610
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
611
+
612
+ Project: {{name}}
613
+ Status: {{status}}
614
+ Profile: {{profile}}
615
+
616
+ Progress: [{{progress_bar}}] {{completed}}/{{total}} stories
617
+
618
+ Current: {{current_story}}
619
+ Next: {{next_action}}
510
620
 
511
- ### Existing Project - QA Intent
621
+ Context: {{percent}}%
622
+
623
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
624
+ To continue with CTX, run: /ctx
625
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
512
626
  ```
513
- User: "is the app accessible?"
514
627
 
515
- CTX: [CTX] Detected: QA request (accessibility)
516
- [CTX] Routing to: /ctx:qa --a11y-only
628
+ </flows>
629
+
630
+ <model_routing>
631
+ Based on config.json profile, use these models for Task() calls:
517
632
 
518
- Running WCAG 2.1 AA accessibility audit...
633
+ | Agent | quality | balanced | budget |
634
+ |-------|---------|----------|--------|
635
+ | Mappers | sonnet | haiku | haiku |
636
+ | Researcher | opus | sonnet | sonnet |
637
+ | Discusser | opus | sonnet | sonnet |
638
+ | Planner | opus | sonnet | sonnet |
639
+ | Executor | opus | sonnet | sonnet |
640
+ | Debugger | opus | sonnet | sonnet |
641
+ | QA | sonnet | sonnet | haiku |
642
+ | Verifier | sonnet | haiku | haiku |
643
+ </model_routing>
519
644
 
520
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
521
- To continue with CTX, run: /ctx
522
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
645
+ <state_transitions>
646
+ ```
647
+ initializing → discussing (after research)
648
+ discussing → executing (after decisions locked)
649
+ executing → debugging (if verification fails)
650
+ executing → verifying (if all tasks done)
651
+ debugging → executing (if fix works)
652
+ debugging → ESCALATE (if max attempts fail)
653
+ verifying → debugging (if any check fails)
654
+ verifying → COMPLETE (if ALL pass 100%)
655
+ paused → (previous state)
523
656
  ```
657
+ </state_transitions>
524
658
 
525
- </examples>
659
+ <success_criteria>
660
+ - [ ] Intent detected from user message
661
+ - [ ] Correct flow routed
662
+ - [ ] ArguSeek called for research (when applicable)
663
+ - [ ] Task() agents spawned with full context
664
+ - [ ] STATE.md updated after each action
665
+ - [ ] Clear "Next Up" shown with /ctx reminder
666
+ - [ ] User knows to run /ctx to continue
667
+ </success_criteria>