opencode-metis 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +140 -0
  2. package/dist/cli.cjs +63 -0
  3. package/dist/mcp-server.cjs +51 -0
  4. package/dist/plugin.cjs +4 -0
  5. package/dist/worker.cjs +224 -0
  6. package/opencode/agent/the-analyst/feature-prioritization.md +66 -0
  7. package/opencode/agent/the-analyst/market-research.md +77 -0
  8. package/opencode/agent/the-analyst/project-coordination.md +81 -0
  9. package/opencode/agent/the-analyst/requirements-analysis.md +77 -0
  10. package/opencode/agent/the-architect/compatibility-review.md +138 -0
  11. package/opencode/agent/the-architect/complexity-review.md +137 -0
  12. package/opencode/agent/the-architect/quality-review.md +67 -0
  13. package/opencode/agent/the-architect/security-review.md +127 -0
  14. package/opencode/agent/the-architect/system-architecture.md +119 -0
  15. package/opencode/agent/the-architect/system-documentation.md +83 -0
  16. package/opencode/agent/the-architect/technology-research.md +85 -0
  17. package/opencode/agent/the-chief.md +79 -0
  18. package/opencode/agent/the-designer/accessibility-implementation.md +101 -0
  19. package/opencode/agent/the-designer/design-foundation.md +74 -0
  20. package/opencode/agent/the-designer/interaction-architecture.md +75 -0
  21. package/opencode/agent/the-designer/user-research.md +70 -0
  22. package/opencode/agent/the-meta-agent.md +155 -0
  23. package/opencode/agent/the-platform-engineer/ci-cd-pipelines.md +109 -0
  24. package/opencode/agent/the-platform-engineer/containerization.md +106 -0
  25. package/opencode/agent/the-platform-engineer/data-architecture.md +81 -0
  26. package/opencode/agent/the-platform-engineer/dependency-review.md +144 -0
  27. package/opencode/agent/the-platform-engineer/deployment-automation.md +81 -0
  28. package/opencode/agent/the-platform-engineer/infrastructure-as-code.md +107 -0
  29. package/opencode/agent/the-platform-engineer/performance-tuning.md +82 -0
  30. package/opencode/agent/the-platform-engineer/pipeline-engineering.md +81 -0
  31. package/opencode/agent/the-platform-engineer/production-monitoring.md +105 -0
  32. package/opencode/agent/the-qa-engineer/exploratory-testing.md +66 -0
  33. package/opencode/agent/the-qa-engineer/performance-testing.md +81 -0
  34. package/opencode/agent/the-qa-engineer/quality-assurance.md +77 -0
  35. package/opencode/agent/the-qa-engineer/test-execution.md +66 -0
  36. package/opencode/agent/the-software-engineer/api-development.md +78 -0
  37. package/opencode/agent/the-software-engineer/component-development.md +79 -0
  38. package/opencode/agent/the-software-engineer/concurrency-review.md +141 -0
  39. package/opencode/agent/the-software-engineer/domain-modeling.md +66 -0
  40. package/opencode/agent/the-software-engineer/performance-optimization.md +113 -0
  41. package/opencode/command/analyze.md +149 -0
  42. package/opencode/command/constitution.md +178 -0
  43. package/opencode/command/debug.md +194 -0
  44. package/opencode/command/document.md +178 -0
  45. package/opencode/command/implement.md +225 -0
  46. package/opencode/command/refactor.md +207 -0
  47. package/opencode/command/review.md +229 -0
  48. package/opencode/command/simplify.md +267 -0
  49. package/opencode/command/specify.md +191 -0
  50. package/opencode/command/validate.md +224 -0
  51. package/opencode/skill/accessibility-design/SKILL.md +566 -0
  52. package/opencode/skill/accessibility-design/checklists/wcag-checklist.md +435 -0
  53. package/opencode/skill/agent-coordination/SKILL.md +224 -0
  54. package/opencode/skill/api-contract-design/SKILL.md +550 -0
  55. package/opencode/skill/api-contract-design/templates/graphql-schema-template.md +818 -0
  56. package/opencode/skill/api-contract-design/templates/rest-api-template.md +417 -0
  57. package/opencode/skill/architecture-design/SKILL.md +160 -0
  58. package/opencode/skill/architecture-design/examples/architecture-examples.md +170 -0
  59. package/opencode/skill/architecture-design/template.md +749 -0
  60. package/opencode/skill/architecture-design/validation.md +99 -0
  61. package/opencode/skill/architecture-selection/SKILL.md +522 -0
  62. package/opencode/skill/architecture-selection/examples/adrs/001-example-adr.md +71 -0
  63. package/opencode/skill/architecture-selection/examples/architecture-patterns.md +239 -0
  64. package/opencode/skill/bug-diagnosis/SKILL.md +235 -0
  65. package/opencode/skill/code-quality-review/SKILL.md +337 -0
  66. package/opencode/skill/code-quality-review/examples/anti-patterns.md +629 -0
  67. package/opencode/skill/code-quality-review/reference.md +322 -0
  68. package/opencode/skill/code-review/SKILL.md +363 -0
  69. package/opencode/skill/code-review/reference.md +450 -0
  70. package/opencode/skill/codebase-analysis/SKILL.md +139 -0
  71. package/opencode/skill/codebase-navigation/SKILL.md +227 -0
  72. package/opencode/skill/codebase-navigation/examples/exploration-patterns.md +263 -0
  73. package/opencode/skill/coding-conventions/SKILL.md +178 -0
  74. package/opencode/skill/coding-conventions/checklists/accessibility-checklist.md +176 -0
  75. package/opencode/skill/coding-conventions/checklists/performance-checklist.md +154 -0
  76. package/opencode/skill/coding-conventions/checklists/security-checklist.md +127 -0
  77. package/opencode/skill/constitution-validation/SKILL.md +315 -0
  78. package/opencode/skill/constitution-validation/examples/CONSTITUTION.md +202 -0
  79. package/opencode/skill/constitution-validation/reference/rule-patterns.md +328 -0
  80. package/opencode/skill/constitution-validation/template.md +115 -0
  81. package/opencode/skill/context-preservation/SKILL.md +445 -0
  82. package/opencode/skill/data-modeling/SKILL.md +385 -0
  83. package/opencode/skill/data-modeling/templates/schema-design-template.md +268 -0
  84. package/opencode/skill/deployment-pipeline-design/SKILL.md +579 -0
  85. package/opencode/skill/deployment-pipeline-design/templates/pipeline-template.md +633 -0
  86. package/opencode/skill/documentation-extraction/SKILL.md +259 -0
  87. package/opencode/skill/documentation-sync/SKILL.md +431 -0
  88. package/opencode/skill/domain-driven-design/SKILL.md +509 -0
  89. package/opencode/skill/domain-driven-design/examples/ddd-patterns.md +688 -0
  90. package/opencode/skill/domain-driven-design/reference.md +465 -0
  91. package/opencode/skill/drift-detection/SKILL.md +383 -0
  92. package/opencode/skill/drift-detection/reference.md +340 -0
  93. package/opencode/skill/error-recovery/SKILL.md +162 -0
  94. package/opencode/skill/error-recovery/examples/error-patterns.md +484 -0
  95. package/opencode/skill/feature-prioritization/SKILL.md +419 -0
  96. package/opencode/skill/feature-prioritization/examples/rice-template.md +139 -0
  97. package/opencode/skill/feature-prioritization/reference.md +256 -0
  98. package/opencode/skill/git-workflow/SKILL.md +453 -0
  99. package/opencode/skill/implementation-planning/SKILL.md +215 -0
  100. package/opencode/skill/implementation-planning/examples/phase-examples.md +217 -0
  101. package/opencode/skill/implementation-planning/template.md +220 -0
  102. package/opencode/skill/implementation-planning/validation.md +88 -0
  103. package/opencode/skill/implementation-verification/SKILL.md +272 -0
  104. package/opencode/skill/knowledge-capture/SKILL.md +265 -0
  105. package/opencode/skill/knowledge-capture/reference/knowledge-capture.md +402 -0
  106. package/opencode/skill/knowledge-capture/reference.md +444 -0
  107. package/opencode/skill/knowledge-capture/templates/domain-template.md +325 -0
  108. package/opencode/skill/knowledge-capture/templates/interface-template.md +255 -0
  109. package/opencode/skill/knowledge-capture/templates/pattern-template.md +144 -0
  110. package/opencode/skill/observability-design/SKILL.md +291 -0
  111. package/opencode/skill/observability-design/references/monitoring-patterns.md +461 -0
  112. package/opencode/skill/pattern-detection/SKILL.md +171 -0
  113. package/opencode/skill/pattern-detection/examples/common-patterns.md +359 -0
  114. package/opencode/skill/performance-analysis/SKILL.md +266 -0
  115. package/opencode/skill/performance-analysis/references/profiling-tools.md +499 -0
  116. package/opencode/skill/requirements-analysis/SKILL.md +139 -0
  117. package/opencode/skill/requirements-analysis/examples/good-prd.md +66 -0
  118. package/opencode/skill/requirements-analysis/template.md +177 -0
  119. package/opencode/skill/requirements-analysis/validation.md +69 -0
  120. package/opencode/skill/requirements-elicitation/SKILL.md +518 -0
  121. package/opencode/skill/requirements-elicitation/examples/interview-questions.md +226 -0
  122. package/opencode/skill/requirements-elicitation/examples/user-stories.md +414 -0
  123. package/opencode/skill/safe-refactoring/SKILL.md +312 -0
  124. package/opencode/skill/safe-refactoring/reference/code-smells.md +347 -0
  125. package/opencode/skill/security-assessment/SKILL.md +421 -0
  126. package/opencode/skill/security-assessment/checklists/security-review-checklist.md +285 -0
  127. package/opencode/skill/specification-management/SKILL.md +143 -0
  128. package/opencode/skill/specification-management/readme-template.md +32 -0
  129. package/opencode/skill/specification-management/reference.md +115 -0
  130. package/opencode/skill/specification-management/spec.py +229 -0
  131. package/opencode/skill/specification-validation/SKILL.md +397 -0
  132. package/opencode/skill/specification-validation/reference/3cs-framework.md +306 -0
  133. package/opencode/skill/specification-validation/reference/ambiguity-detection.md +132 -0
  134. package/opencode/skill/specification-validation/reference/constitution-validation.md +301 -0
  135. package/opencode/skill/specification-validation/reference/drift-detection.md +383 -0
  136. package/opencode/skill/task-delegation/SKILL.md +607 -0
  137. package/opencode/skill/task-delegation/examples/file-coordination.md +495 -0
  138. package/opencode/skill/task-delegation/examples/parallel-research.md +337 -0
  139. package/opencode/skill/task-delegation/examples/sequential-build.md +504 -0
  140. package/opencode/skill/task-delegation/reference.md +825 -0
  141. package/opencode/skill/tech-stack-detection/SKILL.md +89 -0
  142. package/opencode/skill/tech-stack-detection/references/framework-signatures.md +598 -0
  143. package/opencode/skill/technical-writing/SKILL.md +190 -0
  144. package/opencode/skill/technical-writing/templates/adr-template.md +205 -0
  145. package/opencode/skill/technical-writing/templates/system-doc-template.md +380 -0
  146. package/opencode/skill/test-design/SKILL.md +464 -0
  147. package/opencode/skill/test-design/examples/test-pyramid.md +724 -0
  148. package/opencode/skill/testing/SKILL.md +213 -0
  149. package/opencode/skill/testing/examples/test-pyramid.md +724 -0
  150. package/opencode/skill/user-insight-synthesis/SKILL.md +576 -0
  151. package/opencode/skill/user-insight-synthesis/templates/research-plan-template.md +217 -0
  152. package/opencode/skill/user-research/SKILL.md +508 -0
  153. package/opencode/skill/user-research/examples/interview-questions.md +265 -0
  154. package/opencode/skill/user-research/examples/personas.md +267 -0
  155. package/opencode/skill/vibe-security/SKILL.md +654 -0
  156. package/package.json +45 -0
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: specification-management
3
+ description: "Provides methodology for scaffolding, status-checking, and managing specification directories including auto-incrementing IDs, README tracking, phase transitions, and decision logging"
4
+ license: MIT
5
+ compatibility: opencode
6
+ metadata:
7
+ category: analysis
8
+ version: "1.0"
9
+ ---
10
+
11
+ # Specification Management
12
+
13
+ Roleplay as a specification workflow orchestrator that manages specification directories and tracks user decisions throughout the PRD to SDD to PLAN workflow.
14
+
15
+ SpecificationManagement {
16
+ Activation {
17
+ When to use this skill:
18
+ - Create a new specification directory with auto-incrementing ID
19
+ - Check specification status (what documents exist)
20
+ - Track user decisions (e.g., "PRD skipped because requirements in JIRA")
21
+ - Manage phase transitions (PRD to SDD to PLAN)
22
+ - Initialize or update README.md in spec directories
23
+ - Read existing spec metadata via spec.py
24
+ }
25
+
26
+ SupportingFiles {
27
+ - [readme-template.md](readme-template.md) -- README template for spec directories
28
+ - [reference.md](reference.md) -- Extended specification metadata protocols
29
+ - [spec.py](spec.py) -- Script for directory creation and metadata reading
30
+ }
31
+
32
+ DirectoryManagement {
33
+ Constraints {
34
+ 1. Use `spec.py` to create and read specification directories
35
+ 2. The `spec.py` script is located in this skill's directory (alongside this SKILL.md file)
36
+ 3. Resolve `spec.py` from this skill's directory; the full path depends on your framework installation location
37
+ }
38
+
39
+ Commands {
40
+ ```bash
41
+ # Create new spec (auto-incrementing ID)
42
+ spec.py "feature-name"
43
+
44
+ # Read existing spec metadata (TOML output)
45
+ spec.py 004 --read
46
+
47
+ # Add template to existing spec
48
+ spec.py 004 --add product-requirements
49
+ ```
50
+ }
51
+
52
+ TOMLOutputFormat {
53
+ ```toml
54
+ id = "004"
55
+ name = "feature-name"
56
+ dir = "docs/specs/004-feature-name"
57
+
58
+ [spec]
59
+ prd = "docs/specs/004-feature-name/product-requirements.md"
60
+ sdd = "docs/specs/004-feature-name/solution-design.md"
61
+
62
+ files = [
63
+ "product-requirements.md",
64
+ "solution-design.md"
65
+ ]
66
+ ```
67
+ }
68
+ }
69
+
70
+ ReadmeManagement {
71
+ Constraints {
72
+ 1. Every spec directory should have a `README.md` tracking decisions and progress
73
+ 2. Create README.md when a new spec is created using the [readme-template.md](readme-template.md) template
74
+ }
75
+
76
+ UpdateTriggers {
77
+ Update README.md when:
78
+ - Phase transitions occur (start, complete, skip)
79
+ - User makes workflow decisions
80
+ - Context needs to be recorded
81
+ }
82
+ }
83
+
84
+ PhaseTransitions {
85
+ Workflow {
86
+ 1. Check existing state -- Use `spec.py [ID] --read`
87
+ 2. Suggest continuation point based on existing documents (evaluate top-to-bottom, first match wins)
88
+ 3. Record decisions in README.md
89
+ 4. Update phase status as work progresses
90
+ }
91
+
92
+ ContinuationTable {
93
+ | IF state is | THEN suggest |
94
+ |---|---|
95
+ | `plan` exists | "PLAN found. Proceed to implementation?" |
96
+ | `sdd` exists but no `plan` | "SDD found. Continue to PLAN?" |
97
+ | `prd` exists but no `sdd` | "PRD found. Continue to SDD?" |
98
+ | No documents exist | "Start from PRD?" |
99
+ }
100
+ }
101
+
102
+ DecisionTracking {
103
+ Constraints {
104
+ 1. Log all significant decisions in README.md
105
+ }
106
+
107
+ Format {
108
+ ```markdown
109
+ ## Decisions Log
110
+
111
+ | Date | Decision | Rationale |
112
+ |------|----------|-----------|
113
+ | 2025-12-10 | PRD skipped | Requirements documented in JIRA-1234 |
114
+ | 2025-12-10 | Start with SDD | Technical spike already completed |
115
+ ```
116
+ }
117
+ }
118
+
119
+ WorkflowIntegration {
120
+ RelatedSkills {
121
+ - `requirements-analysis` skill -- PRD creation and validation
122
+ - `architecture-design` skill -- SDD creation and validation
123
+ - `implementation-planning` skill -- PLAN creation and validation
124
+ }
125
+
126
+ HandoffPattern {
127
+ 1. Specification-management creates directory and README
128
+ 2. User confirms phase to start
129
+ 3. Context shifts to document-specific work
130
+ 4. Document skill activates for detailed guidance
131
+ 5. On completion, context returns here for phase transition
132
+ }
133
+ }
134
+
135
+ ValidationChecklist {
136
+ Before completing any operation:
137
+ - [ ] spec.py command executed successfully
138
+ - [ ] README.md exists and is up-to-date
139
+ - [ ] Current phase is correctly recorded
140
+ - [ ] All decisions have been logged
141
+ - [ ] User has confirmed next steps
142
+ }
143
+ }
@@ -0,0 +1,32 @@
1
+ # Specification: {{SPEC_ID}}-{{SPEC_NAME}}
2
+
3
+ ## Status
4
+
5
+ | Field | Value |
6
+ |-------|-------|
7
+ | **Created** | {{CREATED_DATE}} |
8
+ | **Current Phase** | {{CURRENT_PHASE}} |
9
+ | **Last Updated** | {{LAST_UPDATED}} |
10
+
11
+ ## Documents
12
+
13
+ | Document | Status | Notes |
14
+ |----------|--------|-------|
15
+ | product-requirements.md | {{PRD_STATUS}} | {{PRD_NOTES}} |
16
+ | solution-design.md | {{SDD_STATUS}} | {{SDD_NOTES}} |
17
+ | implementation-plan.md | {{PLAN_STATUS}} | {{PLAN_NOTES}} |
18
+
19
+ **Status values**: `pending` | `in_progress` | `completed` | `skipped`
20
+
21
+ ## Decisions Log
22
+
23
+ | Date | Decision | Rationale |
24
+ |------|----------|-----------|
25
+ | {{DATE}} | {{DECISION}} | {{RATIONALE}} |
26
+
27
+ ## Context
28
+
29
+ {{CONTEXT_NOTES}}
30
+
31
+ ---
32
+ *This file is managed by the specification-management skill.*
@@ -0,0 +1,115 @@
1
+ # Specification Management Reference
2
+
3
+ ## Spec ID Format
4
+
5
+ - **Format**: 3-digit zero-padded number (001, 002, ..., 999)
6
+ - **Auto-incrementing**: Script scans existing directories to find next ID
7
+ - **Directory naming**: `[NNN]-[sanitized-feature-name]`
8
+ - **Sanitization**: Lowercase, special chars to hyphens, trim leading/trailing hyphens
9
+
10
+ ## Directory Structure
11
+
12
+ ```
13
+ docs/specs/
14
+ ├── 001-user-authentication/
15
+ │ ├── README.md # Managed by specification-management skill
16
+ │ ├── product-requirements.md # Created by requirements-analysis skill
17
+ │ ├── solution-design.md # Created by architecture-design skill
18
+ │ └── implementation-plan.md # Created by implementation-planning skill
19
+ ├── 002-payment-processing/
20
+ │ └── ...
21
+ └── 003-notification-system/
22
+ └── ...
23
+ ```
24
+
25
+ ## Script Commands
26
+
27
+ ### Create New Spec
28
+ ```bash
29
+ spec.py "feature name here"
30
+ ```
31
+ **Output:**
32
+ ```
33
+ Created spec directory: docs/specs/005-feature-name-here
34
+ Spec ID: 005
35
+ Specification directory created successfully
36
+ ```
37
+
38
+ ### Read Spec Metadata
39
+ ```bash
40
+ spec.py 005 --read
41
+ ```
42
+ **Output (TOML):**
43
+ ```toml
44
+ id = "005"
45
+ name = "feature-name-here"
46
+ dir = "docs/specs/005-feature-name-here"
47
+
48
+ [spec]
49
+ prd = "docs/specs/005-feature-name-here/product-requirements.md"
50
+ sdd = "docs/specs/005-feature-name-here/solution-design.md"
51
+
52
+ files = [
53
+ "product-requirements.md",
54
+ "README.md",
55
+ "solution-design.md"
56
+ ]
57
+ ```
58
+
59
+ ### Add Template to Existing Spec
60
+ ```bash
61
+ spec.py 005 --add product-requirements
62
+ spec.py 005 --add solution-design
63
+ spec.py 005 --add implementation-plan
64
+ ```
65
+
66
+ ## Template Resolution
67
+
68
+ Templates are resolved in this order:
69
+ 1. `skills/[template-name]/template.md` (primary)
70
+ 2. `templates/[template-name].md` (deprecated fallback)
71
+
72
+ ## README.md Fields
73
+
74
+ | Field | Description |
75
+ |-------|-------------|
76
+ | Created | Date spec was created |
77
+ | Current Phase | Active workflow phase |
78
+ | Last Updated | Date of last status change |
79
+ | Document Status | pending, in_progress, completed, skipped |
80
+ | Notes | Additional context for each document |
81
+
82
+ ## Phase Workflow
83
+
84
+ ```
85
+ Initialization
86
+ |
87
+ PRD (Product Requirements)
88
+ |
89
+ SDD (Solution Design)
90
+ |
91
+ PLAN (Implementation Plan)
92
+ |
93
+ Ready for Implementation
94
+ ```
95
+
96
+ Each phase can be:
97
+ - **Completed**: Document finished and validated
98
+ - **Skipped**: User decided to skip (decision logged)
99
+ - **In Progress**: Currently being worked on
100
+ - **Pending**: Not yet started
101
+
102
+ ## Decision Logging
103
+
104
+ Record decisions with:
105
+ - **Date**: When the decision was made
106
+ - **Decision**: What was decided
107
+ - **Rationale**: Why (external references like JIRA IDs welcome)
108
+
109
+ Example:
110
+ ```markdown
111
+ | Date | Decision | Rationale |
112
+ |------|----------|-----------|
113
+ | 2025-12-10 | PRD skipped | Requirements in JIRA-1234 |
114
+ | 2025-12-10 | Start with SDD | Technical spike completed |
115
+ ```
@@ -0,0 +1,229 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ The Agentic Startup - Spec Generation Script
4
+ Creates numbered spec directories with auto-incrementing IDs
5
+
6
+ Location: ~/.config/opencode/skill/specification-management/spec.py
7
+ Template resolution: skills/[template-name]/template.md (primary)
8
+ templates/[template-name].md (fallback, deprecated)
9
+ """
10
+
11
+ import argparse
12
+ import re
13
+ import sys
14
+ from pathlib import Path
15
+ from typing import Optional
16
+
17
+
18
+ # Get plugin root from script location
19
+ # This script is at: ~/.config/opencode/skill/specification-management/spec.py
20
+ # Plugin root is: plugins/start/
21
+ script_dir = Path(__file__).resolve().parent
22
+ plugin_root = script_dir.parent.parent
23
+
24
+ # Specs are created in the current working directory
25
+ SPECS_DIR = Path("docs/specs")
26
+ # Skills directory for primary template lookup
27
+ SKILLS_DIR = plugin_root / "skills"
28
+ # Templates directory for fallback (deprecated)
29
+ TEMPLATES_DIR = plugin_root / "templates"
30
+
31
+
32
+ def get_template_path(template_name: str) -> Path:
33
+ """
34
+ Resolve template path with skill-first, legacy-fallback pattern.
35
+
36
+ Resolution order:
37
+ 1. skills/[template-name]/template.md (new location)
38
+ 2. templates/[template-name].md (deprecated, backward compat)
39
+ """
40
+ # Primary: Look in skill directory
41
+ skill_template = SKILLS_DIR / template_name / "template.md"
42
+ if skill_template.exists():
43
+ return skill_template
44
+
45
+ # Fallback: Legacy templates directory (deprecated)
46
+ legacy_template = TEMPLATES_DIR / f"{template_name}.md"
47
+ if legacy_template.exists():
48
+ print(f"Warning: Using deprecated template location. "
49
+ f"Template should be at: {skill_template}", file=sys.stderr)
50
+ return legacy_template
51
+
52
+ raise FileNotFoundError(f"Template not found: {template_name}")
53
+
54
+
55
+ def get_next_spec_id() -> str:
56
+ """Get next available spec ID by scanning existing directories."""
57
+ max_id = 0
58
+
59
+ if SPECS_DIR.exists():
60
+ # Find highest existing spec number
61
+ for dir_path in SPECS_DIR.iterdir():
62
+ if dir_path.is_dir():
63
+ # Extract number from pattern: 001-feature-name
64
+ match = re.match(r'^(\d{3})-', dir_path.name)
65
+ if match:
66
+ num = int(match.group(1))
67
+ if num > max_id:
68
+ max_id = num
69
+
70
+ # Return next ID with zero-padding
71
+ return f"{max_id + 1:03d}"
72
+
73
+
74
+ def sanitize_name(name: str) -> str:
75
+ """Convert feature name to URL-friendly directory name."""
76
+ # Convert to lowercase
77
+ name = name.lower()
78
+ # Replace special characters with hyphens
79
+ name = re.sub(r'[^a-z0-9]+', '-', name)
80
+ # Remove leading/trailing hyphens
81
+ name = name.strip('-')
82
+ return name
83
+
84
+
85
+ def read_spec(spec_id: str) -> None:
86
+ """Read spec metadata and output TOML format."""
87
+ if not SPECS_DIR.exists():
88
+ print("Error: Specs directory not found", file=sys.stderr)
89
+ sys.exit(1)
90
+
91
+ # Find directory matching spec ID
92
+ spec_dir = None
93
+ for dir_path in SPECS_DIR.iterdir():
94
+ if dir_path.is_dir() and dir_path.name.startswith(f"{spec_id}-"):
95
+ spec_dir = dir_path
96
+ break
97
+
98
+ if not spec_dir:
99
+ print(f"Error: Spec {spec_id} not found", file=sys.stderr)
100
+ sys.exit(1)
101
+
102
+ # Extract name from directory
103
+ name = spec_dir.name[len(spec_id) + 1:] # Remove "001-" prefix
104
+
105
+ # Generate TOML output
106
+ print(f'id = "{spec_id}"')
107
+ print(f'name = "{name}"')
108
+ print(f'dir = "{spec_dir}"')
109
+
110
+ # List spec documents
111
+ print()
112
+ print("[spec]")
113
+ if (spec_dir / "product-requirements.md").exists():
114
+ print(f'prd = "{spec_dir / "product-requirements.md"}"')
115
+ if (spec_dir / "solution-design.md").exists():
116
+ print(f'sdd = "{spec_dir / "solution-design.md"}"')
117
+ if (spec_dir / "implementation-plan.md").exists():
118
+ print(f'plan = "{spec_dir / "implementation-plan.md"}"')
119
+
120
+ # List quality gates if they exist
121
+ gate_files = [
122
+ ("definition-of-ready.md", "definition_of_ready"),
123
+ ("definition-of-done.md", "definition_of_done"),
124
+ ("task-definition-of-done.md", "task_definition_of_done"),
125
+ ]
126
+
127
+ gate_exists = any((spec_dir / file).exists() for file, _ in gate_files)
128
+ if gate_exists:
129
+ print()
130
+ print("[gates]")
131
+ for file, key in gate_files:
132
+ if (spec_dir / file).exists():
133
+ print(f'{key} = "{spec_dir / file}"')
134
+
135
+ # List all files
136
+ print()
137
+ print("files = [")
138
+ files = sorted([f.name for f in spec_dir.iterdir() if f.is_file()])
139
+ for i, file in enumerate(files):
140
+ comma = "," if i < len(files) - 1 else ""
141
+ print(f' "{file}"{comma}')
142
+ print("]")
143
+
144
+
145
+ def create_spec(feature_name: str, template: Optional[str] = None) -> None:
146
+ """Create a new spec directory with optional template."""
147
+ # Check if feature_name is an existing spec ID (3 digits)
148
+ is_spec_id = re.match(r'^\d{3}$', feature_name)
149
+
150
+ if is_spec_id and template:
151
+ # Try to find existing directory with this ID
152
+ if SPECS_DIR.exists():
153
+ for dir_path in SPECS_DIR.iterdir():
154
+ if dir_path.is_dir() and dir_path.name.startswith(f"{feature_name}-"):
155
+ spec_dir = dir_path
156
+ spec_id = feature_name
157
+ print(f"Adding template to existing spec: {spec_dir}")
158
+
159
+ # Copy template to existing directory using new resolution
160
+ try:
161
+ template_file = get_template_path(template)
162
+ dest_file = spec_dir / f"{template}.md"
163
+ dest_file.write_text(template_file.read_text())
164
+ print(f"Generated template: {template}.md")
165
+ except FileNotFoundError as e:
166
+ print(f"Error: {e}", file=sys.stderr)
167
+ sys.exit(1)
168
+ return
169
+
170
+ # If we get here, the spec ID was not found
171
+ print(f"Error: Spec {feature_name} not found", file=sys.stderr)
172
+ sys.exit(1)
173
+
174
+ # Create new spec directory
175
+ spec_id = get_next_spec_id()
176
+ sanitized_name = sanitize_name(feature_name)
177
+ spec_dir = SPECS_DIR / f"{spec_id}-{sanitized_name}"
178
+
179
+ # Create spec directory
180
+ spec_dir.mkdir(parents=True, exist_ok=True)
181
+
182
+ print(f"Created spec directory: {spec_dir}")
183
+ print(f"Spec ID: {spec_id}")
184
+
185
+ # Copy template if requested
186
+ if template:
187
+ try:
188
+ template_file = get_template_path(template)
189
+ dest_file = spec_dir / f"{template}.md"
190
+ dest_file.write_text(template_file.read_text())
191
+ print(f"Generated template: {template}.md")
192
+ except FileNotFoundError as e:
193
+ print(f"Warning: {e}", file=sys.stderr)
194
+
195
+ print("Specification directory created successfully")
196
+
197
+
198
+ def main():
199
+ """Main entry point."""
200
+ parser = argparse.ArgumentParser(
201
+ description="The Agentic Startup - Spec Generation Script"
202
+ )
203
+ parser.add_argument(
204
+ "feature_name",
205
+ help="Feature name or spec ID (for --read mode)"
206
+ )
207
+ parser.add_argument(
208
+ "--add",
209
+ metavar="TEMPLATE",
210
+ help="Add template file to spec directory"
211
+ )
212
+ parser.add_argument(
213
+ "--read",
214
+ action="store_true",
215
+ help="Read spec metadata and output TOML"
216
+ )
217
+
218
+ args = parser.parse_args()
219
+
220
+ # Handle read mode
221
+ if args.read:
222
+ read_spec(args.feature_name)
223
+ else:
224
+ # Handle spec creation
225
+ create_spec(args.feature_name, args.add)
226
+
227
+
228
+ if __name__ == "__main__":
229
+ main()