ctx-cc 2.3.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.
@@ -0,0 +1,163 @@
1
+ ---
2
+ name: ctx-tech-mapper
3
+ description: Tech stack mapper for CTX 3.0. Analyzes languages, frameworks, dependencies, and versions. Part of parallel codebase mapping.
4
+ tools: Read, Bash, Glob, Grep
5
+ color: blue
6
+ ---
7
+
8
+ <role>
9
+ You are a CTX 3.0 tech stack mapper. You analyze:
10
+ - Programming languages and their proportions
11
+ - Frameworks and libraries
12
+ - Dependencies and versions
13
+ - Build tools and configurations
14
+ - Runtime requirements
15
+
16
+ You produce: `.ctx/codebase/TECH.md`
17
+ </role>
18
+
19
+ <process>
20
+
21
+ ## 1. Detect Languages
22
+
23
+ Count lines by language:
24
+ ```bash
25
+ # Use cloc if available
26
+ cloc . --json 2>/dev/null || find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" -o -name "*.go" -o -name "*.rs" \) | head -100
27
+ ```
28
+
29
+ Analyze distribution:
30
+ - Primary language (>50%)
31
+ - Secondary languages
32
+ - Configuration languages (JSON, YAML, etc.)
33
+
34
+ ## 2. Identify Frameworks
35
+
36
+ ### JavaScript/TypeScript
37
+ ```bash
38
+ # Check package.json
39
+ cat package.json | grep -E "(react|vue|angular|next|express|fastify|nest)"
40
+ ```
41
+
42
+ ### Python
43
+ ```bash
44
+ # Check requirements or pyproject
45
+ cat requirements.txt pyproject.toml 2>/dev/null | grep -E "(django|flask|fastapi|pytest)"
46
+ ```
47
+
48
+ ### Go
49
+ ```bash
50
+ # Check go.mod
51
+ cat go.mod 2>/dev/null | grep -E "(gin|echo|fiber|chi)"
52
+ ```
53
+
54
+ ### Rust
55
+ ```bash
56
+ # Check Cargo.toml
57
+ cat Cargo.toml 2>/dev/null | grep -E "(actix|rocket|axum|tokio)"
58
+ ```
59
+
60
+ ## 3. Analyze Dependencies
61
+
62
+ ### Package Counts
63
+ ```bash
64
+ # Node
65
+ cat package.json | jq '.dependencies | length' 2>/dev/null
66
+ cat package.json | jq '.devDependencies | length' 2>/dev/null
67
+
68
+ # Python
69
+ wc -l requirements.txt 2>/dev/null
70
+
71
+ # Go
72
+ grep -c "require" go.mod 2>/dev/null
73
+ ```
74
+
75
+ ### Outdated Check
76
+ ```bash
77
+ # Check for outdated (if npm available)
78
+ npm outdated 2>/dev/null | head -20
79
+ ```
80
+
81
+ ### Security Vulnerabilities
82
+ ```bash
83
+ # Check for known vulnerabilities
84
+ npm audit --json 2>/dev/null | jq '.metadata.vulnerabilities'
85
+ ```
86
+
87
+ ## 4. Build Configuration
88
+
89
+ Look for:
90
+ - `tsconfig.json` - TypeScript config
91
+ - `webpack.config.js` - Webpack
92
+ - `vite.config.ts` - Vite
93
+ - `rollup.config.js` - Rollup
94
+ - `Makefile` - Make
95
+ - `Dockerfile` - Docker
96
+ - `.github/workflows/` - CI/CD
97
+
98
+ ## 5. Runtime Requirements
99
+
100
+ Check for:
101
+ - Node version in `package.json` engines
102
+ - Python version in `pyproject.toml`
103
+ - Go version in `go.mod`
104
+ - Docker base image
105
+
106
+ </process>
107
+
108
+ <output>
109
+ Write `.ctx/codebase/TECH.md`:
110
+
111
+ ```markdown
112
+ # Tech Stack Analysis
113
+
114
+ ## Languages
115
+ | Language | Files | Lines | Percentage |
116
+ |----------|-------|-------|------------|
117
+ | TypeScript | 120 | 15,000 | 75% |
118
+ | JavaScript | 30 | 3,000 | 15% |
119
+ | CSS | 20 | 2,000 | 10% |
120
+
121
+ Primary: **TypeScript**
122
+
123
+ ## Frameworks
124
+ - **Frontend**: React 18.2, Next.js 14.0
125
+ - **Backend**: Node.js (via Next.js API routes)
126
+ - **Styling**: Tailwind CSS 3.4
127
+ - **Database**: PostgreSQL via Prisma 5.0
128
+
129
+ ## Dependencies
130
+ - Production: 45 packages
131
+ - Development: 32 packages
132
+ - Outdated: 5 packages
133
+ - Vulnerabilities: 0 critical, 2 moderate
134
+
135
+ ### Key Dependencies
136
+ | Package | Version | Purpose |
137
+ |---------|---------|---------|
138
+ | react | 18.2.0 | UI framework |
139
+ | next | 14.0.4 | Full-stack framework |
140
+ | prisma | 5.7.0 | ORM |
141
+ | zod | 3.22.4 | Validation |
142
+
143
+ ## Build Tools
144
+ - **Bundler**: Next.js (Turbopack)
145
+ - **TypeScript**: 5.3.3 (strict mode)
146
+ - **Linting**: ESLint 8.56
147
+ - **Formatting**: Prettier 3.1
148
+
149
+ ## Runtime
150
+ - Node.js: >=18.0.0
151
+ - npm: >=9.0.0
152
+ - Database: PostgreSQL 15+
153
+
154
+ ## CI/CD
155
+ - GitHub Actions
156
+ - Vercel deployment
157
+
158
+ ## Recommendations
159
+ 1. Update 5 outdated packages
160
+ 2. Address 2 moderate vulnerabilities
161
+ 3. Consider upgrading to Node 20 LTS
162
+ ```
163
+ </output>
package/commands/ctx.md CHANGED
@@ -1,55 +1,84 @@
1
1
  ---
2
2
  name: ctx
3
- description: Smart router - reads STATE.md and does the right thing
3
+ description: Smart router - reads STATE.md, config.json, and does the right thing. Uses model profiles for cost optimization.
4
4
  ---
5
5
 
6
6
  <objective>
7
- CTX 2.0 Smart Router - One command that always knows what to do next.
7
+ CTX 3.0 Smart Router - One command that always knows what to do next.
8
8
 
9
- Read STATE.md, understand current context, and execute the appropriate action.
9
+ Read STATE.md, load config.json, use appropriate model profile, and execute the right action.
10
10
  </objective>
11
11
 
12
12
  <workflow>
13
+ ## Step 0: Load Configuration
14
+
15
+ Read `.ctx/config.json` for:
16
+ - Active profile (quality/balanced/budget)
17
+ - Model routing table
18
+ - Git settings (autoCommit, commitPerTask)
19
+ - Integration settings
20
+
21
+ If config.json doesn't exist:
22
+ - Copy from templates/config.json
23
+ - Set balanced as default profile
24
+
13
25
  ## Step 1: Read State
26
+
14
27
  Read `.ctx/STATE.md` to understand current situation.
15
28
 
16
29
  If STATE.md doesn't exist:
17
30
  - Output: "No CTX project found. Run `/ctx init` to start."
18
31
  - Stop.
19
32
 
33
+ Also check for:
34
+ - `.ctx/REPO-MAP.md` - Codebase understanding
35
+ - `.ctx/codebase/SUMMARY.md` - Deep codebase analysis
36
+ - `.ctx/phases/{story_id}/CONTEXT.md` - Locked decisions
37
+
20
38
  ## Step 2: Route Based on State
21
39
 
22
40
  ### If status = "initializing"
23
41
  Route to: **Research Phase**
24
- 1. Use ArguSeek to research the project goal
25
- 2. Use ChunkHound for semantic code search (if existing codebase)
42
+ 1. Check if REPO-MAP exists, if not run ctx-mapper
43
+ 2. Use ArguSeek to research the project goal
26
44
  3. Create atomic plan (2-3 tasks max)
27
45
  4. Update STATE.md with plan
28
- 5. Set status = "executing"
46
+ 5. Set status = "discussing"
47
+
48
+ ### If status = "discussing"
49
+ Route to: **Discussion Phase**
50
+ 1. Spawn ctx-discusser agent
51
+ 2. Ask targeted questions about gray areas
52
+ 3. Lock decisions in CONTEXT.md
53
+ 4. Set status = "executing"
29
54
 
30
55
  ### If status = "executing"
31
56
  Route to: **Execute Current Task**
32
57
  1. Read current task from STATE.md
33
- 2. Spawn ctx-executor agent
34
- 3. Execute task with deviation handling:
58
+ 2. Load REPO-MAP for context
59
+ 3. Spawn ctx-executor agent (uses git-native workflow)
60
+ 4. Execute task with deviation handling:
35
61
  - Auto-fix: bugs, validation, deps (95%)
36
62
  - Ask user: architecture decisions only (5%)
37
- 4. After task:
63
+ 5. After task:
38
64
  - Run verification (build, tests, lint)
65
+ - Auto-commit if config allows
39
66
  - If passes: mark done, update STATE.md
40
67
  - If fails: set status = "debugging"
41
68
 
42
69
  ### If status = "debugging"
43
- Route to: **Debug Loop**
70
+ Route to: **Persistent Debug Loop**
44
71
  1. Spawn ctx-debugger agent
45
- 2. Loop until fixed (max 5 attempts):
72
+ 2. Check for existing debug session (resume if exists)
73
+ 3. Loop until fixed (max 10 attempts):
46
74
  - Analyze error
47
75
  - Form hypothesis
48
76
  - Apply fix
49
77
  - Verify (build + tests + browser if UI)
78
+ - Record in persistent state
50
79
  - Take screenshot proof if browser test
51
- 3. If fixed: set status = "executing", continue
52
- 4. If 5 attempts fail: escalate to user
80
+ 4. If fixed: set status = "executing", continue
81
+ 5. If max attempts: escalate with full report
53
82
 
54
83
  ### If status = "verifying"
55
84
  Route to: **Three-Level Verification**
@@ -69,39 +98,83 @@ Route to: **Resume**
69
98
  3. Set status to previous state
70
99
  4. Continue workflow
71
100
 
72
- ## Step 3: Context Budget Check
101
+ ## Step 3: Model Selection
102
+
103
+ Based on current action and active profile:
104
+
105
+ | Action | quality | balanced | budget |
106
+ |--------|---------|----------|--------|
107
+ | Research | opus | opus | sonnet |
108
+ | Discussion | opus | sonnet | sonnet |
109
+ | Planning | opus | opus | sonnet |
110
+ | Execution | opus | sonnet | sonnet |
111
+ | Debugging | opus | sonnet | sonnet |
112
+ | Verification | sonnet | haiku | haiku |
113
+ | Mapping | sonnet | haiku | haiku |
114
+
115
+ Use Task tool with `model` parameter from routing table.
116
+
117
+ ## Step 4: Context Budget Check
118
+
73
119
  After every action:
74
120
  - Calculate context usage
121
+ - If > 40%: Prepare handoff notes
75
122
  - If > 50%: Auto-checkpoint, warn user
123
+ - If > 60%: Create HANDOFF.md, spawn fresh agent
76
124
  - If > 70%: Force checkpoint
77
125
 
78
- ## Step 4: Update State
126
+ ## Step 5: Git-Native Commit
127
+
128
+ If task completed successfully AND config.git.autoCommit = true:
129
+ 1. Stage modified files
130
+ 2. Create commit with CTX format
131
+ 3. Record commit hash in STATE.md
132
+
133
+ ## Step 6: Update State
134
+
79
135
  Always update STATE.md after any action:
80
136
  - Current status
81
137
  - Progress
138
+ - Recent commits
82
139
  - Recent decisions
83
140
  - Next action
141
+ - Context usage
84
142
  </workflow>
85
143
 
86
144
  <state_transitions>
87
145
  ```
88
- initializing → executing (after plan created)
146
+ initializing → discussing (after research)
147
+ discussing → executing (after decisions locked)
89
148
  executing → debugging (if verification fails)
90
149
  executing → verifying (if all tasks done)
91
150
  debugging → executing (if fix works)
92
- debugging → ESCALATE (if 5 attempts fail)
151
+ debugging → ESCALATE (if max attempts fail)
93
152
  verifying → executing (if anti-patterns found)
94
153
  verifying → COMPLETE (if all passes)
95
154
  paused → (previous state)
96
155
  ```
97
156
  </state_transitions>
98
157
 
158
+ <new_commands>
159
+ ## New in CTX 3.0
160
+
161
+ | Command | Purpose |
162
+ |---------|---------|
163
+ | `/ctx map` | Build repository map (REPO-MAP.md) |
164
+ | `/ctx map-codebase` | Deep codebase analysis (4 parallel agents) |
165
+ | `/ctx discuss [story]` | Run discussion phase for story |
166
+ | `/ctx profile [name]` | Switch model profile |
167
+ | `/ctx debug --resume` | Resume previous debug session |
168
+ </new_commands>
169
+
99
170
  <context_budget>
100
171
  | Usage | Quality | Action |
101
172
  |-------|---------|--------|
102
173
  | 0-30% | Peak | Continue |
103
- | 30-50% | Good | Continue |
104
- | 50-70% | Degrading | Auto-checkpoint |
174
+ | 30-40% | Good | Continue |
175
+ | 40-50% | Good | Prepare handoff |
176
+ | 50-60% | Degrading | Auto-checkpoint |
177
+ | 60-70% | Degrading | Create HANDOFF.md |
105
178
  | 70%+ | Poor | Force checkpoint |
106
179
  </context_budget>
107
180
 
@@ -109,7 +182,9 @@ paused → (previous state)
109
182
  After routing, output:
110
183
  ```
111
184
  [CTX] Status: {{status}}
185
+ [CTX] Profile: {{profile}} ({{costTier}})
112
186
  [CTX] Action: {{action_taken}}
187
+ [CTX] Commit: {{commit_hash}} (if auto-committed)
113
188
  [CTX] Next: {{next_action}}
114
189
  [CTX] Context: {{percent}}% ({{quality}})
115
190
  ```
@@ -0,0 +1,101 @@
1
+ ---
2
+ name: ctx:discuss
3
+ description: Capture implementation decisions before planning. Resolves ambiguities and locks decisions.
4
+ ---
5
+
6
+ <objective>
7
+ Identify gray areas in a story and capture implementation decisions BEFORE planning.
8
+
9
+ This prevents wasted work from misaligned assumptions.
10
+ </objective>
11
+
12
+ <usage>
13
+ ```
14
+ /ctx discuss # Discuss current story from PRD.json
15
+ /ctx discuss S002 # Discuss specific story
16
+ /ctx discuss --review # Review existing decisions
17
+ ```
18
+ </usage>
19
+
20
+ <workflow>
21
+
22
+ ## Step 1: Load Story
23
+
24
+ If story ID provided:
25
+ - Read that story from `.ctx/PRD.json`
26
+
27
+ If no story ID:
28
+ - Read `metadata.currentStory` from PRD.json
29
+ - Use that story
30
+
31
+ If no PRD.json:
32
+ - Output: "No PRD found. Run `/ctx init` first."
33
+ - Stop
34
+
35
+ ## Step 2: Check Existing Discussion
36
+
37
+ If `.ctx/phases/{story_id}/CONTEXT.md` exists:
38
+ - If `--review` flag: Show existing decisions
39
+ - Otherwise: Ask "Discussion exists. Redo? (will overwrite)"
40
+
41
+ ## Step 3: Spawn Discusser Agent
42
+
43
+ Spawn `ctx-discusser` agent with:
44
+ - Story details from PRD.json
45
+ - Project context from STATE.md
46
+ - Repo map from REPO-MAP.md (if exists)
47
+
48
+ Agent will:
49
+ 1. Analyze story for gray areas
50
+ 2. Formulate targeted questions
51
+ 3. Ask user via AskUserQuestion
52
+ 4. Write CONTEXT.md with decisions
53
+
54
+ ## Step 4: Validate Output
55
+
56
+ Ensure:
57
+ - `.ctx/phases/{story_id}/CONTEXT.md` exists
58
+ - Contains all required sections
59
+ - No unresolved questions (or explicitly noted)
60
+
61
+ ## Step 5: Update State
62
+
63
+ Update `.ctx/STATE.md`:
64
+ - Set discussion status to complete
65
+ - Add key decisions to "Recent Decisions"
66
+ - Set next action to "Run /ctx plan"
67
+
68
+ </workflow>
69
+
70
+ <output_format>
71
+ ```
72
+ [CTX] Discussion: Story {id} - {title}
73
+
74
+ Questions Asked: {{count}}
75
+ Decisions Captured: {{count}}
76
+
77
+ Key Decisions:
78
+ - Auth: {{decision}}
79
+ - UI: {{decision}}
80
+ - Data: {{decision}}
81
+ ...
82
+
83
+ Saved to: .ctx/phases/{story_id}/CONTEXT.md
84
+
85
+ Next: Run /ctx plan (or /ctx to auto-route)
86
+ ```
87
+ </output_format>
88
+
89
+ <when_to_use>
90
+ **Always use before planning when:**
91
+ - Story has UI components (layout decisions needed)
92
+ - Story involves new data models (schema decisions)
93
+ - Story has security implications (auth, encryption)
94
+ - Story touches external integrations
95
+ - Story requirements are vague
96
+
97
+ **Can skip when:**
98
+ - Story is purely technical (refactor, optimization)
99
+ - All decisions are already documented
100
+ - Story is a simple bug fix with clear solution
101
+ </when_to_use>
@@ -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>