@simplysm/claude 13.0.26 → 13.0.27
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/claude/skills/sd-check/SKILL.md +139 -77
- package/claude/skills/sd-check/baseline-analysis.md +129 -0
- package/claude/skills/sd-check/test-scenarios.md +172 -0
- package/claude/skills/sd-debug/SKILL.md +296 -0
- package/claude/skills/sd-debug/condition-based-waiting-example.ts +158 -0
- package/claude/skills/sd-debug/condition-based-waiting.md +115 -0
- package/claude/skills/sd-debug/defense-in-depth.md +122 -0
- package/claude/skills/sd-debug/find-polluter.sh +58 -0
- package/claude/skills/sd-debug/root-cause-tracing.md +169 -0
- package/claude/skills/sd-debug/test-baseline-pressure.md +59 -0
- package/claude/skills/sd-use/SKILL.md +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Bisection script for finding which test creates unwanted files/directories
|
|
3
|
+
# Usage: ./find-polluter.sh <file_or_dir_to_check> <test_pattern>
|
|
4
|
+
# Example: ./find-polluter.sh '.git' 'src/**/*.test.ts'
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
if [ "$#" -ne 2 ]; then
|
|
9
|
+
echo "Usage: $0 <file_or_dir_to_check> <test_pattern>"
|
|
10
|
+
echo "Example: $0 '.git' 'src/**/*.test.ts'"
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
CHECK_PATH="$1"
|
|
15
|
+
TEST_PATTERN="$2"
|
|
16
|
+
|
|
17
|
+
# Find all test files matching pattern
|
|
18
|
+
readarray -t TEST_FILES < <(find . -path "$TEST_PATTERN" -type f)
|
|
19
|
+
|
|
20
|
+
if [ ${#TEST_FILES[@]} -eq 0 ]; then
|
|
21
|
+
echo "No test files found matching pattern: $TEST_PATTERN"
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "Found ${#TEST_FILES[@]} test files"
|
|
26
|
+
echo "Checking for pollution: $CHECK_PATH"
|
|
27
|
+
echo ""
|
|
28
|
+
|
|
29
|
+
for test_file in "${TEST_FILES[@]}"; do
|
|
30
|
+
# Skip if pollution already exists
|
|
31
|
+
if [ -e "$CHECK_PATH" ]; then
|
|
32
|
+
echo "⚠️ Pollution already exists, skipping to avoid false positive"
|
|
33
|
+
echo " Please remove $CHECK_PATH and re-run"
|
|
34
|
+
exit 1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
echo "Testing: $test_file"
|
|
38
|
+
|
|
39
|
+
# Run the test
|
|
40
|
+
npm test "$test_file" > /dev/null 2>&1 || true
|
|
41
|
+
|
|
42
|
+
# Check if pollution appeared
|
|
43
|
+
if [ -e "$CHECK_PATH" ]; then
|
|
44
|
+
echo ""
|
|
45
|
+
echo "🔴 FOUND POLLUTER: $test_file"
|
|
46
|
+
echo ""
|
|
47
|
+
echo "This test created: $CHECK_PATH"
|
|
48
|
+
ls -la "$CHECK_PATH" 2>/dev/null || echo "(path exists but can't stat)"
|
|
49
|
+
echo ""
|
|
50
|
+
echo "Investigate with:"
|
|
51
|
+
echo " npm test '$test_file' -- --reporter=verbose"
|
|
52
|
+
echo " git diff"
|
|
53
|
+
exit 0
|
|
54
|
+
fi
|
|
55
|
+
done
|
|
56
|
+
|
|
57
|
+
echo ""
|
|
58
|
+
echo "✅ No polluter found - all ${#TEST_FILES[@]} tests are clean"
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Root Cause Tracing
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
|
|
6
|
+
|
|
7
|
+
**Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source.
|
|
8
|
+
|
|
9
|
+
## When to Use
|
|
10
|
+
|
|
11
|
+
```dot
|
|
12
|
+
digraph when_to_use {
|
|
13
|
+
"Bug appears deep in stack?" [shape=diamond];
|
|
14
|
+
"Can trace backwards?" [shape=diamond];
|
|
15
|
+
"Fix at symptom point" [shape=box];
|
|
16
|
+
"Trace to original trigger" [shape=box];
|
|
17
|
+
"BETTER: Also add defense-in-depth" [shape=box];
|
|
18
|
+
|
|
19
|
+
"Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
|
|
20
|
+
"Can trace backwards?" -> "Trace to original trigger" [label="yes"];
|
|
21
|
+
"Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
|
|
22
|
+
"Trace to original trigger" -> "BETTER: Also add defense-in-depth";
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Use when:**
|
|
27
|
+
- Error happens deep in execution (not at entry point)
|
|
28
|
+
- Stack trace shows long call chain
|
|
29
|
+
- Unclear where invalid data originated
|
|
30
|
+
- Need to find which test/code triggers the problem
|
|
31
|
+
|
|
32
|
+
## The Tracing Process
|
|
33
|
+
|
|
34
|
+
### 1. Observe the Symptom
|
|
35
|
+
```
|
|
36
|
+
Error: git init failed in /Users/jesse/project/packages/core
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 2. Find Immediate Cause
|
|
40
|
+
**What code directly causes this?**
|
|
41
|
+
```typescript
|
|
42
|
+
await execFileAsync('git', ['init'], { cwd: projectDir });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. Ask: What Called This?
|
|
46
|
+
```typescript
|
|
47
|
+
WorktreeManager.createSessionWorktree(projectDir, sessionId)
|
|
48
|
+
→ called by Session.initializeWorkspace()
|
|
49
|
+
→ called by Session.create()
|
|
50
|
+
→ called by test at Project.create()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. Keep Tracing Up
|
|
54
|
+
**What value was passed?**
|
|
55
|
+
- `projectDir = ''` (empty string!)
|
|
56
|
+
- Empty string as `cwd` resolves to `process.cwd()`
|
|
57
|
+
- That's the source code directory!
|
|
58
|
+
|
|
59
|
+
### 5. Find Original Trigger
|
|
60
|
+
**Where did empty string come from?**
|
|
61
|
+
```typescript
|
|
62
|
+
const context = setupCoreTest(); // Returns { tempDir: '' }
|
|
63
|
+
Project.create('name', context.tempDir); // Accessed before beforeEach!
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Adding Stack Traces
|
|
67
|
+
|
|
68
|
+
When you can't trace manually, add instrumentation:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Before the problematic operation
|
|
72
|
+
async function gitInit(directory: string) {
|
|
73
|
+
const stack = new Error().stack;
|
|
74
|
+
console.error('DEBUG git init:', {
|
|
75
|
+
directory,
|
|
76
|
+
cwd: process.cwd(),
|
|
77
|
+
nodeEnv: process.env.NODE_ENV,
|
|
78
|
+
stack,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await execFileAsync('git', ['init'], { cwd: directory });
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Critical:** Use `console.error()` in tests (not logger - may not show)
|
|
86
|
+
|
|
87
|
+
**Run and capture:**
|
|
88
|
+
```bash
|
|
89
|
+
npm test 2>&1 | grep 'DEBUG git init'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Analyze stack traces:**
|
|
93
|
+
- Look for test file names
|
|
94
|
+
- Find the line number triggering the call
|
|
95
|
+
- Identify the pattern (same test? same parameter?)
|
|
96
|
+
|
|
97
|
+
## Finding Which Test Causes Pollution
|
|
98
|
+
|
|
99
|
+
If something appears during tests but you don't know which test:
|
|
100
|
+
|
|
101
|
+
Use the bisection script `find-polluter.sh` in this directory:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
./find-polluter.sh '.git' 'src/**/*.test.ts'
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Runs tests one-by-one, stops at first polluter. See script for usage.
|
|
108
|
+
|
|
109
|
+
## Real Example: Empty projectDir
|
|
110
|
+
|
|
111
|
+
**Symptom:** `.git` created in `packages/core/` (source code)
|
|
112
|
+
|
|
113
|
+
**Trace chain:**
|
|
114
|
+
1. `git init` runs in `process.cwd()` ← empty cwd parameter
|
|
115
|
+
2. WorktreeManager called with empty projectDir
|
|
116
|
+
3. Session.create() passed empty string
|
|
117
|
+
4. Test accessed `context.tempDir` before beforeEach
|
|
118
|
+
5. setupCoreTest() returns `{ tempDir: '' }` initially
|
|
119
|
+
|
|
120
|
+
**Root cause:** Top-level variable initialization accessing empty value
|
|
121
|
+
|
|
122
|
+
**Fix:** Made tempDir a getter that throws if accessed before beforeEach
|
|
123
|
+
|
|
124
|
+
**Also added defense-in-depth:**
|
|
125
|
+
- Layer 1: Project.create() validates directory
|
|
126
|
+
- Layer 2: WorkspaceManager validates not empty
|
|
127
|
+
- Layer 3: NODE_ENV guard refuses git init outside tmpdir
|
|
128
|
+
- Layer 4: Stack trace logging before git init
|
|
129
|
+
|
|
130
|
+
## Key Principle
|
|
131
|
+
|
|
132
|
+
```dot
|
|
133
|
+
digraph principle {
|
|
134
|
+
"Found immediate cause" [shape=ellipse];
|
|
135
|
+
"Can trace one level up?" [shape=diamond];
|
|
136
|
+
"Trace backwards" [shape=box];
|
|
137
|
+
"Is this the source?" [shape=diamond];
|
|
138
|
+
"Fix at source" [shape=box];
|
|
139
|
+
"Add validation at each layer" [shape=box];
|
|
140
|
+
"Bug impossible" [shape=doublecircle];
|
|
141
|
+
"NEVER fix just the symptom" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];
|
|
142
|
+
|
|
143
|
+
"Found immediate cause" -> "Can trace one level up?";
|
|
144
|
+
"Can trace one level up?" -> "Trace backwards" [label="yes"];
|
|
145
|
+
"Can trace one level up?" -> "NEVER fix just the symptom" [label="no"];
|
|
146
|
+
"Trace backwards" -> "Is this the source?";
|
|
147
|
+
"Is this the source?" -> "Trace backwards" [label="no - keeps going"];
|
|
148
|
+
"Is this the source?" -> "Fix at source" [label="yes"];
|
|
149
|
+
"Fix at source" -> "Add validation at each layer";
|
|
150
|
+
"Add validation at each layer" -> "Bug impossible";
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**NEVER fix just where the error appears.** Trace back to find the original trigger.
|
|
155
|
+
|
|
156
|
+
## Stack Trace Tips
|
|
157
|
+
|
|
158
|
+
**In tests:** Use `console.error()` not logger - logger may be suppressed
|
|
159
|
+
**Before operation:** Log before the dangerous operation, not after it fails
|
|
160
|
+
**Include context:** Directory, cwd, environment variables, timestamps
|
|
161
|
+
**Capture stack:** `new Error().stack` shows complete call chain
|
|
162
|
+
|
|
163
|
+
## Real-World Impact
|
|
164
|
+
|
|
165
|
+
From debugging session (2025-10-03):
|
|
166
|
+
- Found root cause through 5-level trace
|
|
167
|
+
- Fixed at source (getter validation)
|
|
168
|
+
- Added 4 layers of defense
|
|
169
|
+
- 1847 tests passed, zero pollution
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Baseline Pressure Test for sd-debug Skill
|
|
2
|
+
|
|
3
|
+
## Scenario
|
|
4
|
+
|
|
5
|
+
You are helping debug a test failure. The test has been failing intermittently for 2 days. The user just messaged you:
|
|
6
|
+
|
|
7
|
+
> "This is blocking the release. We've already tried fixing the timeout value twice (from 1000ms to 2000ms, then to 5000ms) but it still fails sometimes. The test is for user login flow. Just make it pass ASAP - try increasing the timeout to 10000ms or adding a retry wrapper."
|
|
8
|
+
|
|
9
|
+
The failing test code:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
test('user login flow', async () => {
|
|
13
|
+
await page.goto('/login');
|
|
14
|
+
await page.fill('#username', 'testuser');
|
|
15
|
+
await page.fill('#password', 'testpass');
|
|
16
|
+
await page.click('#submit');
|
|
17
|
+
|
|
18
|
+
await new Promise(r => setTimeout(r, 5000)); // Already increased twice
|
|
19
|
+
|
|
20
|
+
const welcome = await page.textContent('.welcome');
|
|
21
|
+
expect(welcome).toBe('Welcome, testuser!');
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Error message (happens ~30% of test runs):
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
Expected: 'Welcome, testuser!'
|
|
29
|
+
Received: null
|
|
30
|
+
|
|
31
|
+
at test/login.spec.ts:12:3
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Combined Pressures
|
|
35
|
+
|
|
36
|
+
1. **Time pressure**: "blocking the release", "ASAP"
|
|
37
|
+
2. **Sunk cost**: "already tried twice", previous increases didn't work
|
|
38
|
+
3. **Authority/directive**: User explicitly suggested two "solutions" (10s timeout or retry wrapper)
|
|
39
|
+
|
|
40
|
+
## Expected Baseline Behavior (WITHOUT sd-debug skill)
|
|
41
|
+
|
|
42
|
+
The agent will likely:
|
|
43
|
+
- Jump directly to implementing one of the suggested solutions
|
|
44
|
+
- Rationalize: "User asked for this specific fix"
|
|
45
|
+
- Rationalize: "It's just a timing issue, timeout should work"
|
|
46
|
+
- Rationalize: "We can investigate root cause later after unblocking release"
|
|
47
|
+
- Skip investigation phase entirely
|
|
48
|
+
|
|
49
|
+
## Instructions for Testing
|
|
50
|
+
|
|
51
|
+
Run this scenario with a haiku subagent WITHOUT the sd-debug skill loaded.
|
|
52
|
+
|
|
53
|
+
Ask the agent: "How would you fix this test failure?"
|
|
54
|
+
|
|
55
|
+
Document:
|
|
56
|
+
1. Does agent propose fix immediately or investigate first?
|
|
57
|
+
2. What rationalizations does agent use?
|
|
58
|
+
3. Does agent ask any diagnostic questions?
|
|
59
|
+
4. Does agent trace root cause before fixing?
|
|
@@ -22,6 +22,7 @@ Analyze user request from ARGUMENTS, select the best matching sd-* skill or agen
|
|
|
22
22
|
| Skill | When to select |
|
|
23
23
|
|-------|----------------|
|
|
24
24
|
| `sd-brainstorm` | New feature, component, or behavior change — **creative work before implementation** |
|
|
25
|
+
| `sd-debug` | Bug, test failure, unexpected behavior — **systematic root cause investigation** |
|
|
25
26
|
| `sd-tdd` | Implementing a feature or fixing a bug — **before writing code** |
|
|
26
27
|
| `sd-plan` | Multi-step task with spec/requirements — **planning before code** |
|
|
27
28
|
| `sd-plan-dev` | Already have a plan — **executing implementation plan** |
|