specweave 0.26.10 → 0.26.13

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 (33) hide show
  1. package/CLAUDE.md +95 -520
  2. package/dist/plugins/specweave-github/lib/completion-calculator.d.ts +4 -1
  3. package/dist/plugins/specweave-github/lib/completion-calculator.d.ts.map +1 -1
  4. package/dist/plugins/specweave-github/lib/completion-calculator.js +49 -29
  5. package/dist/plugins/specweave-github/lib/completion-calculator.js.map +1 -1
  6. package/dist/src/cli/commands/init.js +2 -2
  7. package/dist/src/cli/commands/init.js.map +1 -1
  8. package/dist/src/core/increment/increment-archiver.d.ts +3 -0
  9. package/dist/src/core/increment/increment-archiver.d.ts.map +1 -1
  10. package/dist/src/core/increment/increment-archiver.js +35 -4
  11. package/dist/src/core/increment/increment-archiver.js.map +1 -1
  12. package/dist/src/core/living-docs/feature-archiver.d.ts +5 -0
  13. package/dist/src/core/living-docs/feature-archiver.d.ts.map +1 -1
  14. package/dist/src/core/living-docs/feature-archiver.js +66 -18
  15. package/dist/src/core/living-docs/feature-archiver.js.map +1 -1
  16. package/package.json +1 -1
  17. package/plugins/specweave/commands/specweave-archive.md +10 -1
  18. package/plugins/specweave/hooks/hooks.json +10 -0
  19. package/plugins/specweave/hooks/lib/update-active-increment.sh +96 -0
  20. package/plugins/specweave/hooks/lib/update-status-line.sh +153 -189
  21. package/plugins/specweave/hooks/post-edit-write-consolidated.sh +6 -0
  22. package/plugins/specweave/hooks/post-metadata-change.sh +9 -0
  23. package/plugins/specweave/hooks/post-task-completion.sh +8 -0
  24. package/plugins/specweave/hooks/post-task-edit.sh +37 -0
  25. package/plugins/specweave/hooks/pre-command-deduplication.sh +43 -53
  26. package/plugins/specweave/hooks/pre-tool-use.sh +5 -0
  27. package/plugins/specweave/hooks/user-prompt-submit.sh +143 -289
  28. package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +18 -0
  29. package/plugins/specweave-github/lib/completion-calculator.js +34 -16
  30. package/plugins/specweave-github/lib/completion-calculator.ts +54 -32
  31. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +27 -0
  32. package/src/templates/AGENTS.md.template +301 -2452
  33. package/src/templates/CLAUDE.md.template +99 -667
package/CLAUDE.md CHANGED
@@ -2,242 +2,93 @@
2
2
 
3
3
  **Project**: SpecWeave - Spec-Driven Development Framework
4
4
  **Type**: TypeScript CLI (NPM Package)
5
- **Repository**: https://github.com/anton-abyzov/specweave
6
5
 
7
6
  For **contributors to SpecWeave itself** (not users).
8
7
 
9
8
  ---
10
9
 
11
- ## 🚨 CRITICAL SAFETY RULES
10
+ ## CRITICAL SAFETY RULES
12
11
 
13
- ### 0. Think-Then-Act Discipline (META RULE!)
12
+ ### 1. Context Management (CRASH PREVENTION!)
14
13
 
15
- **NEVER run commands you know will fail.** Act on reasoning BEFORE execution.
16
-
17
- **Context Management**: Active increment with 10+ tasks + editing unrelated 2000+ line file = crash risk (context overflow). Pause first: `/specweave:pause XXXX` → edit → `/specweave:resume XXXX`. See ADR-0133, Section 15.
18
-
19
- ```bash
20
- # ❌ WRONG: node -e "require('./dist/file.js')" (before build)
21
- # ✅ CORRECT: npm run rebuild && node -e "require('./dist/file.js')"
22
- ```
23
-
24
- ---
25
-
26
- ## 1. Development Setup
27
-
28
- **Standard Workflow**:
29
- ```bash
30
- git clone https://github.com/YOUR_USERNAME/specweave.git
31
- cd specweave && npm install && npm run rebuild
32
-
33
- # Development Cycle
34
- npm run rebuild && npm test
35
- git add . && git commit -m "feat: feature" && git push origin develop
36
- # Wait 5-10s → Claude Code auto-updates marketplace
37
- ```
38
-
39
- **Testing Unpushed**: Temp branch → push → test → delete, OR `claude plugin marketplace add github:YOUR_USERNAME/specweave`
40
-
41
- ---
42
-
43
- ### 1a. Marketplace Refresh
44
-
45
- ```bash
46
- bash scripts/refresh-marketplace.sh # GitHub (default, ALWAYS use)
47
- bash scripts/refresh-marketplace.sh --local # Local dev only (filesystem coupling risks)
48
- ```
49
-
50
- **Use GitHub mode**: Proper install path, stable source, no hook coupling (~30s)
51
- **Verify**: `jq -r '.specweave.source' ~/.claude/plugins/known_marketplaces.json` → should be `"github"`
52
-
53
- **Note**: GitHub mode shows "AC test validator not available" warning because `dist/` is gitignored. Use `--local` mode when developing hooks/validators to test with built artifacts. Regular users with `npm install specweave` won't see this (validator found in `node_modules/`).
54
-
55
- ---
56
-
57
- ### 1b. NPM Release
14
+ **Active increment (10+ tasks) + large file edit (2000+ lines) = CRASH**
58
15
 
59
16
  ```bash
60
- /specweave-release:npm # GitHub Actions (2-3 min, recommended)
61
- /specweave-release:npm --only # Direct publish (30s, emergencies)
17
+ # Before editing large files outside increment:
18
+ /specweave:pause XXXX edit /specweave:resume XXXX
19
+ # OR close completed increments: /specweave:done XXXX
62
20
  ```
63
21
 
64
- ---
65
-
66
- ## 2. Folder Structure Rules
67
-
68
- **At `.specweave/increments/` root - ONLY**:
69
- 1. `####-increment-name/` folders
70
- 2. `_archive/` folder
71
- 3. `README.md` (optional)
72
-
73
- **Inside increment folders - ONLY at root**: `spec.md`, `plan.md`, `tasks.md`, `metadata.json`
74
-
75
- **Everything else → subfolders**:
76
- - `reports/` - Completion reports, investigation findings, final summaries
77
- - `scripts/` - Helper scripts, automation, migration tools
78
- - `logs/` - Debug logs, performance logs, execution traces
79
- - `backups/` - Backup files, .backup versions
80
- - `docs/` - Additional documentation, diagrams, references
81
-
82
- **Examples**:
83
- ```
84
- 0055-feature/
85
- ├── spec.md ✅ Required
86
- ├── plan.md ✅ Required
87
- ├── tasks.md ✅ Required
88
- ├── metadata.json ✅ Required
89
- ├── reports/ ✅ Good organization
90
- │ ├── completion-summary.md
91
- │ └── FINAL-REPORT.md
92
- ├── scripts/ ✅ Good organization
93
- │ └── migration.sh
94
- └── backups/ ✅ Good organization
95
- └── SKILL.md.backup
96
- ```
97
-
98
- ```bash
99
- # Validation (should output NOTHING):
100
- ls -1 .specweave/increments/ | grep -v "^[0-9]" | grep -v "^_archive" | grep -v "^README.md"
101
-
102
- # Check for misplaced files in increment roots:
103
- find .specweave/increments -maxdepth 2 -type f ! -name "spec.md" ! -name "plan.md" ! -name "tasks.md" ! -name "metadata.json" | grep -E "/[0-9]{4}-"
104
- ```
105
-
106
- ---
107
-
108
- ## 3. Protected Directories
109
-
110
- **Never delete**: `.specweave/docs/`, `.specweave/increments/`
111
- **Pre-commit hook blocks**: 50+ file deletions, `rm -rf` on protected dirs
112
- **Recovery**: `git restore .specweave/`
113
-
114
- ---
115
-
116
- ## 4-6. Safety Rules
117
-
118
- **4. Test Cleanup**: `pwd` check → dry-run → count → confirm → execute
119
- **5. NEVER**: `specweave init . --force` (deletes all without backup)
120
- **6. Completion**: `/specweave:done 0043` (validates), NEVER manual `metadata.json` edit
121
-
122
- ---
123
-
124
- ## 7. Source of Truth: tasks.md + spec.md (CRITICAL!)
22
+ ### 2. Source of Truth
125
23
 
126
- **Internal TODO is ephemeral. tasks.md + spec.md are SOURCE OF TRUTH.**
24
+ **tasks.md + spec.md are SOURCE OF TRUTH** (not internal TODO)
127
25
 
128
- **MANDATORY workflow**:
129
26
  ```typescript
130
- // 1. Complete work 2. TodoWrite → 3. IMMEDIATELY Edit tasks.md → 4. IMMEDIATELY Edit spec.md
131
- await work();
27
+ // After completing work - IMMEDIATELY update both:
132
28
  TodoWrite([{task: "T-013", status: "completed"}]);
133
29
  Edit("tasks.md", "**Status**: [ ] pending", "**Status**: [x] completed");
134
30
  Edit("spec.md", "- [ ] **AC-US1-01**", "- [x] **AC-US1-01**");
135
31
  ```
136
32
 
137
- **Status Line Sync**: TodoWrite → `post-task-completion.sh` cache updates
138
- **GitHub Duplicates**: Use `DuplicateDetector.createWithProtection()`, NEVER `--limit 1` in gh searches
139
- **Validation**: `/specweave:validate-status`
33
+ ### 3. Protected Directories
140
34
 
141
- **Pre-closure check**:
142
- ```bash
143
- grep "^\*\*Status\*\*:" tasks.md | grep -c "\[x\] completed" # Must equal total
144
- grep -c "^- \[x\] \*\*AC-" spec.md # Must equal total ACs
145
- ```
146
-
147
- ---
35
+ **NEVER delete**: `.specweave/docs/`, `.specweave/increments/`
36
+ **NEVER run**: `specweave init . --force` (deletes all without backup)
148
37
 
149
- ### 7a. AC Presence in spec.md (MANDATORY)
38
+ ### 4. Skills Must NOT Spawn Large Agents
150
39
 
151
- **spec.md MUST contain inline ACs** even with external living docs. AC sync hook requires them.
152
-
153
- **Required Format**:
154
- ```markdown
155
- ## Acceptance Criteria
156
- <!-- Auto-synced from living docs -->
157
- ### US-001: Title
158
- - [ ] **AC-US1-01**: Description
159
- ```
160
-
161
- **If missing**: `/specweave:embed-acs 0050` (auto-embeds from living docs)
162
- **Validation**: `/specweave:do` blocks if ACs missing
163
-
164
- ---
165
-
166
- ### 7b. AC Sync Parser (v0.25.2)
167
-
168
- **Both formats supported**: `- [x] Done` (legacy list) OR `**Status**: [x] completed` (field format)
169
-
170
- ---
171
-
172
- ## 8. Logger Abstraction
173
-
174
- **Rule**: ALL `src/` code uses logger injection, NEVER `console.*`
40
+ **Skills spawning content-generating agents = CRASH** (context explosion)
175
41
 
176
42
  ```typescript
177
- import { Logger, consoleLogger } from '../../utils/logger.js';
178
- constructor(options: { logger?: Logger } = {}) {
179
- this.logger = options.logger ?? consoleLogger;
180
- }
181
- ```
182
-
183
- **Exception**: `src/cli/commands/*.ts` may use `console.*` with comment explaining it's user-facing output
184
-
185
- ---
186
-
187
- ### 8a. Native fs
188
-
189
- **Use native Node.js `fs`, NEVER `fs-extra`**
43
+ // FORBIDDEN in skills:
44
+ Task({ subagent_type: "specweave:architect:architect" }); // 1000-3000 lines output
190
45
 
191
- ```typescript
192
- // ✅ CORRECT
193
- import { existsSync, readFileSync } from 'fs';
194
- import { promises as fs } from 'fs';
195
- import { mkdirpSync, writeJsonSync } from '../utils/fs-native.js';
46
+ // ✅ CORRECT: Skills create templates, guide user to invoke agents in main context
196
47
  ```
197
48
 
198
49
  ---
199
50
 
200
- ## 9. Coding Standards
51
+ ## Development Setup
201
52
 
202
- **Critical rules (enforced)**:
203
- 1. NEVER `console.*` (use logger)
204
- 2. ALWAYS `.js` extensions in imports
205
- 3. Test files: `.test.ts` (NEVER `.spec.ts`)
206
- 4. Avoid `any` type
207
- 5. Functions < 100 lines
208
- 6. Custom error types
209
- 7. Comment "why" not "what"
210
- 8. No hardcoded secrets
211
- 9. No N+1 queries
212
- 10. Naming: camelCase (vars), PascalCase (classes), UPPER_SNAKE_CASE (constants)
53
+ ```bash
54
+ npm install && npm run rebuild
55
+ npm run rebuild && npm test
56
+ git add . && git commit -m "feat: feature" && git push origin develop
57
+ ```
213
58
 
214
- **Auto-discovery**: `/specweave:analyze-standards`
59
+ **Marketplace**: `bash scripts/refresh-marketplace.sh` (GitHub mode, always use)
60
+ **NPM Release**: `/specweave-release:npm`
215
61
 
216
62
  ---
217
63
 
218
- ## 10. GitHub Issue Format
219
-
220
- **ONLY Correct Format**: `[FS-XXX][US-YYY] User Story Title`
64
+ ## Coding Standards
221
65
 
222
- **PROHIBITED**: `[SP-*]`, `[FS-XXX]` alone, `[undefined][US-XXX]`, project suffixes
223
-
224
- **Architecture**: Feature → Milestone, User Stories Issues
225
-
226
- **Create**: `/specweave-github:sync FS-048`
66
+ 1. **Logger injection**: ALL `src/` code uses `logger`, NEVER `console.*`
67
+ ```typescript
68
+ import { Logger, consoleLogger } from '../../utils/logger.js';
69
+ constructor(options: { logger?: Logger } = {}) {
70
+ this.logger = options.logger ?? consoleLogger;
71
+ }
72
+ ```
73
+ 2. **Imports**: ALWAYS `.js` extensions
74
+ 3. **Tests**: `.test.ts` files, `vi.fn()` (not jest), `os.tmpdir()` (not cwd)
75
+ 4. **Filesystem**: Native `fs` only (NEVER `fs-extra`)
76
+ 5. **Code**: Functions < 100 lines, avoid `any`, custom error types
227
77
 
228
78
  ---
229
79
 
230
- ### 10a. NO Increment-to-Increment References (ADR-0061)
80
+ ## Folder Structure
231
81
 
232
- **FORBIDDEN**: User stories referencing increments (`increments: [0050-...]`)
233
- **ONLY ALLOWED**: `INCREMENT → FEATURE → USER STORIES` (forward reference only)
82
+ **At `.specweave/increments/` root - ONLY**: `####-name/` folders, `_archive/`, `README.md`
234
83
 
235
- **Why**: Hooks break, circular dependencies, multi-increment support broken
84
+ **Inside increment folders - ONLY at root**: `spec.md`, `plan.md`, `tasks.md`, `metadata.json`
85
+ **Everything else → subfolders**: `reports/`, `scripts/`, `logs/`, `backups/`, `docs/`
236
86
 
237
87
  ---
238
88
 
239
- ## 11. Task Format with US Linkage
89
+ ## Key Formats
240
90
 
91
+ ### Task Format (MANDATORY)
241
92
  ```markdown
242
93
  ### T-001: Task Title
243
94
  **User Story**: US-001 ← MANDATORY
@@ -245,383 +96,107 @@ import { mkdirpSync, writeJsonSync } from '../utils/fs-native.js';
245
96
  **Status**: [x] completed
246
97
  ```
247
98
 
248
- ---
249
-
250
- ## 12. ADR Naming
251
-
252
- **Format**: `XXXX-decision-title.md` (4-digit, kebab-case, NO `adr-` prefix)
253
- **Header**: `# ADR-XXXX: Decision Title`
254
- **Location**: `.specweave/docs/internal/architecture/adr/`
255
-
256
- **Auto-numbering**:
257
- ```bash
258
- ls .specweave/docs/internal/architecture/adr/*.md | grep -E '/[0-9]{4}-' | \
259
- sed 's/.*\/\([0-9][0-9][0-9][0-9]\)-.*/\1/' | sort -u | tail -1 | \
260
- awk '{printf "Next ADR: %04d\n", $1 + 1}'
261
- ```
262
-
263
- ---
264
-
265
- ## 13. Structured Data Matching
99
+ ### GitHub Issue Format
100
+ **ONLY**: `[FS-XXX][US-YYY] User Story Title`
101
+ **PROHIBITED**: `[SP-*]`, `[FS-XXX]` alone, `[undefined][US-XXX]`
266
102
 
267
- **NEVER use string search for frontmatter/IDs**:
268
-
269
- ```typescript
270
- // ❌ WRONG: content.includes('FS-039') // Matches "See FS-039"!
271
- // ✅ CORRECT: const match = content.match(/^feature_id:\s*["']?([^"'\n]+)["']?$/m);
272
- ```
273
-
274
- ---
275
-
276
- ## 14. Marketplace Plugin Completeness
277
-
278
- **Complete plugin requires**: `agents/`, `commands/`, OR `lib/` (not just `.claude-plugin/` + `skills/`)
279
-
280
- **MANDATORY**: `bash scripts/validate-marketplace-plugins.sh`
281
-
282
- ---
283
-
284
- ## 15. Skills vs Agents
285
-
286
- | Aspect | Skills | Agents |
287
- |--------|--------|--------|
288
- | **Location** | `plugins/*/skills/name/SKILL.md` | `plugins/*/agents/name/AGENT.md` |
289
- | **Invocation** | `Skill()` or `/command` | `Task()` with `subagent_type` |
290
- | **Activation** | Automatic (keywords) | Explicit |
291
-
292
- **Agent naming**: `{plugin}:{directory}:{yaml-name}`
293
-
294
- ### Skills Must NOT Spawn Large Content-Generating Agents (ADR-0133)
295
-
296
- **CRITICAL**: Skills spawning agents via `Task()` causes Claude Code crashes due to context explosion.
297
-
298
- **Problem**: Skill (1500 lines) + Agent (600 lines) + Agent output (2000+ lines) = 4000+ lines in memory = CRASH 💥
299
-
300
- **❌ FORBIDDEN**:
301
- ```typescript
302
- // In a skill SKILL.md:
303
- Task({
304
- subagent_type: "specweave:architect:architect", // ❌ Generates 1000-3000 lines
305
- subagent_type: "specweave:pm:pm", // ❌ Generates 500-2000 lines
306
- subagent_type: "specweave:test-aware-planner", // ❌ Generates 500-1500 lines
307
- });
308
- ```
309
-
310
- **✅ CORRECT**:
311
- ```typescript
312
- // Skills create templates and guide users:
313
- 1. Create basic templates (< 50 lines each)
314
- 2. Output: "Tell Claude: 'Complete the spec for increment 0005-feature'"
315
- 3. Agents activate in MAIN context (not nested) = SAFE
316
- ```
317
-
318
- **When to use Task() from skills**:
319
- - ✅ Small utility agents (output < 200 lines)
320
- - ✅ Data processing agents (no large generation)
321
- - ❌ Content generators (specs, ADRs, plans, tasks)
322
-
323
- **Main Context Pattern**: Same explosion occurs when editing files outside active increments. Large increment spec (800+ lines) + unrelated file edit (2000+ lines) + tool invocation (AskUserQuestion) = crash. Solution: Pause increment before editing unrelated files (see Section 0).
324
-
325
- **Reference**: ADR-0133, Architect crash incident (2025-11-24, Increment 0052); Context explosion incident (2025-11-24, Increment 0058, init.ts edit)
326
-
327
- ---
328
-
329
- ## 16. YAML Frontmatter
330
-
331
- **Required**:
103
+ ### YAML Frontmatter (spec.md)
332
104
  ```yaml
333
105
  ---
334
- increment: 0001-feature-name # REQUIRED: 4-digit + kebab-case
106
+ increment: 0001-feature-name # REQUIRED
335
107
  feature_id: FS-001 # OPTIONAL
336
108
  ---
337
109
  ```
338
110
 
339
- **Validation**: Pre-commit hook, spec parser, `/specweave:validate 0001`
111
+ ### ADR Naming
112
+ **Format**: `XXXX-decision-title.md` (4-digit, NO `adr-` prefix)
113
+ **Location**: `.specweave/docs/internal/architecture/adr/`
340
114
 
341
115
  ---
342
116
 
343
- ## 17. Git Provider Abstraction
117
+ ## Important Rules
344
118
 
345
- **Interface-driven multi-platform support**:
346
- - GitHub, GitLab, Bitbucket, Azure DevOps, Local Git
119
+ ### NO Increment-to-Increment References
120
+ **FORBIDDEN**: User stories referencing increments (`increments: [0050-...]`)
121
+ **ONLY ALLOWED**: `INCREMENT → FEATURE → USER STORIES` (forward reference only)
347
122
 
348
- **Usage**:
123
+ ### Structured Data Matching
349
124
  ```typescript
350
- import { getPlatformRegistry } from './platform-registry.js';
351
- const provider = registry.getProvider('github');
352
- const result = await provider.validateRepository('owner', 'repo', token);
125
+ // WRONG: content.includes('FS-039') // Matches "See FS-039"!
126
+ // CORRECT: content.match(/^feature_id:\s*["']?([^"'\n]+)["']?$/m)
353
127
  ```
354
128
 
355
- **NEVER**: Hardcode platform names, API endpoints, Git hosts
356
-
357
- ---
358
-
359
- ### 17a. GitHub Multi-Repo Init Flow (v0.26.3 - ADR-0132)
129
+ ### GitHub Duplicates
130
+ Use `DuplicateDetector.createWithProtection()`, NEVER `--limit 1` in gh searches
360
131
 
361
- **Rule**: NEVER early returns in routing code. Use mapping.
132
+ ### AC Presence in spec.md
133
+ **MANDATORY** - even with external living docs. Use `/specweave:embed-acs` if missing.
362
134
 
363
- ```typescript
364
- // ❌ if (option === 'advanced') return { type: 'basic' };
365
- // ✅ let mapped = undefined; if (option === 'advanced') mapped = 'enhanced';
366
- ```
135
+ ### Git Provider Abstraction
136
+ Use `getPlatformRegistry().getProvider('github')`. NEVER hardcode platform names/endpoints.
367
137
 
368
138
  ---
369
139
 
370
- ## Sync Orchestration Architecture (v0.26.3+)
371
-
372
- ### **How GitHub Issue Sync Works**
373
-
374
- **3-Phase Sync Flow**:
375
- ```
376
- TodoWrite → Hook → US Completion Orchestrator → Living Docs Sync → External Tool Sync → GitHub Issues Updated
377
- ```
378
-
379
- **Phase 1: Task Completion Detection**
380
- - User marks task complete via `TodoWrite`
381
- - `post-task-completion.sh` fires (sets `SKIP_GITHUB_SYNC=true` to prevent duplicate syncs)
382
- - `consolidated-sync.js` runs 6 operations sequentially
383
-
384
- **Phase 2: US Completion Orchestration**
385
- - `syncCompletedUserStories()` (operation 5 of 6) detects newly completed user stories
386
- - Checks if all ACs for a US are complete (100% → status: "completed")
387
- - **Throttle**: 60s window prevents spam (manual override: `/specweave:sync-progress`)
388
- - If newly completed USs found → triggers Phase 3
389
-
390
- **Phase 3: External Tool Sync**
391
- - `LivingDocsSync.syncIncrement()` called
392
- - `detectExternalTools()` checks **3 levels** for GitHub config:
393
- - **Level 1**: `metadata.json` (increment-cached links)
394
- - **Level 2**: `config.json` - **4 detection methods** (ADR-0137):
395
- - Method 1: `config.sync.github.enabled` ← **Most common (60% of users)**
396
- - Method 2: `config.sync.profiles[activeProfile]` ← Multi-profile setups
397
- - Method 3: `config.multiProject.projects[project].externalTools.github` ← Multi-project
398
- - Method 4: `config.plugins.settings['specweave-github']` ← Legacy
399
- - **Level 3**: Environment variables (`GITHUB_TOKEN` + `GITHUB_OWNER`/`GITHUB_REPOSITORY`)
400
- - If GitHub detected → `syncToGitHub()` → `GitHubFeatureSync.syncFeatureToGitHub()`
401
- - Updates GitHub issues with completed AC checkboxes
402
-
403
- ### **GitHub Configuration (Required)**
404
-
405
- **Recommended Setup (Pattern 1 - Simplest)**:
406
- ```json
407
- // .specweave/config.json
408
- {
409
- "sync": {
410
- "github": {
411
- "enabled": true,
412
- "owner": "your-org",
413
- "repo": "your-repo"
414
- }
415
- }
416
- }
417
- ```
418
-
419
- **Plus `.env`**:
420
- ```bash
421
- GITHUB_TOKEN=ghp_your_token_here
422
- GITHUB_OWNER=your-org # Optional if in config.json
423
- GITHUB_REPO=your-repo # Optional if in config.json
424
- ```
425
-
426
- **Diagnostic**: Run `node dist/test-github-detection.js` to verify detection (create this file if needed)
140
+ ## Configuration
427
141
 
428
- ### **Troubleshooting Sync Issues**
429
-
430
- **Issue**: GitHub issues not updating after US completion
431
- **Diagnosis**:
432
- ```bash
433
- # 1. Check detection
434
- grep "External tools detected" .specweave/logs/hooks-debug.log | tail -5
435
- # Should see: "📡 External tools detected: github"
436
-
437
- # 2. Check config
438
- cat .specweave/config.json | jq '.sync.github'
439
- # Should have: enabled: true, owner: "...", repo: "..."
440
-
441
- # 3. Check throttle
442
- grep "throttled" .specweave/logs/hooks-debug.log | tail -3
443
- # If throttled → wait 60s OR run: /specweave:sync-progress
444
- ```
445
-
446
- **Issue**: Throttle blocking sync
447
- **Solution**: Manual sync (bypasses throttle):
448
- ```bash
449
- /specweave:sync-progress 0054 # Sync specific increment
450
- /specweave-github:sync FS-054 # Sync entire feature
451
- ```
452
-
453
- **Issue**: Detection not finding GitHub config
454
- **Fix**: ADR-0137 enhanced detection (v0.26.3+)
455
- - Checks 4 config locations + env vars
456
- - Update to latest version: `npm update specweave`
457
-
458
- ## Hook Performance & Safety
459
-
460
- **Emergency**: `export SPECWEAVE_DISABLE_HOOKS=1` → `rm -f .specweave/state/.hook-*` → `npm run rebuild`
461
-
462
- **Mandatory Checklist**: PROJECT_ROOT first, kill switch, circuit breaker, file lock, debounce (5s), `set +e`, `exit 0`, active-only filtering
463
- **Never**: `set -e`, sync spawns, error propagation
464
- **Targets**: <100ms, 0-2 processes, 0 breaker trips
465
-
466
- **Critical Fixes**:
467
- - v0.26.3: **Multi-location GitHub config detection!** (ADR-0137) → Checks 4 config patterns + env vars
468
- - v0.26.1: **Automatic US sync restored!** `SKIP_US_SYNC` removed → Smart throttle (60s window) → fs.writeFile() validated safe
469
- - v0.25.2: `SKIP_EXTERNAL_SYNC` guard at LivingDocsSync layer → prevents recursion cascade
470
- - v0.25.1: TodoWrite crash → emergency `SKIP_US_SYNC=true` → manual `/specweave:sync-progress` (temporary fix)
471
- - v0.25.0: 6→4 hooks (33% reduction)
472
- - v0.24.4: State-based filtering (95% overhead reduction)
473
- - v0.26.1: PROJECT_ROOT before RECURSION_GUARD_FILE (order bug fix)
142
+ **Secrets** (`.env`, gitignored): Tokens, PATs, emails
143
+ **Config** (`.specweave/config.json`, committed): Domains, strategies, sync settings
474
144
 
475
145
  ---
476
146
 
477
- ## Development Workflow
147
+ ## Commands
478
148
 
479
- **Core commands**:
480
149
  ```bash
481
- /specweave:increment "feature" # Plan
482
- /specweave:do # Execute
483
- /specweave:progress # Status
484
- /specweave:sync-progress # Comprehensive sync (tasks → docs → external tools)
485
- /specweave:done 0002 # Close (validates)
486
- /specweave:validate 0001 # Validate
487
- /specweave:qa 0001 # Quality check
488
-
489
- # Feature deletion
490
- specweave delete-feature FS-042 --dry-run # Preview
491
- specweave delete-feature FS-042 # Safe delete (requires confirmation)
492
- specweave delete-feature FS-042 --force # Force (orphans active increments)
150
+ /specweave:increment "feature" # Plan new increment
151
+ /specweave:do # Execute tasks
152
+ /specweave:done 0002 # Close (validates gates)
153
+ /specweave:progress # Show status
154
+ /specweave:sync-progress # Full sync (tasks→docs→GitHub/JIRA/ADO)
155
+ /specweave:validate 0001 # Validate increment
493
156
  ```
494
157
 
495
158
  ---
496
159
 
497
160
  ## Build & Test
498
161
 
499
- **Build**: `npm run rebuild` (clean + build), `npm run build`
500
- **Architecture**: `tsc` → `dist/src/`, esbuild → hooks, copy deps → `plugins/*/lib/vendor/`
501
- **CRITICAL**: Always `.js` extensions in imports
502
-
503
- **Test**:
504
162
  ```bash
505
- npm test # Smoke
506
- npm run test:unit # Unit
507
- npm run test:integration # Integration
508
- npm run test:all # All
509
- npm run test:coverage # Coverage (80%+ required)
163
+ npm run rebuild # Clean + build (tsc → dist/, esbuild → hooks)
164
+ npm test # Smoke tests
165
+ npm run test:all # All tests (80%+ coverage required)
510
166
  ```
511
167
 
512
- **Test rules**: `vi.fn()` (NOT `jest.fn()`), `os.tmpdir()` (NOT `process.cwd()`), `.test.ts` (NOT `.spec.ts`)
513
-
514
- ---
515
-
516
- ## Configuration Management
517
-
518
- **Secrets** (.env, gitignored) vs **Config** (.specweave/config.json, committed)
519
-
520
- | Type | Location | Committed? |
521
- |------|----------|------------|
522
- | Tokens/Emails | `.env` | ❌ |
523
- | Domains/Strategies | `config.json` | ✅ |
524
-
525
- ---
526
-
527
- ## Cache Management
528
-
529
- **Location**: `.specweave/cache/`, **TTL**: 24 hours
530
-
531
- **Cached**: JIRA projects, ADO config, boards, components (NOT tokens/PATs)
532
-
533
- **Manual**: `/specweave-jira:refresh-cache --all`, `/specweave:cleanup-cache --older-than 7d`
534
-
535
- ---
536
-
537
- ## Comprehensive Progress Sync
538
-
539
- **Command**: `/specweave:sync-progress [increment]`
540
-
541
- **Flow**: tasks.md → spec.md ACs → living docs → external tools (GitHub/JIRA/ADO) → status line
542
-
543
- **Replaces 4 commands**: `/specweave:sync-acs` + `/specweave:sync-specs` + `/specweave-github:sync` + `/specweave:update-status`
544
-
545
- **Flags**: `--dry-run`, `--no-github`, `--no-jira`, `--no-ado`, `--force`
546
-
547
- **When to use**: After completing tasks, before closing increment, bulk completion
548
-
549
- ---
550
-
551
- ## Safe Feature Deletion
552
-
553
- **Command**: `specweave delete-feature <feature-id>`
554
-
555
- **4-Tier Validation**: Feature detection → active increment check → git status → GitHub scan
556
- **3-Phase Commit**: Validation → staging (reversible) → commit (irreversible)
557
- **Multi-Gate Confirmation**: Primary (y/N) → elevated (type "delete" in force mode) → GitHub (separate)
558
-
559
- **Deletes**: Living docs FEATURE.md, user stories, README, GitHub issues
560
- **NOT deleted**: Increments (metadata.json updated if orphaned)
561
-
562
- **Modes**: Safe (default, blocks active increments), Force (`--force`, orphans increments), Dry-run (`--dry-run`, preview)
563
-
564
- **Audit**: `.specweave/logs/feature-deletions.log` (JSON Lines, includes commit SHA)
168
+ **Plugin validation**: `bash scripts/validate-marketplace-plugins.sh`
565
169
 
566
170
  ---
567
171
 
568
- ## Project Structure
172
+ ## Emergency
569
173
 
174
+ ```bash
175
+ export SPECWEAVE_DISABLE_HOOKS=1
176
+ rm -f .specweave/state/.hook-*
177
+ npm run rebuild
570
178
  ```
571
- src/ # TypeScript → dist/
572
- plugins/ # Skills, agents, commands, hooks
573
- ├── specweave/ # Core
574
- └── specweave-*/ # Optional
575
- .specweave/ # Increments, docs, logs
576
- ```
577
-
578
- ---
579
179
 
580
- ## Plugin Hook Registration
581
-
582
- **Valid events** (10): PostToolUse, PreToolUse, PermissionRequest, Notification, UserPromptSubmit, Stop, SubagentStop, PreCompact, SessionStart, SessionEnd
583
-
584
- ```json
585
- {
586
- "hooks": {
587
- "PostToolUse": [{
588
- "matcher": "TodoWrite",
589
- "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/post-task-completion.sh", "timeout": 10 }]
590
- }]
591
- }
592
- }
593
- ```
180
+ **Recovery docs**: `.specweave/docs/internal/emergency-procedures/`
594
181
 
595
182
  ---
596
183
 
597
184
  ## Quick Reference
598
185
 
599
- **Commands**: `/specweave:increment`, `/specweave:do`, `/specweave:done`, `/specweave:progress`, `/specweave:validate`, `/specweave:qa`
600
-
601
- **Build**: `npm run rebuild`, `npm test`, `npm run test:all`
602
-
603
- **Structure**: `src/` (TS), `plugins/` (components), `.specweave/` (data), `tests/` (tests)
604
-
605
- **Remember**:
606
- 1. Push → GitHub → auto-updates (5-10s)
607
- 2. **Keep increment roots clean**: Only spec.md, plan.md, tasks.md, metadata.json. Everything else in subfolders (reports/, scripts/, logs/, backups/, docs/)
608
- 3. Test before commit
609
- 4. NEVER delete `.specweave/`
610
- 5. Use `/specweave:done` (not manual edits)
611
- 6. ALWAYS use GitHub mode for marketplace refresh (unless actively developing uncommitted changes)
612
- 7. tasks.md + spec.md are SOURCE OF TRUTH (not internal TODO)
613
- 8. Pause large increments (10+ tasks) before editing unrelated files to prevent crashes
614
-
615
- **See**: `.github/CONTRIBUTING.md`, https://spec-weave.com
186
+ | Aspect | Rule |
187
+ |--------|------|
188
+ | Skills vs Agents | Skills = auto-activate (keywords), Agents = explicit `Task()` |
189
+ | Hook events | PostToolUse, PreToolUse, UserPromptSubmit, Stop, SessionStart/End, etc. |
190
+ | Cache location | `.specweave/cache/` (24h TTL) |
191
+ | Pre-commit | Blocks 50+ deletions, `rm -rf` on protected dirs |
616
192
 
617
193
  ---
618
194
 
619
195
  ## References
620
196
 
621
- **ADRs**: 0032 (GitHub Hierarchy), 0050 (Config Management), 0051 (Caching), 0060 (Hook Optimization), 0061 (No Increment References), 0064 (AC Presence), 0069 (Git Provider Abstraction), 0070 (Hook Consolidation), 0129 (US Sync Guard Rails), 0132 (No Early Returns)
622
-
623
- **Emergency Procedures**: `.specweave/docs/internal/emergency-procedures/HOOK-CRASH-RECOVERY.md`, `TODOWRITE-CRASH-RECOVERY.md`, `AC-SYNC-CONFLICT-FIX-2025-11-24.md`, `CONTEXT-EXPLOSION-PREVENTION.md`
624
-
625
- **Incident Reports**: See increment 0044 (TODO desync), 0047 (GitHub sync removal), 0050 (Hook crashes, AC presence, GitHub issues), 0051 (PROJECT_ROOT order), 0053 (Safe deletion, TodoWrite crash, AC parser, GitHub multi-repo), 0058 (Context explosion, init.ts edit crash)
197
+ **Internal Docs**: `.specweave/docs/internal/`
198
+ - `sync-architecture.md` - GitHub sync flow, troubleshooting
199
+ - `architecture/adr/` - Decision records (ADR-0032, 0060, 0129, etc.)
200
+ - `emergency-procedures/` - Crash recovery guides
626
201
 
627
- **Validation Scripts**: `validate-marketplace-plugins.sh`, `validate-plugin-directories.sh`, `validate-hook-variable-order.sh`, `cleanup-duplicate-github-issues.sh`
202
+ **External**: `.github/CONTRIBUTING.md`, https://spec-weave.com