sdtk-code-kit 0.1.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.
Files changed (55) hide show
  1. package/README.md +138 -0
  2. package/assets/manifest/toolkit-bundle.manifest.json +147 -0
  3. package/assets/manifest/toolkit-bundle.sha256.txt +28 -0
  4. package/assets/toolkit/toolkit/AGENTS.md +210 -0
  5. package/assets/toolkit/toolkit/install.ps1 +126 -0
  6. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -0
  7. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +127 -0
  8. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -0
  9. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +53 -0
  10. package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -0
  11. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -0
  12. package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +56 -0
  13. package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +297 -0
  14. package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +69 -0
  15. package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -0
  16. package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +75 -0
  17. package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +206 -0
  18. package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +65 -0
  19. package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +27 -0
  20. package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +114 -0
  21. package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +62 -0
  22. package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +86 -0
  23. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +80 -0
  24. package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +126 -0
  25. package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +147 -0
  26. package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +53 -0
  27. package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +379 -0
  28. package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +300 -0
  29. package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +145 -0
  30. package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +229 -0
  31. package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +112 -0
  32. package/bin/sdtk-code.js +14 -0
  33. package/package.json +44 -0
  34. package/src/commands/build.js +53 -0
  35. package/src/commands/generate.js +11 -0
  36. package/src/commands/help.js +169 -0
  37. package/src/commands/init.js +86 -0
  38. package/src/commands/plan.js +52 -0
  39. package/src/commands/runtime.js +205 -0
  40. package/src/commands/ship.js +54 -0
  41. package/src/commands/start.js +89 -0
  42. package/src/commands/verify.js +57 -0
  43. package/src/index.js +70 -0
  44. package/src/lib/args.js +107 -0
  45. package/src/lib/errors.js +41 -0
  46. package/src/lib/powershell.js +65 -0
  47. package/src/lib/scope.js +55 -0
  48. package/src/lib/toolkit-payload.js +72 -0
  49. package/src/lib/workflow-artifact.js +453 -0
  50. package/src/lib/workflow-build.js +127 -0
  51. package/src/lib/workflow-handoff.js +427 -0
  52. package/src/lib/workflow-intake.js +100 -0
  53. package/src/lib/workflow-plan.js +96 -0
  54. package/src/lib/workflow-ship.js +163 -0
  55. package/src/lib/workflow-verify.js +212 -0
@@ -0,0 +1,78 @@
1
+ param(
2
+ [string]$ProjectPath,
3
+ [ValidateSet('project', 'user')]
4
+ [string]$Scope = 'project',
5
+ [switch]$Force,
6
+ [switch]$Quiet
7
+ )
8
+
9
+ $ErrorActionPreference = 'Stop'
10
+ Set-StrictMode -Version Latest
11
+
12
+ $toolkitRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
13
+ $skillsSource = Join-Path $toolkitRoot 'skills'
14
+ if (-not (Test-Path -LiteralPath $skillsSource)) {
15
+ throw "Missing toolkit skills source directory: $skillsSource"
16
+ }
17
+
18
+ $managedSkills = @(Get-ChildItem -LiteralPath $skillsSource -Directory | Sort-Object Name)
19
+ if ($managedSkills.Count -ne 12) {
20
+ throw "Expected 12 managed SDTK-CODE skills but found $($managedSkills.Count)."
21
+ }
22
+
23
+ if ($Scope -eq 'user') {
24
+ $skillsDest = Join-Path $HOME '.claude/skills'
25
+ } else {
26
+ if (-not $ProjectPath) {
27
+ throw "ProjectPath is required for Claude project scope installation."
28
+ }
29
+ $projectRoot = (Resolve-Path -LiteralPath $ProjectPath).Path
30
+ $skillsDest = Join-Path $projectRoot '.claude/skills'
31
+ }
32
+
33
+ New-Item -ItemType Directory -Force -Path $skillsDest | Out-Null
34
+
35
+ $copied = 0
36
+ $skipped = 0
37
+ foreach ($skillDir in $managedSkills) {
38
+ $skillFile = Join-Path $skillDir.FullName 'SKILL.md'
39
+ if (-not (Test-Path -LiteralPath $skillFile)) {
40
+ throw "Managed skill is missing SKILL.md: $($skillDir.FullName)"
41
+ }
42
+
43
+ $destDir = Join-Path $skillsDest $skillDir.Name
44
+ if (Test-Path -LiteralPath $destDir) {
45
+ if (-not $Force) {
46
+ $skipped++
47
+ if (-not $Quiet) {
48
+ Write-Warning "Skill already installed (skipping). Use -Force to overwrite: $($skillDir.Name)"
49
+ }
50
+ continue
51
+ }
52
+ Remove-Item -LiteralPath $destDir -Recurse -Force
53
+ }
54
+
55
+ Copy-Item -LiteralPath $skillDir.FullName -Destination $destDir -Recurse -Force
56
+ $copied++
57
+ if (-not $Quiet) {
58
+ Write-Host "Installed: $($skillDir.Name)"
59
+ }
60
+ }
61
+
62
+ $installedNow = @(
63
+ Get-ChildItem -LiteralPath $skillsDest -Directory -ErrorAction SilentlyContinue |
64
+ Where-Object { $managedSkills.Name -contains $_.Name } |
65
+ Select-Object -ExpandProperty Name
66
+ )
67
+ if ($installedNow.Count -ne 12) {
68
+ throw "Claude skill install incomplete. Expected 12 managed skills at $skillsDest but found $($installedNow.Count)."
69
+ }
70
+
71
+ if (-not $Quiet) {
72
+ Write-Host ""
73
+ Write-Host "Install summary:"
74
+ Write-Host "- Scope: $Scope"
75
+ Write-Host "- Destination: $skillsDest"
76
+ Write-Host "- Copied: $copied"
77
+ Write-Host "- Skipped: $skipped"
78
+ }
@@ -0,0 +1,127 @@
1
+ param(
2
+ [ValidateSet('project', 'user')]
3
+ [string]$Scope = 'user',
4
+ [switch]$Force,
5
+ [switch]$Quiet
6
+ )
7
+
8
+ if ($Scope -eq 'project') {
9
+ Write-Error "Codex does not support project-local skills. Use -Scope user instead."
10
+ exit 1
11
+ }
12
+
13
+ $ErrorActionPreference = 'Stop'
14
+ Set-StrictMode -Version Latest
15
+
16
+ function Write-Utf8NoBomFile {
17
+ param(
18
+ [Parameter(Mandatory = $true)][string]$Path,
19
+ [Parameter(Mandatory = $true)][string]$Content
20
+ )
21
+
22
+ $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
23
+ [System.IO.File]::WriteAllText($Path, $Content, $utf8NoBom)
24
+ }
25
+
26
+ function Rewrite-SkillFrontmatterName {
27
+ param(
28
+ [Parameter(Mandatory = $true)][string]$SkillFilePath,
29
+ [Parameter(Mandatory = $true)][string]$ExpectedName
30
+ )
31
+
32
+ $content = Get-Content -LiteralPath $SkillFilePath -Raw -Encoding UTF8
33
+ $newline = if ($content.Contains("`r`n")) { "`r`n" } else { "`n" }
34
+ $match = [regex]::Match(
35
+ $content,
36
+ '\A(?<prefix>\s*(?:<!--[\s\S]*?-->\s*)?)---\r?\n(?<frontmatter>[\s\S]*?)\r?\n---(?<suffix>[\s\S]*)\z'
37
+ )
38
+ if (-not $match.Success) {
39
+ throw "Skill file is missing a valid YAML frontmatter block: $SkillFilePath"
40
+ }
41
+
42
+ $frontmatter = $match.Groups['frontmatter'].Value
43
+ if ($frontmatter -notmatch '(?m)^name:\s*(?<name>[^\r\n]+)\s*$') {
44
+ throw "Skill file is missing a frontmatter name field: $SkillFilePath"
45
+ }
46
+
47
+ $updatedFrontmatter = [regex]::Replace(
48
+ $frontmatter,
49
+ '(?m)^name:\s*[^\r\n]+\s*$',
50
+ "name: $ExpectedName",
51
+ 1
52
+ )
53
+
54
+ $updatedContent = $match.Groups['prefix'].Value + '---' + $newline + $updatedFrontmatter + $newline + '---' + $match.Groups['suffix'].Value
55
+ Write-Utf8NoBomFile -Path $SkillFilePath -Content $updatedContent
56
+ }
57
+
58
+ $toolkitRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
59
+ $skillsSource = Join-Path $toolkitRoot 'skills'
60
+ if (-not (Test-Path -LiteralPath $skillsSource)) {
61
+ throw "Missing toolkit skills source directory: $skillsSource"
62
+ }
63
+
64
+ $managedSkills = @(Get-ChildItem -LiteralPath $skillsSource -Directory | Sort-Object Name)
65
+ if ($managedSkills.Count -ne 12) {
66
+ throw "Expected 12 managed SDTK-CODE skills but found $($managedSkills.Count)."
67
+ }
68
+
69
+ $codexHome = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $HOME '.codex' }
70
+ $skillsDest = Join-Path $codexHome 'skills'
71
+ New-Item -ItemType Directory -Force -Path $skillsDest | Out-Null
72
+
73
+ $copied = 0
74
+ $skipped = 0
75
+ foreach ($skillDir in $managedSkills) {
76
+ $skillFile = Join-Path $skillDir.FullName 'SKILL.md'
77
+ if (-not (Test-Path -LiteralPath $skillFile)) {
78
+ throw "Managed skill is missing SKILL.md: $($skillDir.FullName)"
79
+ }
80
+
81
+ $destName = "sdtk-$($skillDir.Name)"
82
+ $destDir = Join-Path $skillsDest $destName
83
+ if (Test-Path -LiteralPath $destDir) {
84
+ if (-not $Force) {
85
+ $skipped++
86
+ if (-not $Quiet) {
87
+ Write-Warning "Skill already installed (skipping). Use -Force to overwrite: $destName"
88
+ }
89
+ continue
90
+ }
91
+ Remove-Item -LiteralPath $destDir -Recurse -Force
92
+ }
93
+
94
+ Copy-Item -LiteralPath $skillDir.FullName -Destination $destDir -Recurse -Force
95
+ try {
96
+ Rewrite-SkillFrontmatterName -SkillFilePath (Join-Path $destDir 'SKILL.md') -ExpectedName $destName
97
+ } catch {
98
+ if (Test-Path -LiteralPath $destDir) {
99
+ Remove-Item -LiteralPath $destDir -Recurse -Force
100
+ }
101
+ throw
102
+ }
103
+
104
+ $copied++
105
+ if (-not $Quiet) {
106
+ Write-Host "Installed: $destName"
107
+ }
108
+ }
109
+
110
+ $expectedNames = $managedSkills.Name | ForEach-Object { "sdtk-$_" }
111
+ $installedNow = @(
112
+ Get-ChildItem -LiteralPath $skillsDest -Directory -ErrorAction SilentlyContinue |
113
+ Where-Object { $expectedNames -contains $_.Name } |
114
+ Select-Object -ExpandProperty Name
115
+ )
116
+ if ($installedNow.Count -ne 12) {
117
+ throw "Codex skill install incomplete. Expected 12 managed skills at $skillsDest but found $($installedNow.Count)."
118
+ }
119
+
120
+ if (-not $Quiet) {
121
+ Write-Host ""
122
+ Write-Host "Install summary:"
123
+ Write-Host "- Scope: user"
124
+ Write-Host "- Destination: $skillsDest"
125
+ Write-Host "- Copied: $copied"
126
+ Write-Host "- Skipped: $skipped"
127
+ }
@@ -0,0 +1,62 @@
1
+ param(
2
+ [string]$ProjectPath,
3
+ [ValidateSet('project', 'user')]
4
+ [string]$Scope = 'project',
5
+ [switch]$All,
6
+ [switch]$Quiet
7
+ )
8
+
9
+ $ErrorActionPreference = 'Stop'
10
+ Set-StrictMode -Version Latest
11
+
12
+ $toolkitRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
13
+ $skillsSource = Join-Path $toolkitRoot 'skills'
14
+ if (-not (Test-Path -LiteralPath $skillsSource)) {
15
+ throw "Missing toolkit skills source directory: $skillsSource"
16
+ }
17
+
18
+ $managedSkillNames = @(
19
+ Get-ChildItem -LiteralPath $skillsSource -Directory | Sort-Object Name | Select-Object -ExpandProperty Name
20
+ )
21
+ if ($managedSkillNames.Count -ne 12) {
22
+ throw "Expected 12 managed SDTK-CODE skills but found $($managedSkillNames.Count)."
23
+ }
24
+
25
+ if ($Scope -eq 'user') {
26
+ $skillsDest = Join-Path $HOME '.claude/skills'
27
+ } else {
28
+ if (-not $ProjectPath) {
29
+ throw "ProjectPath is required for Claude project scope uninstall."
30
+ }
31
+ $projectRoot = (Resolve-Path -LiteralPath $ProjectPath).Path
32
+ $skillsDest = Join-Path $projectRoot '.claude/skills'
33
+ }
34
+
35
+ if (-not (Test-Path -LiteralPath $skillsDest)) {
36
+ if (-not $Quiet) {
37
+ Write-Host "Claude skills directory not found: $skillsDest"
38
+ }
39
+ exit 0
40
+ }
41
+
42
+ $removed = New-Object System.Collections.Generic.List[string]
43
+ $missing = New-Object System.Collections.Generic.List[string]
44
+ foreach ($name in $managedSkillNames) {
45
+ $dest = Join-Path $skillsDest $name
46
+ if (-not (Test-Path -LiteralPath $dest)) {
47
+ $missing.Add($name) | Out-Null
48
+ continue
49
+ }
50
+
51
+ Remove-Item -LiteralPath $dest -Recurse -Force
52
+ $removed.Add($name) | Out-Null
53
+ }
54
+
55
+ if (-not $Quiet) {
56
+ Write-Host ""
57
+ Write-Host "Uninstall summary:"
58
+ Write-Host "- Scope: $Scope"
59
+ Write-Host "- Destination: $skillsDest"
60
+ Write-Host "- Removed: $($removed.Count)"
61
+ Write-Host "- Missing/Skipped: $($missing.Count)"
62
+ }
@@ -0,0 +1,53 @@
1
+ param(
2
+ [switch]$All,
3
+ [switch]$Quiet
4
+ )
5
+
6
+ $ErrorActionPreference = 'Stop'
7
+ Set-StrictMode -Version Latest
8
+
9
+ $toolkitRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
10
+ $skillsSource = Join-Path $toolkitRoot 'skills'
11
+ if (-not (Test-Path -LiteralPath $skillsSource)) {
12
+ throw "Missing toolkit skills source directory: $skillsSource"
13
+ }
14
+
15
+ $managedSkillNames = @(
16
+ Get-ChildItem -LiteralPath $skillsSource -Directory |
17
+ Sort-Object Name |
18
+ ForEach-Object { "sdtk-$($_.Name)" }
19
+ )
20
+ if ($managedSkillNames.Count -ne 12) {
21
+ throw "Expected 12 managed SDTK-CODE skills but found $($managedSkillNames.Count)."
22
+ }
23
+
24
+ $codexHome = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $HOME '.codex' }
25
+ $skillsDest = Join-Path $codexHome 'skills'
26
+ if (-not (Test-Path -LiteralPath $skillsDest)) {
27
+ if (-not $Quiet) {
28
+ Write-Host "Codex skills directory not found: $skillsDest"
29
+ }
30
+ exit 0
31
+ }
32
+
33
+ $removed = New-Object System.Collections.Generic.List[string]
34
+ $missing = New-Object System.Collections.Generic.List[string]
35
+ foreach ($name in $managedSkillNames) {
36
+ $dest = Join-Path $skillsDest $name
37
+ if (-not (Test-Path -LiteralPath $dest)) {
38
+ $missing.Add($name) | Out-Null
39
+ continue
40
+ }
41
+
42
+ Remove-Item -LiteralPath $dest -Recurse -Force
43
+ $removed.Add($name) | Out-Null
44
+ }
45
+
46
+ if (-not $Quiet) {
47
+ Write-Host ""
48
+ Write-Host "Uninstall summary:"
49
+ Write-Host "- Scope: user"
50
+ Write-Host "- Destination: $skillsDest"
51
+ Write-Host "- Removed: $($removed.Count)"
52
+ Write-Host "- Missing/Skipped: $($missing.Count)"
53
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "toolkit": "SDTK-CODE",
3
+ "version": "0.1.0",
4
+ "skills_path": "toolkit/skills",
5
+ "skill_prefix": "code-"
6
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "$comment": "SCAFFOLD: Example profiles config for SDTKCODE. Copy to sdtk-spec.config.profiles.json and customize.",
3
+ "profiles": {
4
+ "default": {
5
+ "stack": {
6
+ "backend": "UPDATE_ME",
7
+ "frontend": "UPDATE_ME",
8
+ "database": "UPDATE_ME"
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,56 @@
1
+ <!-- Based on superpowers by Jesse Vincent (MIT License, 2025). Adapted for SDTK-CODE. See ../../THIRD_PARTY_NOTICES.md for details. -->
2
+ ---
3
+ name: code-brainstorm
4
+ description: Brainstorming designs before code. Use before any creative work -- creating features, building components, modifying behavior. Explores intent, requirements, and design before implementation.
5
+ ---
6
+
7
+ # Code Brainstorm
8
+
9
+ ## Critical Constraints
10
+ - I do not take implementation action before presenting a design and getting approval.
11
+ - I do not treat "simple" requests as justification to skip design.
12
+
13
+ <HARD-GATE>
14
+ Do NOT invoke any implementation skill, write any code, scaffold any project, or take any implementation action until you have presented a design and the user has approved it. This applies to EVERY project regardless of perceived simplicity.
15
+ </HARD-GATE>
16
+
17
+ ## Overview
18
+ Explore coding approaches before writing code.
19
+
20
+ The outcome is an approved design direction that can be handed to `code-plan`.
21
+
22
+ ## Process
23
+ 1. Read the current codebase context, recent changes, and relevant requirements.
24
+ 2. Ask clarifying questions one at a time.
25
+ 3. Propose 2-3 approaches with tradeoffs and a recommendation.
26
+ 4. Present the design in sections sized to the problem complexity.
27
+ 5. Record assumptions and open questions.
28
+ 6. Get approval on the design direction.
29
+ 7. Hand off to `code-plan`.
30
+
31
+ ## Process Flow
32
+ ```dot
33
+ digraph brainstorming {
34
+ "Explore project context" [shape=box];
35
+ "Ask clarifying questions" [shape=box];
36
+ "Propose 2-3 approaches" [shape=box];
37
+ "Present design sections" [shape=box];
38
+ "User approves design?" [shape=diamond];
39
+ "Revise design" [shape=box];
40
+ "Invoke code-plan" [shape=doublecircle];
41
+
42
+ "Explore project context" -> "Ask clarifying questions";
43
+ "Ask clarifying questions" -> "Propose 2-3 approaches";
44
+ "Propose 2-3 approaches" -> "Present design sections";
45
+ "Present design sections" -> "User approves design?";
46
+ "User approves design?" -> "Revise design" [label="no"];
47
+ "Revise design" -> "Present design sections";
48
+ "User approves design?" -> "Invoke code-plan" [label="yes"];
49
+ }
50
+ ```
51
+
52
+ ## Red Flags
53
+ - Starting code because the request looks small.
54
+ - Asking multiple unrelated questions in one turn.
55
+ - Offering only one approach when there are real tradeoffs.
56
+ - Moving to implementation before the design is approved.
@@ -0,0 +1,297 @@
1
+ <!-- Based on superpowers by Jesse Vincent (MIT License, 2025). Adapted for SDTK-CODE. See ../../THIRD_PARTY_NOTICES.md for details. -->
2
+ ---
3
+ name: code-debug
4
+ description: Systematic debugging. Use when encountering any bug, test failure, or unexpected behavior -- binary search to root cause, evidence-first, no guessing fixes.
5
+ ---
6
+
7
+ # Code Debug
8
+
9
+ ## Critical Constraints
10
+ - I do not propose or apply fixes before tracing the problem to a root cause.
11
+ - I do not stack speculative fixes on top of each other to see what sticks.
12
+
13
+
14
+ ## Overview
15
+ Random fixes waste time and create new bugs. Quick patches mask underlying issues.
16
+
17
+ **Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
18
+
19
+ **Violating the letter of this process is violating the spirit of debugging.**
20
+
21
+ ## Procedure
22
+ Follow the four phases in order: investigate root cause, compare against working patterns, form one hypothesis, then implement the smallest fix with proof. If evidence is incomplete, return to investigation instead of proposing another fix.
23
+
24
+ ## The Iron Law
25
+
26
+ ```
27
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
28
+ ```
29
+
30
+ If you haven't completed Phase 1, you cannot propose fixes.
31
+
32
+ ## When to Use
33
+
34
+ Use for ANY technical issue:
35
+ - Test failures
36
+ - Bugs in production
37
+ - Unexpected behavior
38
+ - Performance problems
39
+ - Build failures
40
+ - Integration issues
41
+
42
+ **Use this ESPECIALLY when:**
43
+ - Under time pressure (emergencies make guessing tempting)
44
+ - "Just one quick fix" seems obvious
45
+ - You've already tried multiple fixes
46
+ - Previous fix didn't work
47
+ - You don't fully understand the issue
48
+
49
+ **Don't skip when:**
50
+ - Issue seems simple (simple bugs have root causes too)
51
+ - You're in a hurry (rushing guarantees rework)
52
+ - Manager wants it fixed NOW (systematic is faster than thrashing)
53
+
54
+ ## The Four Phases
55
+
56
+ You MUST complete each phase before proceeding to the next.
57
+
58
+ ### Phase 1: Root Cause Investigation
59
+
60
+ **BEFORE attempting ANY fix:**
61
+
62
+ 1. **Read Error Messages Carefully**
63
+ - Don't skip past errors or warnings
64
+ - They often contain the exact solution
65
+ - Read stack traces completely
66
+ - Note line numbers, file paths, error codes
67
+
68
+ 2. **Reproduce Consistently**
69
+ - Can you trigger it reliably?
70
+ - What are the exact steps?
71
+ - Does it happen every time?
72
+ - If not reproducible -> gather more data, don't guess
73
+
74
+ 3. **Check Recent Changes**
75
+ - What changed that could cause this?
76
+ - Git diff, recent commits
77
+ - New dependencies, config changes
78
+ - Environmental differences
79
+
80
+ 4. **Gather Evidence in Multi-Component Systems**
81
+
82
+ **WHEN system has multiple components (CI -> build -> signing, API -> service -> database):**
83
+
84
+ **BEFORE proposing fixes, add diagnostic instrumentation:**
85
+ ```
86
+ For EACH component boundary:
87
+ - Log what data enters component
88
+ - Log what data exits component
89
+ - Verify environment/config propagation
90
+ - Check state at each layer
91
+
92
+ Run once to gather evidence showing WHERE it breaks
93
+ THEN analyze evidence to identify failing component
94
+ THEN investigate that specific component
95
+ ```
96
+
97
+ **Example (multi-layer system):**
98
+ ```bash
99
+ # Layer 1: Workflow
100
+ echo "=== Secrets available in workflow: ==="
101
+ echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
102
+
103
+ # Layer 2: Build script
104
+ echo "=== Env vars in build script: ==="
105
+ env | grep IDENTITY || echo "IDENTITY not in environment"
106
+
107
+ # Layer 3: Signing script
108
+ echo "=== Keychain state: ==="
109
+ security list-keychains
110
+ security find-identity -v
111
+
112
+ # Layer 4: Actual signing
113
+ codesign --sign "$IDENTITY" --verbose=4 "$APP"
114
+ ```
115
+
116
+ **This reveals:** Which layer fails (secrets -> workflow , workflow -> build )
117
+
118
+ 5. **Trace Data Flow**
119
+
120
+ **WHEN error is deep in call stack:**
121
+
122
+ See `./references/root-cause-tracing.md` in this directory for the complete backward tracing technique.
123
+
124
+ **Quick version:**
125
+ - Where does bad value originate?
126
+ - What called this with bad value?
127
+ - Keep tracing up until you find the source
128
+ - Fix at source, not at symptom
129
+
130
+ ### Phase 2: Pattern Analysis
131
+
132
+ **Find the pattern before fixing:**
133
+
134
+ 1. **Find Working Examples**
135
+ - Locate similar working code in same codebase
136
+ - What works that's similar to what's broken?
137
+
138
+ 2. **Compare Against References**
139
+ - If implementing pattern, read reference implementation COMPLETELY
140
+ - Don't skim - read every line
141
+ - Understand the pattern fully before applying
142
+
143
+ 3. **Identify Differences**
144
+ - What's different between working and broken?
145
+ - List every difference, however small
146
+ - Don't assume "that can't matter"
147
+
148
+ 4. **Understand Dependencies**
149
+ - What other components does this need?
150
+ - What settings, config, environment?
151
+ - What assumptions does it make?
152
+
153
+ ### Phase 3: Hypothesis and Testing
154
+
155
+ **Scientific method:**
156
+
157
+ 1. **Form Single Hypothesis**
158
+ - State clearly: "I think X is the root cause because Y"
159
+ - Write it down
160
+ - Be specific, not vague
161
+
162
+ 2. **Test Minimally**
163
+ - Make the SMALLEST possible change to test hypothesis
164
+ - One variable at a time
165
+ - Don't fix multiple things at once
166
+
167
+ 3. **Verify Before Continuing**
168
+ - Did it work? Yes -> Phase 4
169
+ - Didn't work? Form NEW hypothesis
170
+ - DON'T add more fixes on top
171
+
172
+ 4. **When You Don't Know**
173
+ - Say "I don't understand X"
174
+ - Don't pretend to know
175
+ - Ask for help
176
+ - Research more
177
+
178
+ ### Phase 4: Implementation
179
+
180
+ **Fix the root cause, not the symptom:**
181
+
182
+ 1. **Create Failing Test Case**
183
+ - Simplest possible reproduction
184
+ - Automated test if possible
185
+ - One-off test script if no framework
186
+ - MUST have before fixing
187
+ - Use the `code-tdd` skill for writing proper failing tests
188
+
189
+ 2. **Implement Single Fix**
190
+ - Address the root cause identified
191
+ - ONE change at a time
192
+ - No "while I'm here" improvements
193
+ - No bundled refactoring
194
+
195
+ 3. **Verify Fix**
196
+ - Test passes now?
197
+ - No other tests broken?
198
+ - Issue actually resolved?
199
+
200
+ 4. **If Fix Doesn't Work**
201
+ - STOP
202
+ - Count: How many fixes have you tried?
203
+ - If < 3: Return to Phase 1, re-analyze with new information
204
+ - **If >= 3: STOP and question the architecture (step 5 below)**
205
+ - DON'T attempt Fix #4 without architectural discussion
206
+
207
+ 5. **If 3+ Fixes Failed: Question Architecture**
208
+
209
+ **Pattern indicating architectural problem:**
210
+ - Each fix reveals new shared state/coupling/problem in different place
211
+ - Fixes require "massive refactoring" to implement
212
+ - Each fix creates new symptoms elsewhere
213
+
214
+ **STOP and question fundamentals:**
215
+ - Is this pattern fundamentally sound?
216
+ - Are we "sticking with it through sheer inertia"?
217
+ - Should we refactor architecture vs. continue fixing symptoms?
218
+
219
+ **Discuss with the user before attempting more fixes**
220
+
221
+ This is NOT a failed hypothesis - this is a wrong architecture.
222
+
223
+ ## Red Flags - STOP and Follow Process
224
+
225
+ If you catch yourself thinking:
226
+ - "Quick fix for now, investigate later"
227
+ - "Just try changing X and see if it works"
228
+ - "Add multiple changes, run tests"
229
+ - "Skip the test, I'll manually verify"
230
+ - "It's probably X, let me fix that"
231
+ - "I don't fully understand but this might work"
232
+ - "Pattern says X but I'll adapt it differently"
233
+ - "Here are the main problems: [lists fixes without investigation]"
234
+ - Proposing solutions before tracing data flow
235
+ - **"One more fix attempt" (when already tried 2+)**
236
+ - **Each fix reveals new problem in different place**
237
+
238
+ **ALL of these mean: STOP. Return to Phase 1.**
239
+
240
+ **If 3+ fixes failed:** Question the architecture (see Phase 4.5)
241
+
242
+ ## Signals You Are Doing It Wrong
243
+
244
+ **Watch for these redirections:**
245
+ - "Is that not happening?" - You assumed without verifying
246
+ - "Will it show us...?" - You should have added evidence gathering
247
+ - "Stop guessing" - You're proposing fixes without understanding
248
+ - "Ultrathink this" - Question fundamentals, not just symptoms
249
+ - "We're stuck?" (frustrated) - Your approach isn't working
250
+
251
+ **When you see these:** STOP. Return to Phase 1.
252
+
253
+ ## Common Rationalizations
254
+
255
+ | Excuse | Reality |
256
+ |--------|---------|
257
+ | "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
258
+ | "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
259
+ | "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
260
+ | "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
261
+ | "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
262
+ | "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
263
+ | "I see the problem, let me fix it" | Seeing symptoms is not the same as understanding root cause. |
264
+ | "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
265
+
266
+ ## Quick Reference
267
+
268
+ | Phase | Key Activities | Success Criteria |
269
+ |-------|---------------|------------------|
270
+ | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
271
+ | **2. Pattern** | Find working examples, compare | Identify differences |
272
+ | **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
273
+ | **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
274
+
275
+ ## When Process Reveals "No Root Cause"
276
+
277
+ If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
278
+
279
+ 1. You've completed the process
280
+ 2. Document what you investigated
281
+ 3. Implement appropriate handling (retry, timeout, error message)
282
+ 4. Add monitoring/logging for future investigation
283
+
284
+ **But:** 95% of "no root cause" cases are incomplete investigation.
285
+
286
+ ## Supporting Techniques
287
+
288
+ Use `./references/root-cause-tracing.md` to trace bugs backward through the call chain until the original trigger is found.
289
+
290
+ **Related skills:**
291
+ - **code-tdd** - For creating failing test case (Phase 4, Step 1)
292
+ - **code-verify** - Verify fix worked before claiming success
293
+
294
+ ## Real-World Impact
295
+
296
+ From debugging sessions:
297
+ - Systematic debugging minimizes thrash, increases first-time fix rate, and reduces new bugs introduced by speculative patches.