specweave 0.32.0 β†’ 0.32.2

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 (191) hide show
  1. package/CLAUDE.md +176 -2
  2. package/README.md +22 -0
  3. package/bin/specweave.js +18 -1
  4. package/dist/src/cli/commands/cache.d.ts +17 -0
  5. package/dist/src/cli/commands/cache.d.ts.map +1 -0
  6. package/dist/src/cli/commands/cache.js +126 -0
  7. package/dist/src/cli/commands/cache.js.map +1 -0
  8. package/dist/src/cli/commands/init.js +1 -1
  9. package/dist/src/cli/commands/init.js.map +1 -1
  10. package/dist/src/cli/commands/plan/increment-detector.js +2 -2
  11. package/dist/src/cli/commands/plan/increment-detector.js.map +1 -1
  12. package/dist/src/cli/commands/sync-spec-commits.js +1 -1
  13. package/dist/src/cli/commands/sync-spec-commits.js.map +1 -1
  14. package/dist/src/cli/commands/sync-specs.js +2 -2
  15. package/dist/src/cli/commands/sync-specs.js.map +1 -1
  16. package/dist/src/cli/helpers/github/increment-profile-selector.js +1 -1
  17. package/dist/src/cli/helpers/github/increment-profile-selector.js.map +1 -1
  18. package/dist/src/cli/workers/living-docs-worker.js +66 -1
  19. package/dist/src/cli/workers/living-docs-worker.js.map +1 -1
  20. package/dist/src/config/types.d.ts +203 -1208
  21. package/dist/src/config/types.d.ts.map +1 -1
  22. package/dist/src/core/discrepancy/increment-generator.d.ts.map +1 -1
  23. package/dist/src/core/discrepancy/increment-generator.js +5 -2
  24. package/dist/src/core/discrepancy/increment-generator.js.map +1 -1
  25. package/dist/src/core/increment/duplicate-detector.js +2 -2
  26. package/dist/src/core/increment/duplicate-detector.js.map +1 -1
  27. package/dist/src/core/increment/increment-archiver.d.ts +24 -0
  28. package/dist/src/core/increment/increment-archiver.d.ts.map +1 -1
  29. package/dist/src/core/increment/increment-archiver.js +59 -2
  30. package/dist/src/core/increment/increment-archiver.js.map +1 -1
  31. package/dist/src/core/increment/increment-status.js +2 -2
  32. package/dist/src/core/increment/increment-status.js.map +1 -1
  33. package/dist/src/core/increment/increment-utils.d.ts +85 -0
  34. package/dist/src/core/increment/increment-utils.d.ts.map +1 -1
  35. package/dist/src/core/increment/increment-utils.js +102 -4
  36. package/dist/src/core/increment/increment-utils.js.map +1 -1
  37. package/dist/src/core/increment/metadata-validator.js +1 -1
  38. package/dist/src/core/increment/metadata-validator.js.map +1 -1
  39. package/dist/src/core/living-docs/feature-id-manager.js +1 -1
  40. package/dist/src/core/living-docs/feature-id-manager.js.map +1 -1
  41. package/dist/src/core/living-docs/hierarchy-mapper.js +3 -3
  42. package/dist/src/core/living-docs/hierarchy-mapper.js.map +1 -1
  43. package/dist/src/core/living-docs/intelligent-analyzer/architecture-generator.d.ts +18 -0
  44. package/dist/src/core/living-docs/intelligent-analyzer/architecture-generator.d.ts.map +1 -0
  45. package/dist/src/core/living-docs/intelligent-analyzer/architecture-generator.js +247 -0
  46. package/dist/src/core/living-docs/intelligent-analyzer/architecture-generator.js.map +1 -0
  47. package/dist/src/core/living-docs/intelligent-analyzer/deep-repo-analyzer.d.ts +15 -0
  48. package/dist/src/core/living-docs/intelligent-analyzer/deep-repo-analyzer.d.ts.map +1 -0
  49. package/dist/src/core/living-docs/intelligent-analyzer/deep-repo-analyzer.js +138 -0
  50. package/dist/src/core/living-docs/intelligent-analyzer/deep-repo-analyzer.js.map +1 -0
  51. package/dist/src/core/living-docs/intelligent-analyzer/file-sampler.d.ts +24 -0
  52. package/dist/src/core/living-docs/intelligent-analyzer/file-sampler.d.ts.map +1 -0
  53. package/dist/src/core/living-docs/intelligent-analyzer/file-sampler.js +198 -0
  54. package/dist/src/core/living-docs/intelligent-analyzer/file-sampler.js.map +1 -0
  55. package/dist/src/core/living-docs/intelligent-analyzer/inconsistency-detector.d.ts +17 -0
  56. package/dist/src/core/living-docs/intelligent-analyzer/inconsistency-detector.d.ts.map +1 -0
  57. package/dist/src/core/living-docs/intelligent-analyzer/inconsistency-detector.js +241 -0
  58. package/dist/src/core/living-docs/intelligent-analyzer/inconsistency-detector.js.map +1 -0
  59. package/dist/src/core/living-docs/intelligent-analyzer/index.d.ts +28 -0
  60. package/dist/src/core/living-docs/intelligent-analyzer/index.d.ts.map +1 -0
  61. package/dist/src/core/living-docs/intelligent-analyzer/index.js +197 -0
  62. package/dist/src/core/living-docs/intelligent-analyzer/index.js.map +1 -0
  63. package/dist/src/core/living-docs/intelligent-analyzer/organization-synthesizer.d.ts +18 -0
  64. package/dist/src/core/living-docs/intelligent-analyzer/organization-synthesizer.d.ts.map +1 -0
  65. package/dist/src/core/living-docs/intelligent-analyzer/organization-synthesizer.js +154 -0
  66. package/dist/src/core/living-docs/intelligent-analyzer/organization-synthesizer.js.map +1 -0
  67. package/dist/src/core/living-docs/intelligent-analyzer/strategy-generator.d.ts +42 -0
  68. package/dist/src/core/living-docs/intelligent-analyzer/strategy-generator.d.ts.map +1 -0
  69. package/dist/src/core/living-docs/intelligent-analyzer/strategy-generator.js +343 -0
  70. package/dist/src/core/living-docs/intelligent-analyzer/strategy-generator.js.map +1 -0
  71. package/dist/src/core/living-docs/intelligent-analyzer/types.d.ts +146 -0
  72. package/dist/src/core/living-docs/intelligent-analyzer/types.d.ts.map +1 -0
  73. package/dist/src/core/living-docs/intelligent-analyzer/types.js +7 -0
  74. package/dist/src/core/living-docs/intelligent-analyzer/types.js.map +1 -0
  75. package/dist/src/core/living-docs/living-docs-sync.d.ts +5 -0
  76. package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -1
  77. package/dist/src/core/living-docs/living-docs-sync.js +36 -2
  78. package/dist/src/core/living-docs/living-docs-sync.js.map +1 -1
  79. package/dist/src/core/sync/spec-increment-mapper.js +3 -3
  80. package/dist/src/core/sync/spec-increment-mapper.js.map +1 -1
  81. package/dist/src/importers/item-converter.d.ts +25 -0
  82. package/dist/src/importers/item-converter.d.ts.map +1 -1
  83. package/dist/src/importers/item-converter.js +135 -5
  84. package/dist/src/importers/item-converter.js.map +1 -1
  85. package/dist/src/init/architecture/types.d.ts +33 -140
  86. package/dist/src/init/architecture/types.d.ts.map +1 -1
  87. package/dist/src/init/compliance/types.d.ts +30 -27
  88. package/dist/src/init/compliance/types.d.ts.map +1 -1
  89. package/dist/src/init/repo/types.d.ts +11 -34
  90. package/dist/src/init/repo/types.d.ts.map +1 -1
  91. package/dist/src/init/research/src/config/types.d.ts +15 -82
  92. package/dist/src/init/research/src/config/types.d.ts.map +1 -1
  93. package/dist/src/init/research/types.d.ts +38 -93
  94. package/dist/src/init/research/types.d.ts.map +1 -1
  95. package/dist/src/init/team/types.d.ts +4 -42
  96. package/dist/src/init/team/types.d.ts.map +1 -1
  97. package/dist/src/types/dashboard-cache.d.ts +181 -0
  98. package/dist/src/types/dashboard-cache.d.ts.map +1 -0
  99. package/dist/src/types/dashboard-cache.js +65 -0
  100. package/dist/src/types/dashboard-cache.js.map +1 -0
  101. package/dist/src/utils/docs-validator.d.ts +131 -0
  102. package/dist/src/utils/docs-validator.d.ts.map +1 -0
  103. package/dist/src/utils/docs-validator.js +529 -0
  104. package/dist/src/utils/docs-validator.js.map +1 -0
  105. package/dist/src/utils/feature-id-collision.js +1 -1
  106. package/dist/src/utils/feature-id-collision.js.map +1 -1
  107. package/dist/src/utils/html-to-mdx.d.ts +1 -0
  108. package/dist/src/utils/html-to-mdx.d.ts.map +1 -1
  109. package/dist/src/utils/html-to-mdx.js +43 -5
  110. package/dist/src/utils/html-to-mdx.js.map +1 -1
  111. package/package.json +1 -1
  112. package/plugins/specweave/agents/pm/AGENT.md +10 -7
  113. package/plugins/specweave/commands/specweave-archive-features.md +5 -7
  114. package/plugins/specweave/commands/specweave-archive.md +2 -1
  115. package/plugins/specweave/commands/specweave-do.md +35 -1
  116. package/plugins/specweave/commands/specweave-done.md +96 -0
  117. package/plugins/specweave/commands/specweave-import-external.md +45 -18
  118. package/plugins/specweave/commands/specweave-increment.md +331 -33
  119. package/plugins/specweave/commands/specweave-jobs.md +2 -2
  120. package/plugins/specweave/commands/specweave-progress.md +4 -4
  121. package/plugins/specweave/commands/specweave-restore-feature.md +5 -4
  122. package/plugins/specweave/commands/specweave-sync-docs.md +1 -1
  123. package/plugins/specweave/commands/specweave-sync-specs.md +216 -322
  124. package/plugins/specweave/commands/specweave-validate-features.md +13 -8
  125. package/plugins/specweave/hooks/docs-changed.sh.backup +79 -0
  126. package/plugins/specweave/hooks/hooks.json +33 -4
  127. package/plugins/specweave/hooks/human-input-required.sh.backup +75 -0
  128. package/plugins/specweave/hooks/lib/common-setup.sh +375 -0
  129. package/plugins/specweave/hooks/lib/crash-prevention.sh +336 -0
  130. package/plugins/specweave/hooks/post-first-increment.sh.backup +61 -0
  131. package/plugins/specweave/hooks/post-increment-change.sh.backup +98 -0
  132. package/plugins/specweave/hooks/post-increment-completion.sh.backup +231 -0
  133. package/plugins/specweave/hooks/post-increment-planning.sh.backup +1048 -0
  134. package/plugins/specweave/hooks/post-increment-status-change.sh.backup +147 -0
  135. package/plugins/specweave/hooks/post-spec-update.sh.backup +158 -0
  136. package/plugins/specweave/hooks/post-task-completion.sh +4 -23
  137. package/plugins/specweave/hooks/post-user-story-complete.sh.backup +179 -0
  138. package/plugins/specweave/hooks/pre-command-deduplication.sh +1 -6
  139. package/plugins/specweave/hooks/pre-command-deduplication.sh.backup +83 -0
  140. package/plugins/specweave/hooks/pre-implementation.sh.backup +67 -0
  141. package/plugins/specweave/hooks/pre-task-completion.sh +8 -37
  142. package/plugins/specweave/hooks/pre-task-completion.sh.backup +194 -0
  143. package/plugins/specweave/hooks/pre-tool-use.sh +2 -11
  144. package/plugins/specweave/hooks/pre-tool-use.sh.backup +133 -0
  145. package/plugins/specweave/hooks/universal/dispatcher.mjs +135 -42
  146. package/plugins/specweave/hooks/universal/fail-fast-wrapper.sh +183 -0
  147. package/plugins/specweave/hooks/user-prompt-submit.sh +140 -38
  148. package/plugins/specweave/hooks/user-prompt-submit.sh.backup +386 -0
  149. package/plugins/specweave/hooks/v2/dispatchers/post-tool-use.sh +12 -0
  150. package/plugins/specweave/hooks/v2/dispatchers/session-start.sh +89 -0
  151. package/plugins/specweave/hooks/v2/guards/bash-file-guard.sh +211 -0
  152. package/plugins/specweave/hooks/v2/guards/bash-file-guard.test.sh +163 -0
  153. package/plugins/specweave/hooks/v2/guards/completion-guard.sh +26 -28
  154. package/plugins/specweave/hooks/v2/guards/features-folder-guard.sh +50 -0
  155. package/plugins/specweave/lib/vendor/core/increment/duplicate-detector.js +2 -2
  156. package/plugins/specweave/lib/vendor/core/increment/duplicate-detector.js.map +1 -1
  157. package/plugins/specweave/scripts/README.md +166 -0
  158. package/plugins/specweave/scripts/cleanup-state.sh +142 -0
  159. package/plugins/specweave/scripts/force-kill.sh +142 -0
  160. package/plugins/specweave/scripts/jobs.js +171 -0
  161. package/plugins/specweave/scripts/progress.js +170 -0
  162. package/plugins/specweave/scripts/read-costs.sh +132 -0
  163. package/plugins/specweave/scripts/read-jobs.sh +324 -0
  164. package/plugins/specweave/scripts/read-progress.sh +185 -0
  165. package/plugins/specweave/scripts/read-status.sh +146 -0
  166. package/plugins/specweave/scripts/read-workflow.sh +173 -0
  167. package/plugins/specweave/scripts/rebuild-dashboard-cache.sh +327 -0
  168. package/plugins/specweave/scripts/session-watchdog.sh +192 -0
  169. package/plugins/specweave/scripts/status.js +154 -0
  170. package/plugins/specweave/scripts/update-dashboard-cache.sh +281 -0
  171. package/plugins/specweave/skills/increment-planner/SKILL.md +333 -24
  172. package/plugins/specweave/skills/increment-planner/templates/spec-multi-project.md +17 -9
  173. package/plugins/specweave/skills/increment-planner/templates/spec-single-project.md +6 -2
  174. package/plugins/specweave/skills/instant-status/SKILL.md +70 -0
  175. package/plugins/specweave-ado/hooks/post-living-docs-update.sh.backup +353 -0
  176. package/plugins/specweave-ado/hooks/post-task-completion.sh.backup +172 -0
  177. package/plugins/specweave-ado/lib/enhanced-ado-sync.js +170 -0
  178. package/plugins/specweave-docs/commands/build.md +32 -4
  179. package/plugins/specweave-docs/commands/preview.md +43 -1
  180. package/plugins/specweave-docs/commands/validate.md +250 -0
  181. package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +1262 -0
  182. package/plugins/specweave-github/hooks/post-task-completion.sh.backup +258 -0
  183. package/plugins/specweave-github/lib/enhanced-github-sync.js +220 -0
  184. package/plugins/specweave-jira/hooks/post-task-completion.sh.backup +172 -0
  185. package/plugins/specweave-jira/lib/enhanced-jira-sync.js +134 -0
  186. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +1254 -0
  187. package/plugins/specweave-release/hooks/post-task-completion.sh.backup +110 -0
  188. package/plugins/specweave/hooks/post-edit-spec.sh +0 -265
  189. package/plugins/specweave/hooks/post-write-spec.sh +0 -267
  190. package/plugins/specweave/hooks/pre-edit-spec.sh +0 -151
  191. package/plugins/specweave/hooks/pre-write-spec.sh +0 -151
@@ -0,0 +1,166 @@
1
+ # SpecWeave Instant Scripts
2
+
3
+ **Blazingly fast status commands that bypass LLM processing.**
4
+
5
+ These scripts provide instant (<100ms) output for status queries that don't require AI reasoning.
6
+
7
+ ## Why These Exist
8
+
9
+ Status commands (`/specweave:status`, `/specweave:progress`, `/specweave:jobs`) were taking 3+ minutes because they expanded as prompts requiring LLM processing. These commands need NO reasoning - they just read JSON and format output.
10
+
11
+ **Performance comparison:**
12
+
13
+ | Command | Before | After |
14
+ |---------|--------|-------|
15
+ | `/specweave:status` | 3+ min | <100ms |
16
+ | `/specweave:progress` | 2+ min | <100ms |
17
+ | `/specweave:jobs` | 3+ min | <100ms |
18
+
19
+ ## Scripts
20
+
21
+ ### Bash Scripts (v0.32.0+ - Recommended)
22
+
23
+ These read from the pre-computed dashboard cache for <10ms response time.
24
+
25
+ #### read-status.sh - Increment Status Overview
26
+
27
+ ```bash
28
+ bash plugins/specweave/scripts/read-status.sh
29
+ bash plugins/specweave/scripts/read-status.sh 0045 # Specific increment
30
+ ```
31
+
32
+ #### read-progress.sh - Task Completion Progress
33
+
34
+ ```bash
35
+ bash plugins/specweave/scripts/read-progress.sh
36
+ bash plugins/specweave/scripts/read-progress.sh 0045 # Specific increment
37
+ ```
38
+
39
+ #### read-jobs.sh - Background Job Status
40
+
41
+ ```bash
42
+ bash plugins/specweave/scripts/read-jobs.sh
43
+ bash plugins/specweave/scripts/read-jobs.sh --all # Include completed
44
+ ```
45
+
46
+ ### Node.js Scripts (Legacy - Fallback)
47
+
48
+ These are used when jq is not available or cache doesn't exist.
49
+
50
+ ```bash
51
+ node plugins/specweave/scripts/status.js
52
+ node plugins/specweave/scripts/progress.js
53
+ node plugins/specweave/scripts/jobs.js
54
+ ```
55
+
56
+ ## Three Execution Paths
57
+
58
+ These scripts work across all contexts through a layered architecture:
59
+
60
+ | Layer | Context | Speed | How It Works |
61
+ |-------|---------|-------|--------------|
62
+ | **Hook** | Claude Code | <100ms | `UserPromptSubmit` intercepts `/specweave:*`, runs script, blocks prompt |
63
+ | **Skill** | Any LLM | ~2s | Skill instructs LLM to run script via Bash |
64
+ | **CLI** | Terminal | ~500ms | `specweave status` / direct `node scripts/*.js` |
65
+
66
+ ### 1. Claude Code (Hook - Fastest)
67
+
68
+ In Claude Code, the `UserPromptSubmit` hook automatically intercepts status commands:
69
+
70
+ ```
71
+ User types: /specweave:status
72
+ Hook runs: bash plugins/specweave/scripts/read-status.sh
73
+ Output appears instantly (<10ms)
74
+ LLM never processes the prompt
75
+ ```
76
+
77
+ ### 2. Other LLMs (Skill - Fast)
78
+
79
+ In Cursor, Windsurf, Copilot, or API usage, the `instant-status` skill provides instructions:
80
+
81
+ ```
82
+ User types: /specweave:status
83
+ Skill activates and instructs LLM to run the script
84
+ LLM executes: bash plugins/specweave/scripts/read-status.sh
85
+ Output appears (~2s)
86
+ ```
87
+
88
+ ### 3. Terminal (CLI - Direct)
89
+
90
+ Users can run scripts directly without any LLM:
91
+
92
+ ```bash
93
+ # Full CLI command
94
+ specweave status
95
+ specweave jobs
96
+
97
+ # Direct script execution (bash preferred)
98
+ bash plugins/specweave/scripts/read-status.sh
99
+ bash plugins/specweave/scripts/read-progress.sh 0045
100
+ ```
101
+
102
+ ## When to Use Which
103
+
104
+ | Situation | Recommended Path |
105
+ |-----------|------------------|
106
+ | Quick status check in Claude Code | Just type `/specweave:status` |
107
+ | Using Cursor/Windsurf/Copilot | Let skill guide execution |
108
+ | Terminal/scripting | `specweave status` or `node scripts/*.js` |
109
+ | CI/CD pipelines | Direct `node scripts/*.js` |
110
+
111
+ ## Adding New Instant Commands
112
+
113
+ To add a new instant command:
114
+
115
+ 1. Create script in `plugins/specweave/scripts/newcmd.js`
116
+ 2. Add `--help` handling (required)
117
+ 3. Add to hook dispatcher in `plugins/specweave/hooks/user-prompt-submit.sh`
118
+ 4. Update `skills/instant-status/SKILL.md` with new command
119
+ 5. Test all three paths (hook, skill, CLI)
120
+
121
+ ### Script Template
122
+
123
+ ```javascript
124
+ #!/usr/bin/env node
125
+ /**
126
+ * Description of what this script does
127
+ * Usage: node newcmd.js [options] [--help]
128
+ */
129
+
130
+ import fs from 'fs';
131
+ import path from 'path';
132
+
133
+ // Handle --help (REQUIRED)
134
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
135
+ console.log(`
136
+ SpecWeave Instant NewCmd
137
+
138
+ USAGE
139
+ node plugins/specweave/scripts/newcmd.js [options]
140
+
141
+ OPTIONS
142
+ --help, -h Show this help message
143
+
144
+ DESCRIPTION
145
+ What this command does...
146
+
147
+ EXECUTION PATHS
148
+ 1. Claude Code: /specweave:newcmd (hook intercepts)
149
+ 2. Any LLM: Skill instructs to run this script
150
+ 3. Terminal: specweave newcmd
151
+ `);
152
+ process.exit(0);
153
+ }
154
+
155
+ // Your implementation here
156
+ const cwd = process.cwd();
157
+ // ...
158
+ ```
159
+
160
+ ## Design Principles
161
+
162
+ 1. **Zero LLM tokens**: Pure filesystem reads, no AI reasoning needed
163
+ 2. **Single source of truth**: Hook, skill, and CLI all use these same scripts
164
+ 3. **Universal compatibility**: Works in Claude Code, Cursor, Copilot, terminal
165
+ 4. **Fast feedback**: <100ms response time for status queries
166
+ 5. **Self-documenting**: All scripts support `--help`
@@ -0,0 +1,142 @@
1
+ #!/bin/bash
2
+ # cleanup-state.sh - Emergency state cleanup for stuck sessions
3
+ #
4
+ # Usage: bash cleanup-state.sh [--all]
5
+ #
6
+ # Cleans:
7
+ # - Lock files (.lock, .lock.d, .pid)
8
+ # - Dedup cache files
9
+ # - Stale event queue files (older than 5 minutes)
10
+ #
11
+ # With --all:
12
+ # - Also cleans circuit breaker state
13
+ # - Resets status line cache
14
+ #
15
+ # IMPORTANT: Run this if Claude Code is stuck or hangs
16
+
17
+ set -e
18
+
19
+ PROJECT_ROOT="$PWD"
20
+ while [[ "$PROJECT_ROOT" != "/" ]] && [[ ! -d "$PROJECT_ROOT/.specweave" ]]; do
21
+ PROJECT_ROOT=$(dirname "$PROJECT_ROOT")
22
+ done
23
+
24
+ if [[ ! -d "$PROJECT_ROOT/.specweave" ]]; then
25
+ echo "❌ No .specweave directory found. Are you in a SpecWeave project?"
26
+ exit 1
27
+ fi
28
+
29
+ STATE_DIR="$PROJECT_ROOT/.specweave/state"
30
+ LOGS_DIR="$PROJECT_ROOT/.specweave/logs"
31
+
32
+ echo "🧹 SpecWeave State Cleanup"
33
+ echo "=========================="
34
+ echo "Project: $PROJECT_ROOT"
35
+ echo ""
36
+
37
+ # Kill any zombie processor processes
38
+ echo "β†’ Killing zombie processes..."
39
+ pkill -f "processor\.sh.*daemon" 2>/dev/null || true
40
+ pkill -f "processor\.js.*daemon" 2>/dev/null || true
41
+ echo " βœ“ Done"
42
+
43
+ # Kill heredoc zombie processes (CRITICAL - prevents infinite hangs)
44
+ echo "β†’ Killing heredoc zombies..."
45
+ pkill -f "cat.*EOF" 2>/dev/null || true
46
+ pkill -f "bash.*heredoc" 2>/dev/null || true
47
+ pkill -9 -f "bash.*specweave.*>" 2>/dev/null || true
48
+ echo " βœ“ Done"
49
+
50
+ # Clean lock files
51
+ echo "β†’ Cleaning lock files..."
52
+ rm -f "$STATE_DIR"/.processor.pid 2>/dev/null || true
53
+ rm -rf "$STATE_DIR"/.processor.lock.d 2>/dev/null || true
54
+ rm -rf "$STATE_DIR"/.processor.lock 2>/dev/null || true
55
+ echo " βœ“ Done"
56
+
57
+ # Clean dedup cache
58
+ echo "β†’ Cleaning dedup cache..."
59
+ rm -rf "$STATE_DIR"/.dedup-cache/*.lock 2>/dev/null || true
60
+ find "$STATE_DIR"/.dedup-cache -type f -mmin +5 -delete 2>/dev/null || true
61
+ echo " βœ“ Done"
62
+
63
+ # Clean stale event queue files
64
+ echo "β†’ Cleaning stale event queue..."
65
+ EVENT_QUEUE="$STATE_DIR/event-queue"
66
+ if [[ -d "$EVENT_QUEUE" ]]; then
67
+ STALE_COUNT=$(find "$EVENT_QUEUE" -name "*.event" -mmin +5 2>/dev/null | wc -l | tr -d ' ')
68
+ if [[ "$STALE_COUNT" -gt 0 ]]; then
69
+ find "$EVENT_QUEUE" -name "*.event" -mmin +5 -delete 2>/dev/null
70
+ echo " βœ“ Removed $STALE_COUNT stale events"
71
+ else
72
+ echo " βœ“ No stale events"
73
+ fi
74
+ else
75
+ echo " βœ“ No event queue"
76
+ fi
77
+
78
+ # Full cleanup with --all flag
79
+ if [[ "$1" == "--all" ]]; then
80
+ echo ""
81
+ echo "β†’ Full cleanup (--all)..."
82
+
83
+ # Reset circuit breakers
84
+ echo " β†’ Resetting circuit breakers..."
85
+ echo "0" > "$STATE_DIR/.hook-circuit-breaker" 2>/dev/null || true
86
+ echo "0" > "$STATE_DIR/.hook-circuit-breaker-pre" 2>/dev/null || true
87
+ echo " βœ“ Done"
88
+
89
+ # Reset status line cache
90
+ echo " β†’ Resetting status line cache..."
91
+ rm -f "$STATE_DIR/status-line.json" 2>/dev/null || true
92
+ echo " βœ“ Done"
93
+
94
+ # Clean all US completion state
95
+ echo " β†’ Cleaning US completion state..."
96
+ rm -f "$STATE_DIR"/.us-completion-* 2>/dev/null || true
97
+ rm -f "$STATE_DIR"/.prev-status-* 2>/dev/null || true
98
+ echo " βœ“ Done"
99
+
100
+ # Clean logs (keep last 10 lines for debugging)
101
+ echo " β†’ Trimming logs..."
102
+ for log in "$LOGS_DIR"/*.log; do
103
+ if [[ -f "$log" ]]; then
104
+ tail -10 "$log" > "$log.tmp" 2>/dev/null && mv "$log.tmp" "$log" || rm -f "$log.tmp"
105
+ fi
106
+ done
107
+ echo " βœ“ Done"
108
+ fi
109
+
110
+ # Check MCP connection issues
111
+ echo "β†’ Checking MCP connection health..."
112
+ CLAUDE_DEBUG="$HOME/.claude/debug/latest"
113
+ if [[ -f "$CLAUDE_DEBUG" ]]; then
114
+ MCP_DROPS=$(grep -c "WS-IDE connection dropped" "$CLAUDE_DEBUG" 2>/dev/null | head -1 || echo "0")
115
+ MCP_DROPS="${MCP_DROPS//[^0-9]/}" # Strip non-numeric chars
116
+ MCP_DROPS="${MCP_DROPS:-0}"
117
+ if [[ "$MCP_DROPS" -gt 0 ]]; then
118
+ echo " ⚠️ Found $MCP_DROPS MCP connection drops in latest session"
119
+ echo ""
120
+ echo " MCP FIX OPTIONS:"
121
+ echo " 1. In VS Code: Cmd+Shift+P β†’ 'Developer: Restart Extension Host'"
122
+ echo " 2. Close extra files/tabs (reduces diagnostics payload)"
123
+ echo " 3. Run Claude Code in plain terminal instead"
124
+ echo ""
125
+ else
126
+ echo " βœ“ No MCP drops detected"
127
+ fi
128
+ else
129
+ echo " βœ“ No debug log to check"
130
+ fi
131
+
132
+ echo ""
133
+ echo "βœ… Cleanup complete!"
134
+ echo ""
135
+ echo "Next steps:"
136
+ echo " 1. Restart Claude Code"
137
+ echo " 2. Run /specweave:progress to check status"
138
+ echo ""
139
+ echo "If MCP issues persist:"
140
+ echo " β€’ Update Claude Code VS Code extension"
141
+ echo " β€’ Use terminal mode: cd project && claude"
142
+ echo ""
@@ -0,0 +1,142 @@
1
+ #!/bin/bash
2
+ # force-kill.sh - AGGRESSIVE process killer for stuck Claude Code sessions
3
+ #
4
+ # This script KILLS processes, not just warns about them.
5
+ # Use when Claude Code is stuck and won't respond.
6
+ #
7
+ # Usage:
8
+ # bash force-kill.sh # Kill all stuck processes
9
+ # bash force-kill.sh --dry-run # Show what would be killed
10
+ #
11
+ # What gets killed:
12
+ # - Heredoc processes (cat.*EOF)
13
+ # - Stuck node processes from hooks
14
+ # - Background SpecWeave processors
15
+ # - Zombie bash processes
16
+
17
+ set -euo pipefail
18
+
19
+ DRY_RUN=false
20
+ VERBOSE=false
21
+
22
+ # Colors
23
+ RED='\033[0;31m'
24
+ GREEN='\033[0;32m'
25
+ YELLOW='\033[1;33m'
26
+ NC='\033[0m'
27
+
28
+ for arg in "$@"; do
29
+ case $arg in
30
+ --dry-run|-n)
31
+ DRY_RUN=true
32
+ ;;
33
+ --verbose|-v)
34
+ VERBOSE=true
35
+ ;;
36
+ esac
37
+ done
38
+
39
+ log() {
40
+ echo -e "$1"
41
+ }
42
+
43
+ kill_processes() {
44
+ local pattern="$1"
45
+ local desc="$2"
46
+ local signal="${3:--9}" # Default to SIGKILL
47
+
48
+ local pids
49
+ pids=$(pgrep -f "$pattern" 2>/dev/null || true)
50
+
51
+ if [[ -n "$pids" ]]; then
52
+ local count
53
+ count=$(echo "$pids" | wc -l | tr -d ' ')
54
+
55
+ if [[ "$DRY_RUN" == "true" ]]; then
56
+ log "${YELLOW}[DRY-RUN]${NC} Would kill $count $desc process(es):"
57
+ echo "$pids" | while read -r pid; do
58
+ ps -p "$pid" -o pid,command 2>/dev/null | tail -1 || true
59
+ done
60
+ else
61
+ log "${RED}Killing${NC} $count $desc process(es)..."
62
+ echo "$pids" | xargs kill $signal 2>/dev/null || true
63
+ sleep 0.5
64
+ # Double-tap with SIGKILL if still alive
65
+ for pid in $pids; do
66
+ if kill -0 "$pid" 2>/dev/null; then
67
+ kill -9 "$pid" 2>/dev/null || true
68
+ fi
69
+ done
70
+ fi
71
+ return 0
72
+ fi
73
+ return 1
74
+ }
75
+
76
+ # === Main execution ===
77
+ log "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
78
+ log "${RED}FORCE KILL - Aggressive Process Termination${NC}"
79
+ log "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
80
+ [[ "$DRY_RUN" == "true" ]] && log "${YELLOW}DRY RUN MODE - No processes will be killed${NC}"
81
+ echo
82
+
83
+ KILLED_ANY=false
84
+
85
+ # 1. Kill heredoc zombies (most common cause of hangs)
86
+ if kill_processes "cat.*EOF" "heredoc zombie"; then
87
+ KILLED_ANY=true
88
+ fi
89
+
90
+ # 2. Kill stuck hook node processes
91
+ if kill_processes "node.*specweave.*hook" "hook node"; then
92
+ KILLED_ANY=true
93
+ fi
94
+
95
+ # 3. Kill stuck dispatcher processes
96
+ if kill_processes "dispatcher.mjs" "dispatcher"; then
97
+ KILLED_ANY=true
98
+ fi
99
+
100
+ # 4. Kill background processors
101
+ if kill_processes "processor.sh" "background processor"; then
102
+ KILLED_ANY=true
103
+ fi
104
+
105
+ # 5. Kill stuck sync processes
106
+ if kill_processes "node.*sync.*specweave" "sync node"; then
107
+ KILLED_ANY=true
108
+ fi
109
+
110
+ # 6. Kill any bash processes with specweave in command (older than 60s)
111
+ # This is more aggressive - use pattern carefully
112
+ if kill_processes "bash.*specweave.*hooks" "specweave bash"; then
113
+ KILLED_ANY=true
114
+ fi
115
+
116
+ # 7. Clean up lock files
117
+ if [[ "$DRY_RUN" != "true" ]]; then
118
+ log "\n${GREEN}Cleaning lock files...${NC}"
119
+ rm -f .specweave/state/.processor.lock 2>/dev/null || true
120
+ rm -f .specweave/state/.processor.pid 2>/dev/null || true
121
+ rm -f .specweave/state/.hook-* 2>/dev/null || true
122
+ rm -rf .specweave/state/.dedup-cache/*.lock 2>/dev/null || true
123
+ log " βœ“ Lock files cleaned"
124
+ fi
125
+
126
+ echo
127
+ if [[ "$KILLED_ANY" == "true" ]]; then
128
+ if [[ "$DRY_RUN" == "true" ]]; then
129
+ log "${YELLOW}Run without --dry-run to kill these processes${NC}"
130
+ else
131
+ log "${GREEN}βœ“ Stuck processes killed${NC}"
132
+ log ""
133
+ log "Next steps:"
134
+ log " 1. Close any stuck Claude Code terminals"
135
+ log " 2. Start a fresh Claude Code session"
136
+ fi
137
+ else
138
+ log "${GREEN}βœ“ No stuck processes found${NC}"
139
+ fi
140
+
141
+ log ""
142
+ log "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Instant Background Jobs Status
4
+ *
5
+ * Executed by UserPromptSubmit hook for /specweave:jobs
6
+ * Bypasses LLM entirely - output shown directly to user
7
+ *
8
+ * Usage: node jobs.js [--all] [--id <jobId>] [--help]
9
+ */
10
+
11
+ import fs from 'fs';
12
+ import path from 'path';
13
+
14
+ // Handle --help
15
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
16
+ console.log(`
17
+ SpecWeave Instant Jobs
18
+
19
+ USAGE
20
+ node plugins/specweave/scripts/jobs.js [options]
21
+ specweave jobs [options]
22
+
23
+ OPTIONS
24
+ --help, -h Show this help message
25
+ --all Show all jobs including completed
26
+ --id <jobId> Show details for specific job
27
+
28
+ DESCRIPTION
29
+ Shows background job status (imports, cloning, sync operations).
30
+ This script bypasses LLM processing for instant results (<100ms).
31
+
32
+ EXECUTION PATHS
33
+ 1. Claude Code: /specweave:jobs (hook intercepts, <100ms)
34
+ 2. Any LLM: Skill instructs to run this script (~2s)
35
+ 3. Terminal: specweave jobs (~500ms)
36
+
37
+ EXAMPLES
38
+ node plugins/specweave/scripts/jobs.js
39
+ node plugins/specweave/scripts/jobs.js --all
40
+ node plugins/specweave/scripts/jobs.js --id abc123
41
+ specweave jobs --all
42
+ `);
43
+ process.exit(0);
44
+ }
45
+
46
+ const cwd = process.cwd();
47
+ const stateFile = path.join(cwd, '.specweave/state/background-jobs.json');
48
+ const args = process.argv.slice(2);
49
+
50
+ // Parse arguments
51
+ const showAll = args.includes('--all');
52
+ const idIndex = args.indexOf('--id');
53
+ const specificId = idIndex !== -1 ? args[idIndex + 1] : null;
54
+
55
+ // Check if state file exists
56
+ if (!fs.existsSync(stateFile)) {
57
+ console.log('No background jobs found.');
58
+ console.log('Jobs are created during `specweave init` when importing large datasets.');
59
+ process.exit(0);
60
+ }
61
+
62
+ // Read and parse state
63
+ let state;
64
+ try {
65
+ state = JSON.parse(fs.readFileSync(stateFile, 'utf-8'));
66
+ } catch (e) {
67
+ console.log('Error reading jobs state:', e.message);
68
+ process.exit(1);
69
+ }
70
+
71
+ const jobs = state.jobs || [];
72
+
73
+ if (jobs.length === 0) {
74
+ console.log('No background jobs found.');
75
+ process.exit(0);
76
+ }
77
+
78
+ // If specific job requested
79
+ if (specificId) {
80
+ const job = jobs.find(j => j.id === specificId || j.id.startsWith(specificId));
81
+ if (!job) {
82
+ console.log(`Job not found: ${specificId}`);
83
+ process.exit(1);
84
+ }
85
+
86
+ console.log(`\nπŸ“¦ Job Details: ${job.id}\n`);
87
+ console.log(`Type: ${job.type}`);
88
+ console.log(`Status: ${job.status}`);
89
+ console.log(`Started: ${job.startedAt}`);
90
+ console.log(`Updated: ${job.updatedAt}`);
91
+
92
+ const p = job.progress;
93
+ const pct = p.total > 0 ? Math.round((p.current / p.total) * 100) : 0;
94
+ console.log(`Progress: ${p.current}/${p.total} (${pct}%)`);
95
+
96
+ if (job.error) {
97
+ console.log(`Error: ${job.error}`);
98
+ }
99
+ process.exit(0);
100
+ }
101
+
102
+ // Group by status
103
+ const running = jobs.filter(j => j.status === 'running');
104
+ const paused = jobs.filter(j => j.status === 'paused');
105
+ const failed = jobs.filter(j => j.status === 'failed');
106
+ const completed = jobs.filter(j => j.status === 'completed');
107
+
108
+ console.log('\nπŸ“‹ Background Jobs\n');
109
+
110
+ // Running
111
+ if (running.length > 0) {
112
+ console.log(`πŸ”„ Running (${running.length}):`);
113
+ for (const job of running) {
114
+ const p = job.progress;
115
+ const pct = p.total > 0 ? Math.round((p.current / p.total) * 100) : 0;
116
+ const elapsed = (Date.now() - new Date(job.startedAt).getTime()) / 1000;
117
+ const rate = elapsed > 0 ? (p.current / elapsed).toFixed(1) : '0';
118
+ console.log(` [${job.id.slice(0,8)}] ${job.type}`);
119
+ console.log(` Progress: ${p.current}/${p.total} (${pct}%) | Rate: ${rate}/s`);
120
+ }
121
+ console.log('');
122
+ }
123
+
124
+ // Paused
125
+ if (paused.length > 0) {
126
+ console.log(`⏸️ Paused (${paused.length}):`);
127
+ for (const job of paused) {
128
+ const p = job.progress;
129
+ const pct = p.total > 0 ? Math.round((p.current / p.total) * 100) : 0;
130
+ console.log(` [${job.id.slice(0,8)}] ${job.type} - ${pct}%`);
131
+ }
132
+ console.log('');
133
+ }
134
+
135
+ // Failed
136
+ if (failed.length > 0) {
137
+ console.log(`❌ Failed (${failed.length}):`);
138
+ for (const job of failed) {
139
+ console.log(` [${job.id.slice(0,8)}] ${job.type}`);
140
+ if (job.error) {
141
+ console.log(` Error: ${job.error}`);
142
+ }
143
+ }
144
+ console.log('');
145
+ }
146
+
147
+ // Completed (only if --all)
148
+ if (showAll && completed.length > 0) {
149
+ console.log(`βœ… Completed (${completed.length}):`);
150
+ for (const job of completed.slice(0, 10)) {
151
+ console.log(` [${job.id.slice(0,8)}] ${job.type} - ${job.progress.current} items`);
152
+ }
153
+ if (completed.length > 10) {
154
+ console.log(` ... and ${completed.length - 10} more`);
155
+ }
156
+ console.log('');
157
+ }
158
+
159
+ // Summary if no active jobs
160
+ if (running.length === 0 && paused.length === 0 && failed.length === 0) {
161
+ if (completed.length > 0) {
162
+ console.log(`No active jobs. ${completed.length} completed (use --all to see).`);
163
+ } else {
164
+ console.log('No jobs found.');
165
+ }
166
+ }
167
+
168
+ // Help
169
+ console.log('πŸ’‘ Commands:');
170
+ console.log(' specweave jobs --id <id> View job details');
171
+ console.log(' specweave jobs --all Show completed jobs');