specpulse 1.0.6__py3-none-any.whl → 1.2.0__py3-none-any.whl

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 (54) hide show
  1. specpulse/__init__.py +1 -1
  2. specpulse/cli/main.py +809 -617
  3. specpulse/core/specpulse.py +1140 -1105
  4. specpulse/resources/commands/claude/sp-continue.md +203 -0
  5. specpulse/resources/commands/claude/sp-decompose.md +227 -0
  6. specpulse/resources/commands/claude/sp-plan.md +220 -0
  7. specpulse/resources/commands/claude/sp-pulse.md +142 -0
  8. specpulse/resources/commands/claude/{spec.md → sp-spec.md} +36 -23
  9. specpulse/resources/commands/claude/sp-status.md +170 -0
  10. specpulse/resources/commands/claude/sp-task.md +315 -0
  11. specpulse/resources/commands/gemini/sp-continue.toml +56 -0
  12. specpulse/resources/commands/gemini/sp-decompose.toml +54 -0
  13. specpulse/resources/commands/gemini/sp-plan.toml +68 -0
  14. specpulse/resources/commands/gemini/{pulse.toml → sp-pulse.toml} +12 -6
  15. specpulse/resources/commands/gemini/sp-spec.toml +54 -0
  16. specpulse/resources/commands/gemini/sp-status.toml +61 -0
  17. specpulse/resources/commands/gemini/sp-task.toml +79 -0
  18. specpulse/resources/memory/constitution.md +5 -5
  19. specpulse/resources/memory/context.md +53 -1
  20. specpulse/resources/scripts/sp-pulse-decompose.py +66 -0
  21. specpulse/resources/scripts/sp-pulse-decompose.sh +56 -0
  22. specpulse/resources/scripts/{pulse-init.py → sp-pulse-init.py} +6 -6
  23. specpulse/resources/scripts/{pulse-init.sh → sp-pulse-init.sh} +95 -95
  24. specpulse/resources/scripts/{pulse-plan.py → sp-pulse-plan.py} +32 -7
  25. specpulse/resources/scripts/{pulse-plan.sh → sp-pulse-plan.sh} +136 -126
  26. specpulse/resources/scripts/{pulse-spec.py → sp-pulse-spec.py} +26 -6
  27. specpulse/resources/scripts/{pulse-spec.sh → sp-pulse-spec.sh} +126 -103
  28. specpulse/resources/scripts/{pulse-task.py → sp-pulse-task.py} +42 -6
  29. specpulse/resources/scripts/{pulse-task.sh → sp-pulse-task.sh} +32 -16
  30. specpulse/resources/templates/decomposition/api-contract.yaml +22 -0
  31. specpulse/resources/templates/decomposition/integration-plan.md +134 -0
  32. specpulse/resources/templates/decomposition/interface.ts +20 -0
  33. specpulse/resources/templates/decomposition/microservices.md +34 -0
  34. specpulse/resources/templates/decomposition/service-plan.md +168 -0
  35. specpulse/resources/templates/plan.md +206 -206
  36. specpulse/resources/templates/spec.md +125 -125
  37. specpulse/resources/templates/task.md +164 -163
  38. {specpulse-1.0.6.dist-info → specpulse-1.2.0.dist-info}/METADATA +95 -36
  39. specpulse-1.2.0.dist-info/RECORD +50 -0
  40. specpulse/resources/commands/claude/plan.md +0 -184
  41. specpulse/resources/commands/claude/pulse.md +0 -91
  42. specpulse/resources/commands/claude/task.md +0 -237
  43. specpulse/resources/commands/gemini/plan.toml +0 -59
  44. specpulse/resources/commands/gemini/spec.toml +0 -45
  45. specpulse/resources/commands/gemini/task.toml +0 -69
  46. specpulse/resources/scripts/pulse-init.ps1 +0 -186
  47. specpulse/resources/scripts/pulse-plan.ps1 +0 -251
  48. specpulse/resources/scripts/pulse-spec.ps1 +0 -185
  49. specpulse/resources/scripts/pulse-task.ps1 +0 -263
  50. specpulse-1.0.6.dist-info/RECORD +0 -41
  51. {specpulse-1.0.6.dist-info → specpulse-1.2.0.dist-info}/WHEEL +0 -0
  52. {specpulse-1.0.6.dist-info → specpulse-1.2.0.dist-info}/entry_points.txt +0 -0
  53. {specpulse-1.0.6.dist-info → specpulse-1.2.0.dist-info}/licenses/LICENSE +0 -0
  54. {specpulse-1.0.6.dist-info → specpulse-1.2.0.dist-info}/top_level.txt +0 -0
@@ -1,1106 +1,1141 @@
1
- """
2
- SpecPulse Core Implementation
3
- """
4
-
5
- from pathlib import Path
6
- from datetime import datetime
7
- from typing import Dict, List, Optional
8
- import yaml
9
- import json
10
- import os
11
-
12
-
13
-
14
- class SpecPulse:
15
- """Core SpecPulse functionality"""
16
-
17
- def __init__(self, project_path: Optional[Path] = None):
18
- self.project_path = project_path or Path.cwd()
19
- self.config = self._load_config()
20
- # Get resource directory path using package data
21
- import pkg_resources
22
- try:
23
- # Get the actual path to the resources directory in the installed package
24
- self.resources_dir = Path(pkg_resources.resource_filename('specpulse', 'resources'))
25
- except:
26
- # Fallback to development path
27
- self.resources_dir = Path(__file__).parent.parent / "resources"
28
-
29
- def _load_config(self) -> Dict:
30
- """Load project configuration"""
31
- config_path = self.project_path / ".specpulse" / "config.yaml"
32
- if config_path.exists():
33
- with open(config_path, 'r') as f:
34
- return yaml.safe_load(f)
35
- return {}
36
-
37
- def get_spec_template(self) -> str:
38
- """Get specification template from file"""
39
- template_path = self.resources_dir / "templates" / "spec.md"
40
- if template_path.exists():
41
- with open(template_path, 'r', encoding='utf-8') as f:
42
- return f.read()
43
- # Fallback to embedded template if file not found
44
- return """<!-- SpecPulse Specification Template v1.0 -->
45
- <!-- AI Instructions: Fill this template based on user description -->
46
-
47
- # Specification: [FEATURE_NAME]
48
-
49
- ## Metadata
50
- - **ID**: SPEC-[XXX]
51
- - **Created**: [DATE]
52
- - **Author**: [USER]
53
- - **AI Assistant**: [CLAUDE|GEMINI]
54
- - **Version**: 1.0.0
55
-
56
- ## Executive Summary
57
- [One paragraph description of what this feature does and why it's needed]
58
-
59
- ## Problem Statement
60
- [Detailed description of the problem being solved]
61
-
62
- ## Proposed Solution
63
- [High-level approach to solving the problem]
64
-
65
- ## Detailed Requirements
66
-
67
- ### Functional Requirements
68
- <!-- AI: Generate numbered list of specific, testable requirements -->
69
-
70
- FR-001: [Requirement]
71
- - Acceptance: [How to verify this requirement is met]
72
- - Priority: [MUST|SHOULD|COULD]
73
-
74
- ### Non-Functional Requirements
75
-
76
- #### Performance
77
- - Response Time: [Target]
78
- - Throughput: [Target]
79
- - Resource Usage: [Limits]
80
-
81
- #### Security
82
- - Authentication: [Method]
83
- - Authorization: [Model]
84
- - Data Protection: [Requirements]
85
-
86
- #### Scalability
87
- - User Load: [Target]
88
- - Data Volume: [Target]
89
- - Geographic Distribution: [Requirements]
90
-
91
- ## User Stories
92
-
93
- <!-- AI: Generate user stories in standard format -->
94
-
95
- ### Story 1: [Title]
96
- **As a** [user type]
97
- **I want** [action/feature]
98
- **So that** [benefit/value]
99
-
100
- **Acceptance Criteria:**
101
- - [ ] [Criterion 1]
102
- - [ ] [Criterion 2]
103
- - [ ] [Criterion 3]
104
-
105
- ## Technical Constraints
106
- <!-- List any technical limitations or requirements -->
107
-
108
- ## Dependencies
109
- <!-- External services, libraries, or other features required -->
110
-
111
- ## Risks and Mitigations
112
- <!-- Identify potential risks and how to address them -->
113
-
114
- ## Open Questions
115
- <!-- Mark with [NEEDS CLARIFICATION] for items requiring user input -->
116
-
117
- ## Appendix
118
- <!-- Additional diagrams, mockups, or references -->
119
- """
120
-
121
- def get_plan_template(self) -> str:
122
- """Get implementation plan template from file"""
123
- template_path = self.resources_dir / "templates" / "plan.md"
124
- if template_path.exists():
125
- with open(template_path, 'r', encoding='utf-8') as f:
126
- return f.read()
127
- # Fallback to embedded template if file not found
128
- return """<!-- SpecPulse Implementation Plan Template v1.0 -->
129
- <!-- AI Instructions: Generate plan from specification -->
130
-
131
- # Implementation Plan: [FEATURE_NAME]
132
-
133
- ## Specification Reference
134
- - **Spec ID**: SPEC-[XXX]
135
- - **Generated**: [DATE]
136
- - **Optimization Focus**: [PERFORMANCE|SECURITY|SIMPLICITY|COST]
137
-
138
- ## Architecture Overview
139
- ```mermaid
140
- <!-- AI: Generate architecture diagram -->
141
- ```
142
-
143
- ## Technology Stack
144
-
145
- ### Core Technologies
146
- - **Language**: [Choice with rationale]
147
- - **Framework**: [Choice with rationale]
148
- - **Database**: [Choice with rationale]
149
- - **Cache**: [Choice with rationale]
150
-
151
- ### Supporting Tools
152
- - **Testing**: [Framework choice]
153
- - **CI/CD**: [Platform choice]
154
- - **Monitoring**: [Solution choice]
155
-
156
- ## Implementation Phases
157
-
158
- ### Phase 0: Setup and Prerequisites
159
- **Duration**: [Estimate]
160
- **Tasks**:
161
- 1. Environment setup
162
- 2. Repository initialization
163
- 3. Dependency installation
164
- 4. Configuration
165
-
166
- ### Phase 1: Data Layer
167
- **Duration**: [Estimate]
168
- **Deliverables**:
169
- - Database schema
170
- - Migration scripts
171
- - Data models
172
- - Repository pattern implementation
173
-
174
- **Tasks**:
175
- 1. Design database schema
176
- 2. Create migration scripts
177
- 3. Implement data models
178
- 4. Create repository interfaces
179
- 5. Write data layer tests
180
-
181
- ### Phase 2: Business Logic
182
- **Duration**: [Estimate]
183
- **Deliverables**:
184
- - Service layer
185
- - Business rules implementation
186
- - Validation logic
187
-
188
- **Tasks**:
189
- 1. Implement service interfaces
190
- 2. Create business logic modules
191
- 3. Add validation rules
192
- 4. Implement error handling
193
- 5. Write unit tests
194
-
195
- ### Phase 3: API Layer
196
- **Duration**: [Estimate]
197
- **Deliverables**:
198
- - REST/GraphQL endpoints
199
- - API documentation
200
- - Authentication/Authorization
201
-
202
- **Tasks**:
203
- 1. Design API contracts
204
- 2. Implement endpoints
205
- 3. Add authentication
206
- 4. Create API documentation
207
- 5. Write integration tests
208
-
209
- ### Phase 4: Testing and Optimization
210
- **Duration**: [Estimate]
211
- **Deliverables**:
212
- - Complete test suite
213
- - Performance optimization
214
- - Security hardening
215
-
216
- **Tasks**:
217
- 1. Complete test coverage
218
- 2. Performance testing
219
- 3. Security audit
220
- 4. Load testing
221
- 5. Documentation
222
-
223
- ## File Structure
224
- ```
225
- [feature-name]/
226
- ├── src/
227
- │ ├── models/
228
- │ ├── services/
229
- │ ├── controllers/
230
- │ └── utils/
231
- ├── tests/
232
- │ ├── unit/
233
- │ ├── integration/
234
- └── e2e/
235
- ├── docs/
236
- └── config/
237
- ```
238
-
239
- ## API Contracts
240
-
241
- ### Endpoint: [ENDPOINT_NAME]
242
- ```yaml
243
- method: POST
244
- path: /api/v1/[resource]
245
- request:
246
- headers:
247
- Content-Type: application/json
248
- Authorization: Bearer {token}
249
- body:
250
- field1: string
251
- field2: number
252
- response:
253
- 200:
254
- success: true
255
- data: object
256
- 400:
257
- error: string
258
- ```
259
-
260
- ## Data Models
261
-
262
- ### Entity: [ENTITY_NAME]
263
- ```yaml
264
- fields:
265
- id: uuid
266
- created_at: timestamp
267
- updated_at: timestamp
268
- [field_name]: [type]
269
- relations:
270
- [relation_name]: [type]
271
- indexes:
272
- - [field_name]
273
- ```
274
-
275
- ## Testing Strategy
276
-
277
- ### Unit Tests
278
- - Coverage Target: 80%
279
- - Framework: [Choice]
280
- - Mock Strategy: [Approach]
281
-
282
- ### Integration Tests
283
- - API Contract Tests
284
- - Database Integration Tests
285
- - External Service Tests
286
-
287
- ### E2E Tests
288
- - Critical User Journeys
289
- - Performance Benchmarks
290
- - Security Scenarios
291
-
292
- ## Constitution Compliance
293
-
294
- ### Principle Validation
295
- - [ ] Single Responsibility: Each component has one purpose
296
- - [ ] Test-First: Tests written before implementation
297
- - [ ] Documentation: All code is documented
298
- - [ ] Security: Security considered by design
299
- - [ ] Performance: Meets performance targets
300
-
301
- ## Risk Assessment
302
-
303
- ### Technical Risks
304
- | Risk | Probability | Impact | Mitigation |
305
- |------|------------|--------|------------|
306
- | [Risk] | [H/M/L] | [H/M/L] | [Strategy] |
307
-
308
- ### Timeline Risks
309
- | Risk | Probability | Impact | Mitigation |
310
- |------|------------|--------|------------|
311
- | [Risk] | [H/M/L] | [H/M/L] | [Strategy] |
312
-
313
- ## Success Criteria
314
- - [ ] All functional requirements implemented
315
- - [ ] Test coverage > 80%
316
- - [ ] Performance targets met
317
- - [ ] Security audit passed
318
- - [ ] Documentation complete
319
- """
320
-
321
- def get_task_template(self) -> str:
322
- """Get task list template from file"""
323
- template_path = self.resources_dir / "templates" / "task.md"
324
- if template_path.exists():
325
- with open(template_path, 'r', encoding='utf-8') as f:
326
- return f.read()
327
- # Fallback to embedded template if file not found
328
- return """<!-- SpecPulse Task List Template v1.0 -->
329
- <!-- AI Instructions: Generate from implementation plan -->
330
-
331
- # Task List: [FEATURE_NAME]
332
-
333
- ## Metadata
334
- - **Plan Reference**: [PLAN_ID]
335
- - **Total Tasks**: [COUNT]
336
- - **Estimated Duration**: [TOTAL_HOURS]
337
- - **Parallel Groups**: [COUNT]
338
-
339
- ## Task Organization
340
-
341
- ### 🔄 Parallel Group A
342
- *These tasks can be executed simultaneously*
343
-
344
- #### TASK-001: [Task Name]
345
- - **Type**: [setup|development|testing|documentation]
346
- - **Priority**: [HIGH|MEDIUM|LOW]
347
- - **Estimate**: [hours]
348
- - **Dependencies**: None
349
- - **Description**: [What needs to be done]
350
- - **Acceptance**: [How to verify completion]
351
- - **Assignable**: [role/skill required]
352
-
353
- #### TASK-002: [Task Name]
354
- [Same structure as above]
355
-
356
- ### 📝 Sequential Tasks
357
- *These tasks must be completed in order*
358
-
359
- #### TASK-003: [Task Name]
360
- - **Dependencies**: TASK-001
361
- [Rest of structure]
362
-
363
- ### 🎯 Critical Path
364
- *Tasks that directly impact timeline*
365
-
366
- 1. TASK-001 → TASK-003 → TASK-007
367
- 2. Estimated critical path duration: [hours]
368
-
369
- ## Task Details
370
-
371
- ### Development Tasks
372
- - [ ] TASK-XXX: Implement [component]
373
- - [ ] TASK-XXX: Create [feature]
374
- - [ ] TASK-XXX: Integrate [service]
375
-
376
- ### Testing Tasks
377
- - [ ] TASK-XXX: Write unit tests for [component]
378
- - [ ] TASK-XXX: Create integration tests
379
- - [ ] TASK-XXX: Perform security testing
380
-
381
- ### Documentation Tasks
382
- - [ ] TASK-XXX: Document API endpoints
383
- - [ ] TASK-XXX: Create user guide
384
- - [ ] TASK-XXX: Update README
385
-
386
- ## Execution Schedule
387
-
388
- ### Day 1-2
389
- - Morning: TASK-001, TASK-002 (parallel)
390
- - Afternoon: TASK-003
391
-
392
- ### Day 3-4
393
- - Morning: TASK-004
394
- - Afternoon: TASK-005, TASK-006
395
-
396
- ## Progress Tracking
397
- ```yaml
398
- status:
399
- total: [count]
400
- completed: 0
401
- in_progress: 0
402
- blocked: 0
403
-
404
- metrics:
405
- velocity: [tasks/day]
406
- estimated_completion: [date]
407
- blockers: []
408
- ```
409
- """
410
-
411
- def get_constitution_template(self) -> str:
412
- """Get constitution template from file"""
413
- template_path = self.resources_dir / "memory" / "constitution.md"
414
- if template_path.exists():
415
- with open(template_path, 'r', encoding='utf-8') as f:
416
- return f.read()
417
- # Fallback to embedded template if file not found
418
- return """# Project Constitution
419
-
420
- ## Immutable Principles
421
-
422
- ### Principle 1: Simplicity First
423
- Every solution must start with the simplest approach that could work.
424
- Complexity is added only when proven necessary.
425
-
426
- ### Principle 2: Test-Driven Development
427
- No production code without tests.
428
- Tests are written first, implementation follows.
429
-
430
- ### Principle 3: Single Responsibility
431
- Each module, function, and component does one thing well.
432
- If you need "and" to describe it, split it.
433
-
434
- ### Principle 4: Documentation as Code
435
- Documentation lives with code.
436
- If it's not documented, it doesn't exist.
437
-
438
- ### Principle 5: Security by Design
439
- Security is not an afterthought.
440
- Every feature considers security implications from the start.
441
-
442
- ## Technical Standards
443
-
444
- ### Code Style
445
- - Python: PEP 8 with type hints
446
- - JavaScript: StandardJS
447
- - Go: Official Go formatting
448
-
449
- ### Testing Requirements
450
- - Minimum 80% code coverage
451
- - All API endpoints must have contract tests
452
- - Critical paths require E2E tests
453
-
454
- ### Performance Targets
455
- - API response time: < 200ms (p95)
456
- - Page load time: < 2 seconds
457
- - Database queries: < 50ms
458
-
459
- ### Security Requirements
460
- - All data encrypted in transit (TLS 1.3+)
461
- - Sensitive data encrypted at rest
462
- - Authentication: OAuth 2.0 / JWT
463
- - Authorization: RBAC with least privilege
464
-
465
- ## Architecture Rules
466
-
467
- ### Service Boundaries
468
- - Services communicate only through defined APIs
469
- - No shared databases between services
470
- - Each service owns its data
471
-
472
- ### Data Management
473
- - Single source of truth for each data type
474
- - Event sourcing for audit requirements
475
- - CQRS where read/write patterns differ
476
-
477
- ### Error Handling
478
- - All errors are handled explicitly
479
- - User-facing errors are helpful and actionable
480
- - System errors are logged with context
481
-
482
- ## Amendment Process
483
-
484
- Changes to this constitution require:
485
- 1. Documented rationale
486
- 2. Team consensus
487
- 3. Gradual migration plan
488
- 4. Update to all affected documentation
489
- """
490
-
491
- def get_context_template(self) -> str:
492
- """Get context template from file"""
493
- template_path = self.resources_dir / "memory" / "context.md"
494
- if template_path.exists():
495
- with open(template_path, 'r', encoding='utf-8') as f:
496
- return f.read()
497
- # Fallback to embedded template if file not found
498
- return """# Project Context
499
-
500
- ## Current State
501
- Last Updated: [AI updates this automatically]
502
-
503
- ### Active Features
504
- 1. **[feature-name]** (SPEC-XXX)
505
- - Status: [Phase]
506
- - Branch: [branch-name]
507
- - Blockers: [None|List]
508
-
509
- ### Recent Decisions
510
- - [Decision with rationale]
511
-
512
- ### Known Issues
513
- - [Issue description]
514
-
515
- ## Team Preferences
516
-
517
- ### Technology Choices
518
- - **Preferred Stack**: [Stack]
519
- - **Testing**: [Framework]
520
- - **CI/CD**: [Platform]
521
- - **Deployment**: [Method]
522
-
523
- ### Coding Patterns
524
- - [Pattern preference]
525
-
526
- ## Project Glossary
527
-
528
- ### Domain Terms
529
- - **[Term]**: [Definition]
530
-
531
- ### Technical Terms
532
- - **[Term]**: [Definition]
533
- """
534
-
535
- def get_decisions_template(self) -> str:
536
- """Get architectural decisions template from file"""
537
- template_path = self.resources_dir / "memory" / "decisions.md"
538
- if template_path.exists():
539
- with open(template_path, 'r', encoding='utf-8') as f:
540
- return f.read()
541
- # Fallback to embedded template if file not found
542
- return """# Architectural Decisions
543
-
544
- ## Decision Log
545
-
546
- ### ADR-001: [Title]
547
- **Date**: [DATE]
548
- **Status**: [PROPOSED|ACCEPTED|DEPRECATED]
549
- **Context**: [Why this decision was needed]
550
- **Decision**: [What was decided]
551
- **Consequences**: [What happens as a result]
552
- **Alternatives Considered**: [Other options that were evaluated]
553
-
554
- ---
555
-
556
- ### ADR-002: [Title]
557
- [Same structure as above]
558
- """
559
-
560
- def get_setup_script(self) -> str:
561
- """Get pulse-init script for feature initialization from file"""
562
- script_path = self.resources_dir / "scripts" / "pulse-init.sh"
563
- if script_path.exists():
564
- with open(script_path, 'r', encoding='utf-8') as f:
565
- return f.read()
566
- # Fallback to embedded script if file not found
567
- return """#!/bin/bash
568
- # SpecPulse Feature Initialization Script
569
-
570
- set -e
571
-
572
- # Get feature name from argument
573
- FEATURE_NAME="$1"
574
- if [ -z "$FEATURE_NAME" ]; then
575
- echo "Error: Feature name required"
576
- exit 1
577
- fi
578
-
579
- # Clean feature name (replace spaces with hyphens, lowercase)
580
- CLEAN_NAME=$(echo "$FEATURE_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr '_' '-')
581
-
582
- # Get next feature number
583
- if [ -d "specs" ]; then
584
- FEATURE_NUM=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | wc -l)
585
- FEATURE_NUM=$((FEATURE_NUM + 1))
586
- else
587
- FEATURE_NUM=1
588
- fi
589
-
590
- # Format with leading zeros
591
- FEATURE_ID=$(printf "%03d" $FEATURE_NUM)
592
- BRANCH_NAME="${FEATURE_ID}-${CLEAN_NAME}"
593
-
594
- # Create directories
595
- mkdir -p "specs/${BRANCH_NAME}"
596
- mkdir -p "plans/${BRANCH_NAME}"
597
- mkdir -p "tasks/${BRANCH_NAME}"
598
-
599
- # Create feature branch if git is available
600
- if command -v git &> /dev/null && [ -d ".git" ]; then
601
- git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
602
- fi
603
-
604
- # Output JSON result
605
- echo "{"
606
- echo " \\"branch_name\\": \\"$BRANCH_NAME\\","
607
- echo " \\"feature_id\\": \\"$FEATURE_ID\\","
608
- echo " \\"spec_dir\\": \\"specs/$BRANCH_NAME\\","
609
- echo " \\"plan_dir\\": \\"plans/$BRANCH_NAME\\","
610
- echo " \\"task_dir\\": \\"tasks/$BRANCH_NAME\\""
611
- echo "}"
612
- """
613
-
614
- def get_spec_script(self) -> str:
615
- """Get pulse-spec script for getting current feature context from file"""
616
- script_path = self.resources_dir / "scripts" / "pulse-spec.sh"
617
- if script_path.exists():
618
- with open(script_path, 'r', encoding='utf-8') as f:
619
- return f.read()
620
- # Fallback to embedded script if file not found
621
- return """#!/bin/bash
622
- # SpecPulse Spec Context Script
623
-
624
- # Check for --current flag
625
- if [ "$1" == "--current" ]; then
626
- # Find the current feature branch
627
- if command -v git &> /dev/null && [ -d ".git" ]; then
628
- BRANCH=$(git branch --show-current)
629
- if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
630
- FEATURE_DIR="specs/$BRANCH"
631
- if [ -d "$FEATURE_DIR" ]; then
632
- echo "{"
633
- echo " \\"branch\\": \\"$BRANCH\\","
634
- echo " \\"spec_file\\": \\"$FEATURE_DIR/spec.md\\","
635
- echo " \\"spec_dir\\": \\"$FEATURE_DIR\\""
636
- echo "}"
637
- exit 0
638
- fi
639
- fi
640
- fi
641
-
642
- # Fallback: find latest spec directory
643
- LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
644
- if [ -n "$LATEST" ]; then
645
- echo "{"
646
- echo " \\"branch\\": \\"$(basename $LATEST)\\","
647
- echo " \\"spec_file\\": \\"$LATEST/spec.md\\","
648
- echo " \\"spec_dir\\": \\"$LATEST\\""
649
- echo "}"
650
- else
651
- echo "{\\"error\\": \\"No active feature found\\"}"
652
- exit 1
653
- fi
654
- fi
655
- """
656
-
657
- def get_plan_script(self) -> str:
658
- """Get pulse-plan script for plan context from file"""
659
- script_path = self.resources_dir / "scripts" / "pulse-plan.sh"
660
- if script_path.exists():
661
- with open(script_path, 'r', encoding='utf-8') as f:
662
- return f.read()
663
- # Fallback to embedded script if file not found
664
- return """#!/bin/bash
665
- # SpecPulse Plan Context Script
666
-
667
- # Check for --current flag
668
- if [ "$1" == "--current" ]; then
669
- # Find the current feature branch
670
- if command -v git &> /dev/null && [ -d ".git" ]; then
671
- BRANCH=$(git branch --show-current)
672
- if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
673
- SPEC_DIR="specs/$BRANCH"
674
- PLAN_DIR="plans/$BRANCH"
675
- if [ -d "$SPEC_DIR" ]; then
676
- echo "{"
677
- echo " \\"branch\\": \\"$BRANCH\\","
678
- echo " \\"spec_file\\": \\"$SPEC_DIR/spec.md\\","
679
- echo " \\"plan_file\\": \\"$PLAN_DIR/plan.md\\","
680
- echo " \\"plan_dir\\": \\"$PLAN_DIR\\""
681
- echo "}"
682
- exit 0
683
- fi
684
- fi
685
- fi
686
-
687
- # Fallback: find latest directories
688
- LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
689
- if [ -n "$LATEST" ]; then
690
- BRANCH=$(basename "$LATEST")
691
- echo "{"
692
- echo " \\"branch\\": \\"$BRANCH\\","
693
- echo " \\"spec_file\\": \\"specs/$BRANCH/spec.md\\","
694
- echo " \\"plan_file\\": \\"plans/$BRANCH/plan.md\\","
695
- echo " \\"plan_dir\\": \\"plans/$BRANCH\\""
696
- echo "}"
697
- else
698
- echo "{\\"error\\": \\"No active feature found\\"}"
699
- exit 1
700
- fi
701
- fi
702
- """
703
-
704
- def get_task_script(self) -> str:
705
- """Get pulse-task script for task context from file"""
706
- script_path = self.resources_dir / "scripts" / "pulse-task.sh"
707
- if script_path.exists():
708
- with open(script_path, 'r', encoding='utf-8') as f:
709
- return f.read()
710
- # Fallback to embedded script if file not found
711
- return """#!/bin/bash
712
- # SpecPulse Task Context Script
713
-
714
- # Check for --current flag
715
- if [ "$1" == "--current" ]; then
716
- # Find the current feature branch
717
- if command -v git &> /dev/null && [ -d ".git" ]; then
718
- BRANCH=$(git branch --show-current)
719
- if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
720
- SPEC_DIR="specs/$BRANCH"
721
- PLAN_DIR="plans/$BRANCH"
722
- TASK_DIR="tasks/$BRANCH"
723
- if [ -d "$SPEC_DIR" ]; then
724
- echo "{"
725
- echo " \\"branch\\": \\"$BRANCH\\","
726
- echo " \\"spec_file\\": \\"$SPEC_DIR/spec.md\\","
727
- echo " \\"plan_file\\": \\"$PLAN_DIR/plan.md\\","
728
- echo " \\"task_file\\": \\"$TASK_DIR/tasks.md\\","
729
- echo " \\"task_dir\\": \\"$TASK_DIR\\""
730
- echo "}"
731
- exit 0
732
- fi
733
- fi
734
- fi
735
-
736
- # Fallback: find latest directories
737
- LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
738
- if [ -n "$LATEST" ]; then
739
- BRANCH=$(basename "$LATEST")
740
- echo "{"
741
- echo " \\"branch\\": \\"$BRANCH\\","
742
- echo " \\"spec_file\\": \\"specs/$BRANCH/spec.md\\","
743
- echo " \\"plan_file\\": \\"plans/$BRANCH/plan.md\\","
744
- echo " \\"task_file\\": \\"tasks/$BRANCH/tasks.md\\","
745
- echo " \\"task_dir\\": \\"tasks/$BRANCH\\""
746
- echo "}"
747
- else
748
- echo "{\\"error\\": \\"No active feature found\\"}"
749
- exit 1
750
- fi
751
- fi
752
- """
753
-
754
- def get_validate_script(self) -> str:
755
- """Get validation script"""
756
- return """#!/bin/bash
757
- # SpecPulse Validation Script
758
-
759
- validate_spec() {
760
- local spec_file=$1
761
- local errors=0
762
-
763
- echo "Validating: $spec_file"
764
-
765
- # Check required sections
766
- if ! grep -q "## Requirements" $spec_file; then
767
- echo " ❌ Missing Requirements section"
768
- ((errors++))
769
- fi
770
-
771
- if ! grep -q "## User Stories" $spec_file; then
772
- echo " Missing User Stories section"
773
- ((errors++))
774
- fi
775
-
776
- if ! grep -q "## Acceptance Criteria" $spec_file; then
777
- echo " Missing Acceptance Criteria section"
778
- ((errors++))
779
- fi
780
-
781
- # Check for clarification markers
782
- if grep -q "\\[NEEDS CLARIFICATION\\]" $spec_file; then
783
- echo " ⚠️ Contains items needing clarification"
784
- fi
785
-
786
- if [ $errors -eq 0 ]; then
787
- echo " ✅ Specification valid"
788
- return 0
789
- else
790
- echo " Specification has $errors errors"
791
- return 1
792
- fi
793
- }
794
-
795
- # Main
796
- if [ "$1" == "spec" ]; then
797
- validate_spec $2
798
- elif [ "$1" == "all" ]; then
799
- for spec in specs/*/spec.md; do
800
- validate_spec $spec
801
- done
802
- fi
803
- """
804
-
805
- def get_generate_script(self) -> str:
806
- """Get generation script"""
807
- return """#!/bin/bash
808
- # SpecPulse Generation Script
809
-
810
- generate_from_template() {
811
- local template=$1
812
- local output=$2
813
- local feature_name=$3
814
-
815
- # Replace placeholders
816
- sed "s/\\[FEATURE_NAME\\]/$feature_name/g" $template > $output
817
- sed -i "s/\\[DATE\\]/$(date +%Y-%m-%d)/g" $output
818
- sed -i "s/\\[XXX\\]/$(printf '%03d' $RANDOM)/g" $output
819
-
820
- echo "Generated: $output"
821
- }
822
-
823
- # Main
824
- if [ "$1" == "spec" ]; then
825
- generate_from_template templates/spec.md $2 $3
826
- elif [ "$1" == "plan" ]; then
827
- generate_from_template templates/plan.md $2 $3
828
- elif [ "$1" == "task" ]; then
829
- generate_from_template templates/task.md $2 $3
830
- fi
831
- """
832
-
833
- def get_claude_instructions(self) -> str:
834
- """Get Claude instructions"""
835
- return """# SpecPulse Commands for Claude
836
-
837
- You have access to SpecPulse commands for specification-driven development.
838
-
839
- ## Available Commands
840
-
841
- ### /pulse init <feature-name>
842
- Initializes a new feature with proper structure.
843
- - Creates feature branch
844
- - Sets up specification directory
845
- - Loads templates
846
- - Updates context
847
-
848
- ### /spec create <description>
849
- Creates a detailed specification from description.
850
- - Use the template in templates/spec.md
851
- - Mark uncertainties with [NEEDS CLARIFICATION]
852
- - Ensure all sections are complete
853
- - Validate against constitution
854
-
855
- ### /plan generate
856
- Generates implementation plan from current specification.
857
- - Read the active specification
858
- - Create detailed phases
859
- - Include technology decisions
860
- - Add time estimates
861
-
862
- ### /task breakdown
863
- Creates task list from implementation plan.
864
- - Identify dependencies
865
- - Mark parallel tasks with [P]
866
- - Add time estimates
867
- - Create critical path
868
-
869
- ### /validate <component>
870
- Validates specifications, plans, or project.
871
- - Check completeness
872
- - Verify consistency
873
- - Ensure constitution compliance
874
-
875
- ## Workflow
876
-
877
- 1. User requests feature Use `/pulse init`
878
- 2. User describes requirements → Use `/spec create`
879
- 3. Specification complete Use `/plan generate`
880
- 4. Plan approved → Use `/task breakdown`
881
- 5. Before implementation → Use `/validate all`
882
-
883
- ## Constitution Rules
884
-
885
- Always enforce these principles:
886
- 1. Simplicity first
887
- 2. Test-driven development
888
- 3. Single responsibility
889
- 4. Documentation as code
890
- 5. Security by design
891
-
892
- ## Context Management
893
-
894
- - Read `memory/context.md` for project state
895
- - Update context after major decisions
896
- - Check `memory/constitution.md` for principles
897
- - Reference previous specs for consistency
898
-
899
- ## Templates
900
-
901
- Always use templates from `templates/` directory:
902
- - `spec.md` for specifications
903
- - `plan.md` for implementation plans
904
- - `task.md` for task lists
905
-
906
- ## Best Practices
907
-
908
- 1. Always validate before moving to next phase
909
- 2. Keep specifications testable and measurable
910
- 3. Update context.md with decisions
911
- 4. Create atomic, focused commits
912
- 5. Document rationale for technology choices
913
- """
914
-
915
- # Claude command getters
916
- def get_claude_pulse_command(self) -> str:
917
- """Get Claude pulse command"""
918
- command_path = self.resources_dir / "commands" / "claude" / "pulse.md"
919
- if command_path.exists():
920
- with open(command_path, 'r', encoding='utf-8') as f:
921
- return f.read()
922
- return "# /pulse command not found"
923
-
924
- def get_claude_spec_command(self) -> str:
925
- """Get Claude spec command"""
926
- command_path = self.resources_dir / "commands" / "claude" / "spec.md"
927
- if command_path.exists():
928
- with open(command_path, 'r', encoding='utf-8') as f:
929
- return f.read()
930
- return "# /spec command not found"
931
-
932
- def get_claude_plan_command(self) -> str:
933
- """Get Claude plan command"""
934
- command_path = self.resources_dir / "commands" / "claude" / "plan.md"
935
- if command_path.exists():
936
- with open(command_path, 'r', encoding='utf-8') as f:
937
- return f.read()
938
- return "# /plan command not found"
939
-
940
- def get_claude_task_command(self) -> str:
941
- """Get Claude task command"""
942
- command_path = self.resources_dir / "commands" / "claude" / "task.md"
943
- if command_path.exists():
944
- with open(command_path, 'r', encoding='utf-8') as f:
945
- return f.read()
946
- return "# /task command not found"
947
-
948
- # Gemini command getters
949
- def get_gemini_pulse_command(self) -> str:
950
- """Get Gemini pulse command"""
951
- command_path = self.resources_dir / "commands" / "gemini" / "pulse.toml"
952
- if command_path.exists():
953
- with open(command_path, 'r', encoding='utf-8') as f:
954
- return f.read()
955
- return "# Gemini pulse command not found"
956
-
957
- def get_gemini_spec_command(self) -> str:
958
- """Get Gemini spec command"""
959
- command_path = self.resources_dir / "commands" / "gemini" / "spec.toml"
960
- if command_path.exists():
961
- with open(command_path, 'r', encoding='utf-8') as f:
962
- return f.read()
963
- return "# Gemini spec command not found"
964
-
965
- def get_gemini_plan_command(self) -> str:
966
- """Get Gemini plan command"""
967
- command_path = self.resources_dir / "commands" / "gemini" / "plan.toml"
968
- if command_path.exists():
969
- with open(command_path, 'r', encoding='utf-8') as f:
970
- return f.read()
971
- return "# Gemini plan command not found"
972
-
973
- def get_gemini_task_command(self) -> str:
974
- """Get Gemini task command"""
975
- command_path = self.resources_dir / "commands" / "gemini" / "task.toml"
976
- if command_path.exists():
977
- with open(command_path, 'r', encoding='utf-8') as f:
978
- return f.read()
979
- return "# Gemini task command not found"
980
-
981
- def get_gemini_instructions(self) -> str:
982
- """Get Gemini instructions"""
983
- return """# SpecPulse Commands for Gemini CLI
984
-
985
- This project uses SpecPulse for specification-driven development.
986
-
987
- ## Command Reference
988
-
989
- ### Initialization
990
- ```
991
- /pulse init <feature-name>
992
- ```
993
- Creates new feature structure and branch.
994
-
995
- ### Specification Creation
996
- ```
997
- /spec create <description>
998
- ```
999
- Generates detailed specification from natural language.
1000
-
1001
- Required sections:
1002
- - Requirements (functional and non-functional)
1003
- - User stories with acceptance criteria
1004
- - Technical constraints
1005
- - Dependencies
1006
- - Risks and mitigations
1007
-
1008
- ### Plan Generation
1009
- ```
1010
- /plan generate [--optimize <focus>]
1011
- ```
1012
- Creates implementation plan from specification.
1013
-
1014
- Optimization options:
1015
- - performance: Speed and efficiency focus
1016
- - security: Security-first approach
1017
- - simplicity: Maintainable solution
1018
- - cost: Resource optimization
1019
-
1020
- ### Task Breakdown
1021
- ```
1022
- /task breakdown [--parallel]
1023
- ```
1024
- Generates actionable task list.
1025
-
1026
- Features:
1027
- - Dependency detection
1028
- - Parallel task identification
1029
- - Time estimation
1030
- - Critical path analysis
1031
-
1032
- ### Validation
1033
- ```
1034
- /validate [all|spec|plan|constitution]
1035
- ```
1036
- Validates project components.
1037
-
1038
- ## Templates Location
1039
-
1040
- Use templates from `templates/` directory:
1041
- - Specification: templates/spec.md
1042
- - Implementation: templates/plan.md
1043
- - Tasks: templates/task.md
1044
-
1045
- ## Memory System
1046
-
1047
- Project memory in `memory/` directory:
1048
- - constitution.md: Immutable principles
1049
- - context.md: Current project state
1050
- - decisions.md: Architectural decisions
1051
-
1052
- ## Workflow Process
1053
-
1054
- 1. **Initialize Feature**
1055
- - Run: `/pulse init feature-name`
1056
- - Creates branch and structure
1057
-
1058
- 2. **Create Specification**
1059
- - Run: `/spec create "description"`
1060
- - Fill template completely
1061
- - Mark unclear items: [NEEDS CLARIFICATION]
1062
-
1063
- 3. **Generate Plan**
1064
- - Run: `/plan generate`
1065
- - Choose optimization focus
1066
- - Review technology choices
1067
-
1068
- 4. **Create Tasks**
1069
- - Run: `/task breakdown`
1070
- - Review dependencies
1071
- - Check time estimates
1072
-
1073
- 5. **Validate**
1074
- - Run: `/validate all`
1075
- - Fix any issues
1076
- - Proceed to implementation
1077
-
1078
- ## Constitution Principles
1079
-
1080
- Enforce these rules:
1081
- 1. Start simple, add complexity only when needed
1082
- 2. Write tests before code
1083
- 3. One responsibility per component
1084
- 4. Document everything
1085
- 5. Consider security from start
1086
-
1087
- ## Project Structure
1088
-
1089
- ```
1090
- project/
1091
- ├── specs/ # Specifications
1092
- ├── plans/ # Implementation plans
1093
- ├── tasks/ # Task lists
1094
- ├── memory/ # Project memory
1095
- ├── scripts/ # Automation
1096
- └── templates/ # Templates
1097
- ```
1098
-
1099
- ## Important Notes
1100
-
1101
- - Always update context.md after decisions
1102
- - Validate specifications before planning
1103
- - Use [P] marker for parallel tasks
1104
- - Keep commits atomic and focused
1105
- - Reference constitution for all decisions
1
+ """
2
+ SpecPulse Core Implementation
3
+ """
4
+
5
+ from pathlib import Path
6
+ from datetime import datetime
7
+ from typing import Dict, List, Optional
8
+ import yaml
9
+ import json
10
+ import os
11
+
12
+
13
+
14
+ class SpecPulse:
15
+ """Core SpecPulse functionality"""
16
+
17
+ def __init__(self, project_path: Optional[Path] = None):
18
+ self.project_path = project_path or Path.cwd()
19
+ self.config = self._load_config()
20
+ # Get resource directory path using package data
21
+ try:
22
+ # Use modern importlib.resources (Python 3.9+)
23
+ from importlib import resources
24
+ self.resources_dir = Path(resources.files('specpulse').joinpath('resources'))
25
+ except:
26
+ try:
27
+ # Fallback to pkg_resources for older Python versions
28
+ import pkg_resources
29
+ self.resources_dir = Path(pkg_resources.resource_filename('specpulse', 'resources'))
30
+ except:
31
+ # Final fallback to development path
32
+ self.resources_dir = Path(__file__).parent.parent / "resources"
33
+
34
+ def _load_config(self) -> Dict:
35
+ """Load project configuration"""
36
+ config_path = self.project_path / ".specpulse" / "config.yaml"
37
+ if config_path.exists():
38
+ with open(config_path, 'r') as f:
39
+ return yaml.safe_load(f)
40
+ return {}
41
+
42
+ def get_spec_template(self) -> str:
43
+ """Get specification template from file"""
44
+ template_path = self.resources_dir / "templates" / "spec-001.md"
45
+ if template_path.exists():
46
+ with open(template_path, 'r', encoding='utf-8') as f:
47
+ return f.read()
48
+ # Fallback to embedded template if file not found
49
+ return """<!-- SpecPulse Specification Template v1.0 -->
50
+ <!-- AI Instructions: Fill this template based on user description -->
51
+
52
+ # Specification: [FEATURE_NAME]
53
+
54
+ ## Metadata
55
+ - **ID**: SPEC-[XXX]
56
+ - **Created**: [DATE]
57
+ - **Author**: [USER]
58
+ - **AI Assistant**: [CLAUDE|GEMINI]
59
+ - **Version**: 1.0.0
60
+
61
+ ## Executive Summary
62
+ [One paragraph description of what this feature does and why it's needed]
63
+
64
+ ## Problem Statement
65
+ [Detailed description of the problem being solved]
66
+
67
+ ## Proposed Solution
68
+ [High-level approach to solving the problem]
69
+
70
+ ## Detailed Requirements
71
+
72
+ ### Functional Requirements
73
+ <!-- AI: Generate numbered list of specific, testable requirements -->
74
+
75
+ FR-001: [Requirement]
76
+ - Acceptance: [How to verify this requirement is met]
77
+ - Priority: [MUST|SHOULD|COULD]
78
+
79
+ ### Non-Functional Requirements
80
+
81
+ #### Performance
82
+ - Response Time: [Target]
83
+ - Throughput: [Target]
84
+ - Resource Usage: [Limits]
85
+
86
+ #### Security
87
+ - Authentication: [Method]
88
+ - Authorization: [Model]
89
+ - Data Protection: [Requirements]
90
+
91
+ #### Scalability
92
+ - User Load: [Target]
93
+ - Data Volume: [Target]
94
+ - Geographic Distribution: [Requirements]
95
+
96
+ ## User Stories
97
+
98
+ <!-- AI: Generate user stories in standard format -->
99
+
100
+ ### Story 1: [Title]
101
+ **As a** [user type]
102
+ **I want** [action/feature]
103
+ **So that** [benefit/value]
104
+
105
+ **Acceptance Criteria:**
106
+ - [ ] [Criterion 1]
107
+ - [ ] [Criterion 2]
108
+ - [ ] [Criterion 3]
109
+
110
+ ## Technical Constraints
111
+ <!-- List any technical limitations or requirements -->
112
+
113
+ ## Dependencies
114
+ <!-- External services, libraries, or other features required -->
115
+
116
+ ## Risks and Mitigations
117
+ <!-- Identify potential risks and how to address them -->
118
+
119
+ ## Open Questions
120
+ <!-- Mark with [NEEDS CLARIFICATION] for items requiring user input -->
121
+
122
+ ## Appendix
123
+ <!-- Additional diagrams, mockups, or references -->
124
+ """
125
+
126
+ def get_plan_template(self) -> str:
127
+ """Get implementation plan template from file"""
128
+ template_path = self.resources_dir / "templates" / "plan-001.md"
129
+ if template_path.exists():
130
+ with open(template_path, 'r', encoding='utf-8') as f:
131
+ return f.read()
132
+ # Fallback to embedded template if file not found
133
+ return """<!-- SpecPulse Implementation Plan Template v1.0 -->
134
+ <!-- AI Instructions: Generate plan from specification -->
135
+
136
+ # Implementation Plan: [FEATURE_NAME]
137
+
138
+ ## Specification Reference
139
+ - **Spec ID**: SPEC-[XXX]
140
+ - **Generated**: [DATE]
141
+ - **Optimization Focus**: [PERFORMANCE|SECURITY|SIMPLICITY|COST]
142
+
143
+ ## Architecture Overview
144
+ ```mermaid
145
+ <!-- AI: Generate architecture diagram -->
146
+ ```
147
+
148
+ ## Technology Stack
149
+
150
+ ### Core Technologies
151
+ - **Language**: [Choice with rationale]
152
+ - **Framework**: [Choice with rationale]
153
+ - **Database**: [Choice with rationale]
154
+ - **Cache**: [Choice with rationale]
155
+
156
+ ### Supporting Tools
157
+ - **Testing**: [Framework choice]
158
+ - **CI/CD**: [Platform choice]
159
+ - **Monitoring**: [Solution choice]
160
+
161
+ ## Implementation Phases
162
+
163
+ ### Phase 0: Setup and Prerequisites
164
+ **Duration**: [Estimate]
165
+ **Tasks**:
166
+ 1. Environment setup
167
+ 2. Repository initialization
168
+ 3. Dependency installation
169
+ 4. Configuration
170
+
171
+ ### Phase 1: Data Layer
172
+ **Duration**: [Estimate]
173
+ **Deliverables**:
174
+ - Database schema
175
+ - Migration scripts
176
+ - Data models
177
+ - Repository pattern implementation
178
+
179
+ **Tasks**:
180
+ 1. Design database schema
181
+ 2. Create migration scripts
182
+ 3. Implement data models
183
+ 4. Create repository interfaces
184
+ 5. Write data layer tests
185
+
186
+ ### Phase 2: Business Logic
187
+ **Duration**: [Estimate]
188
+ **Deliverables**:
189
+ - Service layer
190
+ - Business rules implementation
191
+ - Validation logic
192
+
193
+ **Tasks**:
194
+ 1. Implement service interfaces
195
+ 2. Create business logic modules
196
+ 3. Add validation rules
197
+ 4. Implement error handling
198
+ 5. Write unit tests
199
+
200
+ ### Phase 3: API Layer
201
+ **Duration**: [Estimate]
202
+ **Deliverables**:
203
+ - REST/GraphQL endpoints
204
+ - API documentation
205
+ - Authentication/Authorization
206
+
207
+ **Tasks**:
208
+ 1. Design API contracts
209
+ 2. Implement endpoints
210
+ 3. Add authentication
211
+ 4. Create API documentation
212
+ 5. Write integration tests
213
+
214
+ ### Phase 4: Testing and Optimization
215
+ **Duration**: [Estimate]
216
+ **Deliverables**:
217
+ - Complete test suite
218
+ - Performance optimization
219
+ - Security hardening
220
+
221
+ **Tasks**:
222
+ 1. Complete test coverage
223
+ 2. Performance testing
224
+ 3. Security audit
225
+ 4. Load testing
226
+ 5. Documentation
227
+
228
+ ## File Structure
229
+ ```
230
+ [feature-name]/
231
+ ├── src/
232
+ │ ├── models/
233
+ │ ├── services/
234
+ ├── controllers/
235
+ │ └── utils/
236
+ ├── tests/
237
+ │ ├── unit/
238
+ │ ├── integration/
239
+ │ └── e2e/
240
+ ├── docs/
241
+ └── config/
242
+ ```
243
+
244
+ ## API Contracts
245
+
246
+ ### Endpoint: [ENDPOINT_NAME]
247
+ ```yaml
248
+ method: POST
249
+ path: /api/v1/[resource]
250
+ request:
251
+ headers:
252
+ Content-Type: application/json
253
+ Authorization: Bearer {token}
254
+ body:
255
+ field1: string
256
+ field2: number
257
+ response:
258
+ 200:
259
+ success: true
260
+ data: object
261
+ 400:
262
+ error: string
263
+ ```
264
+
265
+ ## Data Models
266
+
267
+ ### Entity: [ENTITY_NAME]
268
+ ```yaml
269
+ fields:
270
+ id: uuid
271
+ created_at: timestamp
272
+ updated_at: timestamp
273
+ [field_name]: [type]
274
+ relations:
275
+ [relation_name]: [type]
276
+ indexes:
277
+ - [field_name]
278
+ ```
279
+
280
+ ## Testing Strategy
281
+
282
+ ### Unit Tests
283
+ - Coverage Target: 80%
284
+ - Framework: [Choice]
285
+ - Mock Strategy: [Approach]
286
+
287
+ ### Integration Tests
288
+ - API Contract Tests
289
+ - Database Integration Tests
290
+ - External Service Tests
291
+
292
+ ### E2E Tests
293
+ - Critical User Journeys
294
+ - Performance Benchmarks
295
+ - Security Scenarios
296
+
297
+ ## Constitution Compliance
298
+
299
+ ### Principle Validation
300
+ - [ ] Single Responsibility: Each component has one purpose
301
+ - [ ] Test-First: Tests written before implementation
302
+ - [ ] Documentation: All code is documented
303
+ - [ ] Security: Security considered by design
304
+ - [ ] Performance: Meets performance targets
305
+
306
+ ## Risk Assessment
307
+
308
+ ### Technical Risks
309
+ | Risk | Probability | Impact | Mitigation |
310
+ |------|------------|--------|------------|
311
+ | [Risk] | [H/M/L] | [H/M/L] | [Strategy] |
312
+
313
+ ### Timeline Risks
314
+ | Risk | Probability | Impact | Mitigation |
315
+ |------|------------|--------|------------|
316
+ | [Risk] | [H/M/L] | [H/M/L] | [Strategy] |
317
+
318
+ ## Success Criteria
319
+ - [ ] All functional requirements implemented
320
+ - [ ] Test coverage > 80%
321
+ - [ ] Performance targets met
322
+ - [ ] Security audit passed
323
+ - [ ] Documentation complete
324
+ """
325
+
326
+ def get_task_template(self) -> str:
327
+ """Get task list template from file"""
328
+ template_path = self.resources_dir / "templates" / "task.md"
329
+ if template_path.exists():
330
+ with open(template_path, 'r', encoding='utf-8') as f:
331
+ return f.read()
332
+ # Fallback to embedded template if file not found
333
+ return """<!-- SpecPulse Task List Template v1.0 -->
334
+ <!-- AI Instructions: Generate from implementation plan -->
335
+
336
+ # Task List: [FEATURE_NAME]
337
+
338
+ ## Metadata
339
+ - **Plan Reference**: [PLAN_ID]
340
+ - **Total Tasks**: [COUNT]
341
+ - **Estimated Duration**: [TOTAL_HOURS]
342
+ - **Parallel Groups**: [COUNT]
343
+
344
+ ## Task Organization
345
+
346
+ ### 🔄 Parallel Group A
347
+ *These tasks can be executed simultaneously*
348
+
349
+ #### TASK-001: [Task Name]
350
+ - **Type**: [setup|development|testing|documentation]
351
+ - **Priority**: [HIGH|MEDIUM|LOW]
352
+ - **Estimate**: [hours]
353
+ - **Dependencies**: None
354
+ - **Description**: [What needs to be done]
355
+ - **Acceptance**: [How to verify completion]
356
+ - **Assignable**: [role/skill required]
357
+
358
+ #### TASK-002: [Task Name]
359
+ [Same structure as above]
360
+
361
+ ### 📝 Sequential Tasks
362
+ *These tasks must be completed in order*
363
+
364
+ #### TASK-003: [Task Name]
365
+ - **Dependencies**: TASK-001
366
+ [Rest of structure]
367
+
368
+ ### 🎯 Critical Path
369
+ *Tasks that directly impact timeline*
370
+
371
+ 1. TASK-001 → TASK-003 → TASK-007
372
+ 2. Estimated critical path duration: [hours]
373
+
374
+ ## Task Details
375
+
376
+ ### Development Tasks
377
+ - [ ] TASK-XXX: Implement [component]
378
+ - [ ] TASK-XXX: Create [feature]
379
+ - [ ] TASK-XXX: Integrate [service]
380
+
381
+ ### Testing Tasks
382
+ - [ ] TASK-XXX: Write unit tests for [component]
383
+ - [ ] TASK-XXX: Create integration tests
384
+ - [ ] TASK-XXX: Perform security testing
385
+
386
+ ### Documentation Tasks
387
+ - [ ] TASK-XXX: Document API endpoints
388
+ - [ ] TASK-XXX: Create user guide
389
+ - [ ] TASK-XXX: Update README
390
+
391
+ ## Execution Schedule
392
+
393
+ ### Day 1-2
394
+ - Morning: TASK-001, TASK-002 (parallel)
395
+ - Afternoon: TASK-003
396
+
397
+ ### Day 3-4
398
+ - Morning: TASK-004
399
+ - Afternoon: TASK-005, TASK-006
400
+
401
+ ## Progress Tracking
402
+ ```yaml
403
+ status:
404
+ total: [count]
405
+ completed: 0
406
+ in_progress: 0
407
+ blocked: 0
408
+
409
+ metrics:
410
+ velocity: [tasks/day]
411
+ estimated_completion: [date]
412
+ blockers: []
413
+ ```
414
+ """
415
+
416
+ def get_constitution_template(self) -> str:
417
+ """Get constitution template from file"""
418
+ template_path = self.resources_dir / "memory" / "constitution.md"
419
+ if template_path.exists():
420
+ with open(template_path, 'r', encoding='utf-8') as f:
421
+ return f.read()
422
+ # Fallback to embedded template if file not found
423
+ return """# Project Constitution
424
+
425
+ ## Immutable Principles
426
+
427
+ ### Principle 1: Simplicity First
428
+ Every solution must start with the simplest approach that could work.
429
+ Complexity is added only when proven necessary.
430
+
431
+ ### Principle 2: Test-Driven Development
432
+ No production code without tests.
433
+ Tests are written first, implementation follows.
434
+
435
+ ### Principle 3: Single Responsibility
436
+ Each module, function, and component does one thing well.
437
+ If you need "and" to describe it, split it.
438
+
439
+ ### Principle 4: Documentation as Code
440
+ Documentation lives with code.
441
+ If it's not documented, it doesn't exist.
442
+
443
+ ### Principle 5: Security by Design
444
+ Security is not an afterthought.
445
+ Every feature considers security implications from the start.
446
+
447
+ ## Technical Standards
448
+
449
+ ### Code Style
450
+ - Python: PEP 8 with type hints
451
+ - JavaScript: StandardJS
452
+ - Go: Official Go formatting
453
+
454
+ ### Testing Requirements
455
+ - Minimum 80% code coverage
456
+ - All API endpoints must have contract tests
457
+ - Critical paths require E2E tests
458
+
459
+ ### Performance Targets
460
+ - API response time: < 200ms (p95)
461
+ - Page load time: < 2 seconds
462
+ - Database queries: < 50ms
463
+
464
+ ### Security Requirements
465
+ - All data encrypted in transit (TLS 1.3+)
466
+ - Sensitive data encrypted at rest
467
+ - Authentication: OAuth 2.0 / JWT
468
+ - Authorization: RBAC with least privilege
469
+
470
+ ## Architecture Rules
471
+
472
+ ### Service Boundaries
473
+ - Services communicate only through defined APIs
474
+ - No shared databases between services
475
+ - Each service owns its data
476
+
477
+ ### Data Management
478
+ - Single source of truth for each data type
479
+ - Event sourcing for audit requirements
480
+ - CQRS where read/write patterns differ
481
+
482
+ ### Error Handling
483
+ - All errors are handled explicitly
484
+ - User-facing errors are helpful and actionable
485
+ - System errors are logged with context
486
+
487
+ ## Amendment Process
488
+
489
+ Changes to this constitution require:
490
+ 1. Documented rationale
491
+ 2. Team consensus
492
+ 3. Gradual migration plan
493
+ 4. Update to all affected documentation
494
+ """
495
+
496
+ def get_context_template(self) -> str:
497
+ """Get context template from file"""
498
+ template_path = self.resources_dir / "memory" / "context.md"
499
+ if template_path.exists():
500
+ with open(template_path, 'r', encoding='utf-8') as f:
501
+ return f.read()
502
+ # Fallback to embedded template if file not found
503
+ return """# Project Context
504
+
505
+ ## Current State
506
+ Last Updated: [AI updates this automatically]
507
+
508
+ ### Active Features
509
+ 1. **[feature-name]** (SPEC-XXX)
510
+ - Status: [Phase]
511
+ - Branch: [branch-name]
512
+ - Blockers: [None|List]
513
+
514
+ ### Recent Decisions
515
+ - [Decision with rationale]
516
+
517
+ ### Known Issues
518
+ - [Issue description]
519
+
520
+ ## Team Preferences
521
+
522
+ ### Technology Choices
523
+ - **Preferred Stack**: [Stack]
524
+ - **Testing**: [Framework]
525
+ - **CI/CD**: [Platform]
526
+ - **Deployment**: [Method]
527
+
528
+ ### Coding Patterns
529
+ - [Pattern preference]
530
+
531
+ ## Project Glossary
532
+
533
+ ### Domain Terms
534
+ - **[Term]**: [Definition]
535
+
536
+ ### Technical Terms
537
+ - **[Term]**: [Definition]
538
+ """
539
+
540
+ def get_decomposition_template(self, template_type: str = "microservices") -> str:
541
+ """Get decomposition template"""
542
+ template_map = {
543
+ "microservices": "microservices.md",
544
+ "api": "api-contract.yaml",
545
+ "interface": "interface.ts"
546
+ }
547
+
548
+ template_file = template_map.get(template_type, "microservices.md")
549
+ template_path = self.resources_dir / "templates" / "decomposition" / template_file
550
+
551
+ if template_path.exists():
552
+ with open(template_path, 'r', encoding='utf-8') as f:
553
+ return f.read()
554
+
555
+ # Fallback for microservices template
556
+ if template_type == "microservices":
557
+ return """# Microservice Decomposition: {{ feature_name }}
558
+
559
+ ## Service Boundaries
560
+ {{ services }}
561
+
562
+ ## Communication Patterns
563
+ {{ communication }}
564
+
565
+ ## Data Ownership
566
+ {{ data_boundaries }}
567
+ """
568
+ return ""
569
+
570
+ def get_decisions_template(self) -> str:
571
+ """Get architectural decisions template from file"""
572
+ template_path = self.resources_dir / "memory" / "decisions.md"
573
+ if template_path.exists():
574
+ with open(template_path, 'r', encoding='utf-8') as f:
575
+ return f.read()
576
+ # Fallback to embedded template if file not found
577
+ return """# Architectural Decisions
578
+
579
+ ## Decision Log
580
+
581
+ ### ADR-001: [Title]
582
+ **Date**: [DATE]
583
+ **Status**: [PROPOSED|ACCEPTED|DEPRECATED]
584
+ **Context**: [Why this decision was needed]
585
+ **Decision**: [What was decided]
586
+ **Consequences**: [What happens as a result]
587
+ **Alternatives Considered**: [Other options that were evaluated]
588
+
589
+ ---
590
+
591
+ ### ADR-002: [Title]
592
+ [Same structure as above]
593
+ """
594
+
595
+ def get_setup_script(self) -> str:
596
+ """Get pulse-init script for feature initialization from file"""
597
+ script_path = self.resources_dir / "scripts" / "pulse-init.sh"
598
+ if script_path.exists():
599
+ with open(script_path, 'r', encoding='utf-8') as f:
600
+ return f.read()
601
+ # Fallback to embedded script if file not found
602
+ return """#!/bin/bash
603
+ # SpecPulse Feature Initialization Script
604
+
605
+ set -e
606
+
607
+ # Get feature name from argument
608
+ FEATURE_NAME="$1"
609
+ if [ -z "$FEATURE_NAME" ]; then
610
+ echo "Error: Feature name required"
611
+ exit 1
612
+ fi
613
+
614
+ # Clean feature name (replace spaces with hyphens, lowercase)
615
+ CLEAN_NAME=$(echo "$FEATURE_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr '_' '-')
616
+
617
+ # Get next feature number
618
+ if [ -d "specs" ]; then
619
+ FEATURE_NUM=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | wc -l)
620
+ FEATURE_NUM=$((FEATURE_NUM + 1))
621
+ else
622
+ FEATURE_NUM=1
623
+ fi
624
+
625
+ # Format with leading zeros
626
+ FEATURE_ID=$(printf "%03d" $FEATURE_NUM)
627
+ BRANCH_NAME="${FEATURE_ID}-${CLEAN_NAME}"
628
+
629
+ # Create directories
630
+ mkdir -p "specs/${BRANCH_NAME}"
631
+ mkdir -p "plans/${BRANCH_NAME}"
632
+ mkdir -p "tasks/${BRANCH_NAME}"
633
+
634
+ # Create feature branch if git is available
635
+ if command -v git &> /dev/null && [ -d ".git" ]; then
636
+ git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
637
+ fi
638
+
639
+ # Output JSON result
640
+ echo "{"
641
+ echo " \\"branch_name\\": \\"$BRANCH_NAME\\","
642
+ echo " \\"feature_id\\": \\"$FEATURE_ID\\","
643
+ echo " \\"spec_dir\\": \\"specs/$BRANCH_NAME\\","
644
+ echo " \\"plan_dir\\": \\"plans/$BRANCH_NAME\\","
645
+ echo " \\"task_dir\\": \\"tasks/$BRANCH_NAME\\""
646
+ echo "}"
647
+ """
648
+
649
+ def get_spec_script(self) -> str:
650
+ """Get pulse-spec script for getting current feature context from file"""
651
+ script_path = self.resources_dir / "scripts" / "pulse-spec.sh"
652
+ if script_path.exists():
653
+ with open(script_path, 'r', encoding='utf-8') as f:
654
+ return f.read()
655
+ # Fallback to embedded script if file not found
656
+ return """#!/bin/bash
657
+ # SpecPulse Spec Context Script
658
+
659
+ # Check for --current flag
660
+ if [ "$1" == "--current" ]; then
661
+ # Find the current feature branch
662
+ if command -v git &> /dev/null && [ -d ".git" ]; then
663
+ BRANCH=$(git branch --show-current)
664
+ if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
665
+ FEATURE_DIR="specs/$BRANCH"
666
+ if [ -d "$FEATURE_DIR" ]; then
667
+ echo "{"
668
+ echo " \\"branch\\": \\"$BRANCH\\","
669
+ echo " \\"spec_file\\": \\"$FEATURE_DIR/spec-001.md\\","
670
+ echo " \\"spec_dir\\": \\"$FEATURE_DIR\\""
671
+ echo "}"
672
+ exit 0
673
+ fi
674
+ fi
675
+ fi
676
+
677
+ # Fallback: find latest spec directory
678
+ LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
679
+ if [ -n "$LATEST" ]; then
680
+ echo "{"
681
+ echo " \\"branch\\": \\"$(basename $LATEST)\\","
682
+ echo " \\"spec_file\\": \\"$LATEST/spec-001.md\\","
683
+ echo " \\"spec_dir\\": \\"$LATEST\\""
684
+ echo "}"
685
+ else
686
+ echo "{\\"error\\": \\"No active feature found\\"}"
687
+ exit 1
688
+ fi
689
+ fi
690
+ """
691
+
692
+ def get_plan_script(self) -> str:
693
+ """Get pulse-plan script for plan context from file"""
694
+ script_path = self.resources_dir / "scripts" / "pulse-plan.sh"
695
+ if script_path.exists():
696
+ with open(script_path, 'r', encoding='utf-8') as f:
697
+ return f.read()
698
+ # Fallback to embedded script if file not found
699
+ return """#!/bin/bash
700
+ # SpecPulse Plan Context Script
701
+
702
+ # Check for --current flag
703
+ if [ "$1" == "--current" ]; then
704
+ # Find the current feature branch
705
+ if command -v git &> /dev/null && [ -d ".git" ]; then
706
+ BRANCH=$(git branch --show-current)
707
+ if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
708
+ SPEC_DIR="specs/$BRANCH"
709
+ PLAN_DIR="plans/$BRANCH"
710
+ if [ -d "$SPEC_DIR" ]; then
711
+ echo "{"
712
+ echo " \\"branch\\": \\"$BRANCH\\","
713
+ echo " \\"spec_file\\": \\"$SPEC_DIR/spec-001.md\\","
714
+ echo " \\"plan_file\\": \\"$PLAN_DIR/plan-001.md\\","
715
+ echo " \\"plan_dir\\": \\"$PLAN_DIR\\""
716
+ echo "}"
717
+ exit 0
718
+ fi
719
+ fi
720
+ fi
721
+
722
+ # Fallback: find latest directories
723
+ LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
724
+ if [ -n "$LATEST" ]; then
725
+ BRANCH=$(basename "$LATEST")
726
+ echo "{"
727
+ echo " \\"branch\\": \\"$BRANCH\\","
728
+ echo " \\"spec_file\\": \\"specs/$BRANCH/spec-001.md\\","
729
+ echo " \\"plan_file\\": \\"plans/$BRANCH/plan-001.md\\","
730
+ echo " \\"plan_dir\\": \\"plans/$BRANCH\\""
731
+ echo "}"
732
+ else
733
+ echo "{\\"error\\": \\"No active feature found\\"}"
734
+ exit 1
735
+ fi
736
+ fi
737
+ """
738
+
739
+ def get_task_script(self) -> str:
740
+ """Get pulse-task script for task context from file"""
741
+ script_path = self.resources_dir / "scripts" / "pulse-task.sh"
742
+ if script_path.exists():
743
+ with open(script_path, 'r', encoding='utf-8') as f:
744
+ return f.read()
745
+ # Fallback to embedded script if file not found
746
+ return """#!/bin/bash
747
+ # SpecPulse Task Context Script
748
+
749
+ # Check for --current flag
750
+ if [ "$1" == "--current" ]; then
751
+ # Find the current feature branch
752
+ if command -v git &> /dev/null && [ -d ".git" ]; then
753
+ BRANCH=$(git branch --show-current)
754
+ if [[ "$BRANCH" =~ ^[0-9]{3}-.* ]]; then
755
+ SPEC_DIR="specs/$BRANCH"
756
+ PLAN_DIR="plans/$BRANCH"
757
+ TASK_DIR="tasks/$BRANCH"
758
+ if [ -d "$SPEC_DIR" ]; then
759
+ echo "{"
760
+ echo " \\"branch\\": \\"$BRANCH\\","
761
+ echo " \\"spec_file\\": \\"$SPEC_DIR/spec-001.md\\","
762
+ echo " \\"plan_file\\": \\"$PLAN_DIR/plan-001.md\\","
763
+ echo " \\"task_file\\": \\"$TASK_DIR/task-001.md\\","
764
+ echo " \\"task_dir\\": \\"$TASK_DIR\\""
765
+ echo "}"
766
+ exit 0
767
+ fi
768
+ fi
769
+ fi
770
+
771
+ # Fallback: find latest directories
772
+ LATEST=$(find specs -maxdepth 1 -type d -name "[0-9][0-9][0-9]-*" | sort -r | head -1)
773
+ if [ -n "$LATEST" ]; then
774
+ BRANCH=$(basename "$LATEST")
775
+ echo "{"
776
+ echo " \\"branch\\": \\"$BRANCH\\","
777
+ echo " \\"spec_file\\": \\"specs/$BRANCH/spec-001.md\\","
778
+ echo " \\"plan_file\\": \\"plans/$BRANCH/plan-001.md\\","
779
+ echo " \\"task_file\\": \\"tasks/$BRANCH/task-001.md\\","
780
+ echo " \\"task_dir\\": \\"tasks/$BRANCH\\""
781
+ echo "}"
782
+ else
783
+ echo "{\\"error\\": \\"No active feature found\\"}"
784
+ exit 1
785
+ fi
786
+ fi
787
+ """
788
+
789
+ def get_validate_script(self) -> str:
790
+ """Get validation script"""
791
+ return """#!/bin/bash
792
+ # SpecPulse Validation Script
793
+
794
+ validate_spec() {
795
+ local spec_file=$1
796
+ local errors=0
797
+
798
+ echo "Validating: $spec_file"
799
+
800
+ # Check required sections
801
+ if ! grep -q "## Requirements" $spec_file; then
802
+ echo " ❌ Missing Requirements section"
803
+ ((errors++))
804
+ fi
805
+
806
+ if ! grep -q "## User Stories" $spec_file; then
807
+ echo " ❌ Missing User Stories section"
808
+ ((errors++))
809
+ fi
810
+
811
+ if ! grep -q "## Acceptance Criteria" $spec_file; then
812
+ echo " ❌ Missing Acceptance Criteria section"
813
+ ((errors++))
814
+ fi
815
+
816
+ # Check for clarification markers
817
+ if grep -q "\\[NEEDS CLARIFICATION\\]" $spec_file; then
818
+ echo " ⚠️ Contains items needing clarification"
819
+ fi
820
+
821
+ if [ $errors -eq 0 ]; then
822
+ echo " ✅ Specification valid"
823
+ return 0
824
+ else
825
+ echo " ❌ Specification has $errors errors"
826
+ return 1
827
+ fi
828
+ }
829
+
830
+ # Main
831
+ if [ "$1" == "spec" ]; then
832
+ validate_spec $2
833
+ elif [ "$1" == "all" ]; then
834
+ for spec in specs/*/spec-001.md; do
835
+ validate_spec $spec
836
+ done
837
+ fi
838
+ """
839
+
840
+ def get_generate_script(self) -> str:
841
+ """Get generation script"""
842
+ return """#!/bin/bash
843
+ # SpecPulse Generation Script
844
+
845
+ generate_from_template() {
846
+ local template=$1
847
+ local output=$2
848
+ local feature_name=$3
849
+
850
+ # Replace placeholders
851
+ sed "s/\\[FEATURE_NAME\\]/$feature_name/g" $template > $output
852
+ sed -i "s/\\[DATE\\]/$(date +%Y-%m-%d)/g" $output
853
+ sed -i "s/\\[XXX\\]/$(printf '%03d' $RANDOM)/g" $output
854
+
855
+ echo "Generated: $output"
856
+ }
857
+
858
+ # Main
859
+ if [ "$1" == "spec" ]; then
860
+ generate_from_template templates/spec-001.md $2 $3
861
+ elif [ "$1" == "plan" ]; then
862
+ generate_from_template templates/plan-001.md $2 $3
863
+ elif [ "$1" == "task" ]; then
864
+ generate_from_template templates/task.md $2 $3
865
+ fi
866
+ """
867
+
868
+ def get_claude_instructions(self) -> str:
869
+ """Get Claude instructions"""
870
+ return """# SpecPulse Commands for Claude
871
+
872
+ You have access to SpecPulse commands for specification-driven development.
873
+
874
+ ## Available Commands
875
+
876
+ ### /sp-pulse <feature-name>
877
+ Initializes a new feature with proper structure.
878
+ - Creates feature branch
879
+ - Sets up specification directory
880
+ - Loads templates
881
+ - Updates context
882
+
883
+ ### /sp-spec create <description>
884
+ Creates a detailed specification from description.
885
+ - Use the template in templates/spec-001.md
886
+ - Mark uncertainties with [NEEDS CLARIFICATION]
887
+ - Ensure all sections are complete
888
+ - Validate against constitution
889
+
890
+ ### /sp-plan generate
891
+ Generates implementation plan from current specification.
892
+ - Read the active specification
893
+ - Create detailed phases
894
+ - Include technology decisions
895
+ - Add time estimates
896
+
897
+ ### /sp-task breakdown
898
+ Creates task list from implementation plan.
899
+ - Identify dependencies
900
+ - Mark parallel tasks with [P]
901
+ - Add time estimates
902
+ - Create critical path
903
+
904
+ ### /validate <component>
905
+ Validates specifications, plans, or project.
906
+ - Check completeness
907
+ - Verify consistency
908
+ - Ensure constitution compliance
909
+
910
+ ## Workflow
911
+
912
+ 1. User requests feature Use `/sp-pulse`
913
+ 2. User describes requirements → Use `/sp-spec create`
914
+ 3. Specification complete → Use `/sp-plan generate`
915
+ 4. Plan approved → Use `/sp-task breakdown`
916
+ 5. Before implementation → Use `/validate all`
917
+
918
+ ## Constitution Rules
919
+
920
+ Always enforce these principles:
921
+ 1. Simplicity first
922
+ 2. Test-driven development
923
+ 3. Single responsibility
924
+ 4. Documentation as code
925
+ 5. Security by design
926
+
927
+ ## Context Management
928
+
929
+ - Read `memory/context.md` for project state
930
+ - Update context after major decisions
931
+ - Check `memory/constitution.md` for principles
932
+ - Reference previous specs for consistency
933
+
934
+ ## Templates
935
+
936
+ Always use templates from `templates/` directory:
937
+ - `spec-001.md` for specifications
938
+ - `plan-001.md` for implementation plans
939
+ - `task.md` for task lists
940
+
941
+ ## Best Practices
942
+
943
+ 1. Always validate before moving to next phase
944
+ 2. Keep specifications testable and measurable
945
+ 3. Update context.md with decisions
946
+ 4. Create atomic, focused commits
947
+ 5. Document rationale for technology choices
948
+ """
949
+
950
+ # Claude command getters
951
+ def get_claude_pulse_command(self) -> str:
952
+ """Get Claude pulse command"""
953
+ command_path = self.resources_dir / "commands" / "claude" / "pulse.md"
954
+ if command_path.exists():
955
+ with open(command_path, 'r', encoding='utf-8') as f:
956
+ return f.read()
957
+ return "# /sp-pulse command not found"
958
+
959
+ def get_claude_spec_command(self) -> str:
960
+ """Get Claude spec command"""
961
+ command_path = self.resources_dir / "commands" / "claude" / "spec-001.md"
962
+ if command_path.exists():
963
+ with open(command_path, 'r', encoding='utf-8') as f:
964
+ return f.read()
965
+ return "# /sp-spec command not found"
966
+
967
+ def get_claude_plan_command(self) -> str:
968
+ """Get Claude plan command"""
969
+ command_path = self.resources_dir / "commands" / "claude" / "plan-001.md"
970
+ if command_path.exists():
971
+ with open(command_path, 'r', encoding='utf-8') as f:
972
+ return f.read()
973
+ return "# /sp-plan command not found"
974
+
975
+ def get_claude_task_command(self) -> str:
976
+ """Get Claude task command"""
977
+ command_path = self.resources_dir / "commands" / "claude" / "task.md"
978
+ if command_path.exists():
979
+ with open(command_path, 'r', encoding='utf-8') as f:
980
+ return f.read()
981
+ return "# /sp-task command not found"
982
+
983
+ # Gemini command getters
984
+ def get_gemini_pulse_command(self) -> str:
985
+ """Get Gemini pulse command"""
986
+ command_path = self.resources_dir / "commands" / "gemini" / "pulse.toml"
987
+ if command_path.exists():
988
+ with open(command_path, 'r', encoding='utf-8') as f:
989
+ return f.read()
990
+ return "# Gemini pulse command not found"
991
+
992
+ def get_gemini_spec_command(self) -> str:
993
+ """Get Gemini spec command"""
994
+ command_path = self.resources_dir / "commands" / "gemini" / "spec.toml"
995
+ if command_path.exists():
996
+ with open(command_path, 'r', encoding='utf-8') as f:
997
+ return f.read()
998
+ return "# Gemini spec command not found"
999
+
1000
+ def get_gemini_plan_command(self) -> str:
1001
+ """Get Gemini plan command"""
1002
+ command_path = self.resources_dir / "commands" / "gemini" / "plan.toml"
1003
+ if command_path.exists():
1004
+ with open(command_path, 'r', encoding='utf-8') as f:
1005
+ return f.read()
1006
+ return "# Gemini plan command not found"
1007
+
1008
+ def get_gemini_task_command(self) -> str:
1009
+ """Get Gemini task command"""
1010
+ command_path = self.resources_dir / "commands" / "gemini" / "task.toml"
1011
+ if command_path.exists():
1012
+ with open(command_path, 'r', encoding='utf-8') as f:
1013
+ return f.read()
1014
+ return "# Gemini task command not found"
1015
+
1016
+ def get_gemini_instructions(self) -> str:
1017
+ """Get Gemini instructions"""
1018
+ return """# SpecPulse Commands for Gemini CLI
1019
+
1020
+ This project uses SpecPulse for specification-driven development.
1021
+
1022
+ ## Command Reference
1023
+
1024
+ ### Initialization
1025
+ ```
1026
+ /sp-pulse <feature-name>
1027
+ ```
1028
+ Creates new feature structure and branch.
1029
+
1030
+ ### Specification Creation
1031
+ ```
1032
+ /sp-spec create <description>
1033
+ ```
1034
+ Generates detailed specification from natural language.
1035
+
1036
+ Required sections:
1037
+ - Requirements (functional and non-functional)
1038
+ - User stories with acceptance criteria
1039
+ - Technical constraints
1040
+ - Dependencies
1041
+ - Risks and mitigations
1042
+
1043
+ ### Plan Generation
1044
+ ```
1045
+ /sp-plan generate [--optimize <focus>]
1046
+ ```
1047
+ Creates implementation plan from specification.
1048
+
1049
+ Optimization options:
1050
+ - performance: Speed and efficiency focus
1051
+ - security: Security-first approach
1052
+ - simplicity: Maintainable solution
1053
+ - cost: Resource optimization
1054
+
1055
+ ### Task Breakdown
1056
+ ```
1057
+ /sp-task breakdown [--parallel]
1058
+ ```
1059
+ Generates actionable task list.
1060
+
1061
+ Features:
1062
+ - Dependency detection
1063
+ - Parallel task identification
1064
+ - Time estimation
1065
+ - Critical path analysis
1066
+
1067
+ ### Validation
1068
+ ```
1069
+ /validate [all|spec|plan|constitution]
1070
+ ```
1071
+ Validates project components.
1072
+
1073
+ ## Templates Location
1074
+
1075
+ Use templates from `templates/` directory:
1076
+ - Specification: templates/spec-001.md
1077
+ - Implementation: templates/plan-001.md
1078
+ - Tasks: templates/task.md
1079
+
1080
+ ## Memory System
1081
+
1082
+ Project memory in `memory/` directory:
1083
+ - constitution.md: Immutable principles
1084
+ - context.md: Current project state
1085
+ - decisions.md: Architectural decisions
1086
+
1087
+ ## Workflow Process
1088
+
1089
+ 1. **Initialize Feature**
1090
+ - Run: `/sp-pulse feature-name`
1091
+ - Creates branch and structure
1092
+
1093
+ 2. **Create Specification**
1094
+ - Run: `/sp-spec create "description"`
1095
+ - Fill template completely
1096
+ - Mark unclear items: [NEEDS CLARIFICATION]
1097
+
1098
+ 3. **Generate Plan**
1099
+ - Run: `/sp-plan generate`
1100
+ - Choose optimization focus
1101
+ - Review technology choices
1102
+
1103
+ 4. **Create Tasks**
1104
+ - Run: `/sp-task breakdown`
1105
+ - Review dependencies
1106
+ - Check time estimates
1107
+
1108
+ 5. **Validate**
1109
+ - Run: `/validate all`
1110
+ - Fix any issues
1111
+ - Proceed to implementation
1112
+
1113
+ ## Constitution Principles
1114
+
1115
+ Enforce these rules:
1116
+ 1. Start simple, add complexity only when needed
1117
+ 2. Write tests before code
1118
+ 3. One responsibility per component
1119
+ 4. Document everything
1120
+ 5. Consider security from start
1121
+
1122
+ ## Project Structure
1123
+
1124
+ ```
1125
+ project/
1126
+ ├── specs/ # Specifications
1127
+ ├── plans/ # Implementation plans
1128
+ ├── tasks/ # Task lists
1129
+ ├── memory/ # Project memory
1130
+ ├── scripts/ # Automation
1131
+ └── templates/ # Templates
1132
+ ```
1133
+
1134
+ ## Important Notes
1135
+
1136
+ - Always update context.md after decisions
1137
+ - Validate specifications before planning
1138
+ - Use [P] marker for parallel tasks
1139
+ - Keep commits atomic and focused
1140
+ - Reference constitution for all decisions
1106
1141
  """