Skip to content

Commit d68d99f

Browse files
committed
fix: Make AST execution deterministic in Gear 4 gap-analysis
PROBLEM: AST analysis was not deterministic - relied on Claude interpreting skill instructions and deciding whether to run the command. This meant AST could be skipped/forgotten, defeating the purpose of having it. User feedback: "AST analysis should be deterministic and certain to happen" "We should not 'forget' to run the AST analysis" SOLUTION: Updated slash command to explicitly invoke Bash tool as Step 1, making AST execution deterministic rather than interpretive. CHANGES: .claude/commands/stackshift.gap-analysis.md: BEFORE: "Use the Skill tool with skill='gap-analysis'" AFTER: "Step 1: Run AST Analysis (Deterministic - Always Executes) First, use the Bash tool to execute: ~/stackshift/scripts/run-ast-analysis.mjs roadmap" Step 2: If AST fails, fall back to skill-based manual analysis skills/gap-analysis/SKILL.md: - Updated to clarify AST as primary method - Made instructions more directive (ACTION REQUIRED, RUN THIS!) - Skill now serves as fallback if AST unavailable Created docs/AST_INTEGRATION_ROADMAP.md: - Explains skills are instructions, not executable code - Maps out integration plan for all 6 gears - Tracks what's done vs TODO Created docs/DETERMINISTIC_AST_EXECUTION.md: - Defines pattern for deterministic execution - Explains command vs skill distinction - Rollout plan for other gears RESULT: ✅ Gear 4 now runs AST deterministically ❌ Other gears still need updating to follow same pattern NEXT STEPS: 1. Create new AST commands (detect-status, verify, extract) 2. Update other slash commands for deterministic execution 3. Keep skills as fallback for manual process This ensures AST runs automatically when environment permits, with graceful fallback if unavailable.
1 parent 81c099f commit d68d99f

File tree

4 files changed

+687
-13
lines changed

4 files changed

+687
-13
lines changed

.claude/commands/stackshift.gap-analysis.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22
description: Gear 4 - Analyze gaps and create prioritized implementation roadmap
33
---
44

5-
Invoke the gap-analysis skill (Gear 4 of StackShift).
5+
# Gear 4: Gap Analysis
66

7-
This identifies incomplete features, creates prioritized roadmap, estimates implementation effort.
7+
**IMPORTANT**: This command runs AST-powered analysis automatically.
88

9-
Prerequisite: Complete Gear 3 (create-specs)
9+
## Step 1: Run AST Analysis (Deterministic - Always Executes)
1010

11-
Use the Skill tool with skill="gap-analysis".
11+
First, use the Bash tool to execute the AST analysis script:
12+
13+
```bash
14+
~/stackshift/scripts/run-ast-analysis.mjs roadmap . --format=markdown
15+
```
16+
17+
**This will**:
18+
- Parse codebase with Babel AST
19+
- Extract function signatures, stubs, business logic
20+
- Compare against specifications
21+
- Generate prioritized roadmap with confidence scores
22+
- Output detailed gap analysis
23+
24+
## Step 2: If AST Fails, Use Fallback
25+
26+
If the AST command fails (script not found, Node.js issue, permissions):
27+
28+
Use the Skill tool with skill="gap-analysis" for manual analysis.

docs/AST_INTEGRATION_ROADMAP.md

Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,366 @@
1+
# AST Integration Roadmap
2+
3+
## Current Status
4+
5+
**✅ Completed**: AST CLI wrapper created and gap-analysis skill updated
6+
7+
**🔄 Next Steps**: Integrate AST into other gears
8+
9+
---
10+
11+
## How Skills Work
12+
13+
**Important Understanding**:
14+
- Skills are **instruction files** (markdown), not executable code
15+
- When you run `/stackshift.gap-analysis`, it tells Claude: "Read gap-analysis skill and follow instructions"
16+
- Claude then **decides** what to do based on the instructions
17+
- For AST to run **automatically**, the skill must **explicitly tell Claude to run the command**
18+
19+
### Before (Doesn't Work)
20+
```markdown
21+
### Optional: You can run AST analysis
22+
23+
```bash
24+
~/stackshift/scripts/run-ast-analysis.mjs roadmap
25+
```
26+
```
27+
28+
❌ Claude sees this as "nice to know" and might skip it
29+
30+
### After (Works!)
31+
```markdown
32+
### Step 2a: Run AST-Powered Analysis (PRIMARY METHOD - RUN THIS!)
33+
34+
**ACTION REQUIRED**: Execute the AST analysis command now:
35+
36+
```bash
37+
~/stackshift/scripts/run-ast-analysis.mjs roadmap . --format=markdown
38+
```
39+
40+
**If this command fails**, proceed to Step 2b. **Otherwise**, use output and skip remaining steps.
41+
```
42+
43+
✅ Claude knows to actually execute this command
44+
45+
---
46+
47+
## Integration Plan by Gear
48+
49+
### ✅ Gear 4: Gap Analysis (DONE)
50+
51+
**Status**: Updated with AST as primary method
52+
53+
**What it does**:
54+
- Step 2a: Run AST analysis (PRIMARY - explicit "RUN THIS!")
55+
- Step 2b: Fallback to /speckit.analyze
56+
- Step 2c: Manual analysis (last resort)
57+
58+
**Automatic?** Yes - skill explicitly tells Claude to run the command
59+
60+
---
61+
62+
### 🔄 Gear 3: Create Specs (TODO)
63+
64+
**Current**: Uses MCP tool `stackshift_create_specs`
65+
66+
**Enhancement Opportunity**:
67+
Use AST to **auto-detect implementation status** when creating specs:
68+
69+
```bash
70+
# During spec creation, run AST to detect status
71+
~/stackshift/scripts/run-ast-analysis.mjs detect-status . --output=json
72+
73+
# Returns for each feature:
74+
{
75+
"user-authentication": {
76+
"status": "partial", # ✅/⚠️/❌
77+
"confidence": 75,
78+
"evidence": {
79+
"functions_found": ["login", "logout"],
80+
"functions_missing": ["register", "resetPassword"],
81+
"stubs_detected": ["resetPassword"]
82+
}
83+
}
84+
}
85+
```
86+
87+
**Action Required**:
88+
1. Create new command: `detect-status`
89+
2. Update create-specs skill to call it
90+
3. Auto-populate spec status from AST results
91+
92+
**Priority**: High (makes specs accurate from day one)
93+
94+
---
95+
96+
### 🔄 Gear 6: Implementation (TODO)
97+
98+
**Current**: Manual verification after implementation
99+
100+
**Enhancement Opportunity**:
101+
Use AST to **verify implementation matches specs**:
102+
103+
```bash
104+
# After implementing a feature, verify it
105+
~/stackshift/scripts/run-ast-analysis.mjs verify . \
106+
--spec=.specify/specs/001-user-auth/spec.md \
107+
--output=markdown
108+
109+
# Returns:
110+
✅ Function exists: createUser
111+
✅ Signature matches: (name: string, email: string) => Promise<User>
112+
✅ Has error handling: try/catch block found
113+
❌ Missing tests: No test file for createUser
114+
⚠️ Stub detected: Function body returns placeholder
115+
```
116+
117+
**Action Required**:
118+
1. Create new command: `verify`
119+
2. Update implement skill to call it after each feature
120+
3. Block completion if verification fails
121+
122+
**Priority**: Medium (quality gate for implementations)
123+
124+
---
125+
126+
### 🔄 Gear 2: Reverse Engineering (TODO)
127+
128+
**Current**: Manual code reading to extract documentation
129+
130+
**Enhancement Opportunity**:
131+
Use AST to **automatically extract** from codebase:
132+
133+
```bash
134+
# Extract API endpoints, business logic, etc.
135+
~/stackshift/scripts/run-ast-analysis.mjs extract . --output=markdown
136+
137+
# Auto-generates docs/reverse-engineering/* files from AST:
138+
- api-endpoints.md (from route definitions)
139+
- business-logic.md (from validation patterns)
140+
- data-models.md (from class definitions)
141+
- integration-points.md (from import analysis)
142+
```
143+
144+
**Action Required**:
145+
1. Create new commands: `extract-apis`, `extract-logic`, `extract-models`
146+
2. Update reverse-engineer skill to call them
147+
3. Auto-generate docs instead of manual extraction
148+
149+
**Priority**: Low (high value but complex to implement)
150+
151+
---
152+
153+
### 🔄 Gear 1: Analysis (TODO)
154+
155+
**Current**: File-based tech stack detection
156+
157+
**Enhancement Opportunity**:
158+
Use AST to **detect actual usage patterns**:
159+
160+
```bash
161+
# Analyze actual code patterns
162+
~/stackshift/scripts/run-ast-analysis.mjs analyze-stack . --output=json
163+
164+
# Returns:
165+
{
166+
"frameworks": ["express", "react"], # From imports
167+
"patterns": ["jwt-auth", "rest-api"], # From code analysis
168+
"apis": {
169+
"rest": 23, # Count of REST endpoints
170+
"graphql": 0,
171+
"websocket": 5
172+
}
173+
}
174+
```
175+
176+
**Action Required**:
177+
1. Create new command: `analyze-stack`
178+
2. Update analyze skill to call it
179+
3. More accurate tech stack detection
180+
181+
**Priority**: Low (nice-to-have)
182+
183+
---
184+
185+
### 🔄 Gear 5: Complete Specs (TODO)
186+
187+
**Current**: Manual clarification questions
188+
189+
**Enhancement Opportunity**:
190+
Use AST to **provide evidence** for clarifications:
191+
192+
```bash
193+
# Find contradictions/ambiguities
194+
~/stackshift/scripts/run-ast-analysis.mjs find-issues . \
195+
--spec=.specify/specs/001-user-auth/spec.md
196+
197+
# Returns:
198+
⚠️ Contradiction found:
199+
Spec says: "JWT tokens expire in 1 hour"
200+
Code shows: expiresIn: '24h' (src/auth/jwt.ts:42)
201+
202+
Question: Should tokens expire in 1h or 24h?
203+
```
204+
205+
**Action Required**:
206+
1. Create new command: `find-issues`
207+
2. Update complete-spec skill to call it
208+
3. Generate evidence-based clarifications
209+
210+
**Priority**: Medium (improves clarification quality)
211+
212+
---
213+
214+
## Summary: What Needs to Happen
215+
216+
### Immediate (Make Current Integration Automatic)
217+
218+
**Gear 4**: Already done - skill explicitly runs AST command
219+
220+
### Short-term (High Value Additions)
221+
222+
1. **Gear 3**: Add `detect-status` command
223+
- Update create-specs skill to run it
224+
- Auto-set implementation status
225+
226+
2. **Gear 6**: Add `verify` command
227+
- Update implement skill to run it
228+
- Quality gate before completion
229+
230+
### Long-term (Nice-to-Have)
231+
232+
3. **Gear 2**: Add `extract-*` commands
233+
- Auto-generate reverse engineering docs
234+
235+
4. **Gear 5**: Add `find-issues` command
236+
- Evidence-based clarifications
237+
238+
5. **Gear 1**: Add `analyze-stack` command
239+
- Better tech detection
240+
241+
---
242+
243+
## Implementation Strategy
244+
245+
### Phase 1: Make It Work (Current)
246+
- ✅ Create CLI wrapper
247+
- ✅ Update Gear 4 to use it explicitly
248+
- ✅ Document approach
249+
250+
### Phase 2: Add New Commands (Next)
251+
Each new AST command follows this pattern:
252+
253+
```javascript
254+
// scripts/run-ast-analysis.mjs
255+
case 'detect-status':
256+
const result = await detectStatusHandler({ directory });
257+
console.log(JSON.stringify(result, null, 2));
258+
break;
259+
260+
case 'verify':
261+
const result = await verifyImplementationHandler({
262+
directory,
263+
specPath: options.spec
264+
});
265+
console.log(result);
266+
break;
267+
```
268+
269+
### Phase 3: Update Skills (Per Command)
270+
```markdown
271+
# skills/create-specs/SKILL.md
272+
273+
## Step 3: Detect Implementation Status (AUTOMATIC)
274+
275+
**Run AST status detection**:
276+
277+
```bash
278+
~/stackshift/scripts/run-ast-analysis.mjs detect-status . --output=json
279+
```
280+
281+
This auto-populates spec status fields (✅/⚠️/❌) based on actual code analysis.
282+
```
283+
284+
### Phase 4: Test & Iterate
285+
- Test each integration
286+
- Gather user feedback
287+
- Refine based on usage
288+
289+
---
290+
291+
## Answer to "Will It Be Automatic?"
292+
293+
### For Gear 4 (Gap Analysis): YES ✅
294+
295+
**The skill now explicitly tells Claude**:
296+
- "ACTION REQUIRED: Execute the AST analysis command now"
297+
- "RUN THIS!" in the heading
298+
- "If this fails, use fallback. Otherwise skip other steps."
299+
300+
When you run `/stackshift.gap-analysis`, Claude will:
301+
1. Read skill file
302+
2. See "ACTION REQUIRED" and "RUN THIS!"
303+
3. Execute: `~/stackshift/scripts/run-ast-analysis.mjs roadmap`
304+
4. Use the AST output
305+
306+
### For Other Gears: NOT YET ❌
307+
308+
They need similar updates:
309+
- Create new AST commands for each use case
310+
- Update skill files with explicit "RUN THIS!" instructions
311+
- Test that Claude actually executes them
312+
313+
---
314+
315+
## How to Enable for Each Gear
316+
317+
**Pattern**:
318+
1. ✅ Create AST command (in `run-ast-analysis.mjs`)
319+
2. ✅ Add handler function (import from mcp-server/dist)
320+
3. ✅ Update skill file with **explicit execution instruction**
321+
4. ✅ Use language like "ACTION REQUIRED", "RUN THIS!", "Execute now"
322+
5. ✅ Provide fallback if command fails
323+
324+
**Example Template**:
325+
```markdown
326+
## Step X: [Task Name] (PRIMARY METHOD - RUN THIS!)
327+
328+
**ACTION REQUIRED**: Execute the AST command now:
329+
330+
```bash
331+
~/stackshift/scripts/run-ast-analysis.mjs [command] . [options]
332+
```
333+
334+
**What this provides**: [benefits]
335+
336+
**If this command fails**: [fallback steps]
337+
338+
**Otherwise**: Use the output and proceed to [next step]
339+
```
340+
341+
---
342+
343+
## Tracking Progress
344+
345+
- [x] Gear 4: Gap Analysis (AST automatic)
346+
- [ ] Gear 3: Create Specs (add `detect-status`)
347+
- [ ] Gear 6: Implementation (add `verify`)
348+
- [ ] Gear 5: Complete Specs (add `find-issues`)
349+
- [ ] Gear 2: Reverse Engineering (add `extract-*`)
350+
- [ ] Gear 1: Analysis (add `analyze-stack`)
351+
352+
---
353+
354+
## Key Insight
355+
356+
**Skills don't run code automatically** - they tell Claude what to do.
357+
358+
For AST to run automatically, the skill must:
359+
1. ✅ Use directive language ("RUN THIS NOW!")
360+
2. ✅ Put it early in the workflow (Step 2a, not "optional")
361+
3. ✅ Make it primary method with fallbacks
362+
4. ✅ Tell Claude to skip other steps if it succeeds
363+
364+
**Current Gear 4** does all of this! ✅
365+
366+
**Other gears** need the same pattern applied. 🔄

0 commit comments

Comments
 (0)