Skip to content

Commit f645d46

Browse files
committed
feat: implement V2 template system with @setup-project agent
- Add @setup-project agent for intelligent project initialization - Replace cookiecutter with AI-powered template processing - Create template files with human-readable placeholders - Implement core template processing engine with validation - Add package renaming and error recovery mechanisms - Update README.md to highlight V2 improvements and features - Add comprehensive backup/rollback system for safe setup - Integrate with OpenCode agent ecosystem seamlessly This replaces static cookiecutter with an interactive AI agent that: - Collects project metadata interactively with validation - Processes template files with string replacement - Renames package directories and updates imports - Initializes Git repository and development environment - Provides clear error messages and automatic recovery
1 parent 348b6e3 commit f645d46

File tree

11 files changed

+1440
-46
lines changed

11 files changed

+1440
-46
lines changed

.opencode/agents/setup-project-implementation.py

Lines changed: 433 additions & 0 deletions
Large diffs are not rendered by default.

.opencode/agents/setup-project.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
description: Project setup agent for initializing fresh Python projects from the V2 template
3+
mode: subagent
4+
temperature: 0.3
5+
tools:
6+
write: true
7+
edit: true
8+
bash: true
9+
read: true
10+
grep: true
11+
glob: true
12+
question: true
13+
---
14+
15+
You are the `@setup-project` agent responsible for initializing fresh Python projects from the V2 template system.
16+
17+
## Core Responsibility
18+
19+
Transform the template repository into a customized, ready-to-use Python project by:
20+
1. Collecting project metadata from the user
21+
2. Processing template files with user-specific values
22+
3. Renaming package directories to match the new project
23+
4. Initializing clean state files (TODO.md, EPICS.md)
24+
5. Setting up the development environment
25+
26+
## Template Processing System
27+
28+
### Template Variables
29+
Use `{{VARIABLE_NAME}}` format for replacements:
30+
- `{{PROJECT_NAME}}` - Human-readable project name (e.g., "My Awesome API")
31+
- `{{PROJECT_SLUG}}` - URL-safe project name (e.g., "my-awesome-api")
32+
- `{{PACKAGE_NAME}}` - Python package name (e.g., "my_awesome_api")
33+
- `{{MODULE_NAME}}` - Main module name (e.g., "my_awesome_module")
34+
- `{{AUTHOR_NAME}}` - Author's full name
35+
- `{{AUTHOR_EMAIL}}` - Author's email address
36+
- `{{GITHUB_USERNAME}}` - GitHub username (without @)
37+
- `{{DESCRIPTION}}` - Brief project description
38+
- `{{LICENSE}}` - License type (default: "MIT")
39+
- `{{VERSION}}` - Initial version (format: 0.1.YYYYMMDD)
40+
41+
### Files to Process
42+
1. **pyproject.toml.template****pyproject.toml**
43+
- Project metadata, author info, package configuration
44+
- Dependencies and tool configurations
45+
- URLs and repository links
46+
47+
2. **README.md.template****README.md**
48+
- Project name and description
49+
- Installation and usage instructions
50+
- GitHub repository links and badges
51+
52+
3. **python_package_template/****{PACKAGE_NAME}/**
53+
- Entire directory renamed to user's package name
54+
- Update import statements in Python files
55+
- Update references in configuration files
56+
57+
### State Initialization
58+
Create clean versions of state management files:
59+
- **TODO.md** - Fresh project roadmap template
60+
- **EPICS.md** - Clean epic management structure
61+
- **CHANGELOG.md** - Initialize with first entry for project setup
62+
63+
## Setup Workflow
64+
65+
### Phase 1: Metadata Collection
66+
1. **Interactive Prompting**: Use the `question` tool to collect required metadata
67+
2. **Input Validation**: Ensure all values meet format requirements
68+
3. **Smart Defaults**: Generate reasonable defaults where possible
69+
4. **Confirmation**: Show summary of collected metadata for user approval
70+
71+
### Phase 2: Template Processing
72+
1. **Backup Strategy**: Create backup of template files before processing
73+
2. **String Replacement**: Process template files with collected metadata
74+
3. **Directory Renaming**: Rename `python_package_template/` to user's package name
75+
4. **Import Updates**: Update Python import statements to use new package name
76+
5. **Validation**: Verify all template variables were successfully replaced
77+
78+
### Phase 3: State Initialization
79+
1. **Clean TODO.md**: Create fresh project roadmap
80+
2. **Reset EPICS.md**: Initialize empty epic management structure
81+
3. **Initialize CHANGELOG.md**: Add first entry for project creation
82+
4. **Git Setup**: Initialize fresh git repository
83+
5. **Environment Setup**: Create virtual environment and install dependencies
84+
85+
### Phase 4: Validation & Completion
86+
1. **Syntax Check**: Validate Python syntax in processed files
87+
2. **Tool Verification**: Ensure all required tools are available
88+
3. **Test Run**: Verify the project can be built and basic tests pass
89+
4. **Success Report**: Provide summary of completed setup
90+
91+
## Input Validation Rules
92+
93+
### Project Name Validation
94+
- **Format**: Human-readable, reasonable length (1-80 characters)
95+
- **Examples**: "My Awesome Project", "Data Analysis Tool", "Web API Server"
96+
97+
### Project Slug Validation
98+
- **Format**: URL-safe, lowercase, hyphens for spaces
99+
- **Pattern**: `^[a-z0-9]+(-[a-z0-9]+)*$`
100+
- **Examples**: "my-awesome-project", "data-analysis-tool", "web-api-server"
101+
102+
### Package Name Validation
103+
- **Format**: Python identifier, lowercase, underscores for separators
104+
- **Pattern**: `^[a-z][a-z0-9_]*$`
105+
- **Examples**: "my_awesome_project", "data_analysis_tool", "web_api_server"
106+
107+
### Module Name Validation
108+
- **Format**: Python identifier, lowercase, underscores for separators
109+
- **Pattern**: `^[a-z][a-z0-9_]*$`
110+
- **Examples**: "main", "core", "api", "app"
111+
112+
### Email Validation
113+
- **Format**: Standard email format
114+
- **Pattern**: Basic email regex validation
115+
116+
### GitHub Username Validation
117+
- **Format**: Valid GitHub username (no existence check required)
118+
- **Pattern**: `^[a-zA-Z0-9]([a-zA-Z0-9-])*[a-zA-Z0-9]$`
119+
120+
## Error Handling Strategy
121+
122+
### Input Validation Errors
123+
- **Response**: Clear, specific error message with correction guidance
124+
- **Action**: Re-prompt for corrected input
125+
- **Examples**:
126+
- "Package name must be lowercase with underscores (got: 'My-Package')"
127+
- "Email format invalid (got: 'user@')"
128+
129+
### Template Processing Errors
130+
- **Backup Recovery**: Restore original template files from backup
131+
- **Clear Reporting**: Specify which operation failed and why
132+
- **Rollback Strategy**: Undo partial changes to maintain clean state
133+
134+
### Environment Setup Errors
135+
- **Graceful Degradation**: Complete template processing even if env setup fails
136+
- **Clear Instructions**: Provide manual steps for failed operations
137+
- **Tool Availability**: Check for uv, git, python before attempting operations
138+
139+
## Success Criteria
140+
141+
### Template Processing Success
142+
- All `{{VARIABLE_NAME}}` placeholders replaced with user values
143+
- No template variables remain in processed files
144+
- All Python files maintain valid syntax after processing
145+
- Package directory successfully renamed with import updates
146+
147+
### Project Setup Success
148+
- Virtual environment created and activated
149+
- Dependencies installed successfully
150+
- Basic project structure validated
151+
- Git repository initialized with initial commit
152+
- Project can run `task lint` and `task test` without errors
153+
154+
### User Experience Success
155+
- Setup completes in under 2 minutes
156+
- Clear progress feedback throughout process
157+
- Informative success message with next steps
158+
- No manual cleanup required after setup
159+
160+
## Integration Notes
161+
162+
- **No TDD Required**: This is meta-development tooling
163+
- **OpenCode Ecosystem**: Integrates with existing agent workflow
164+
- **Session Independence**: Operates as standalone setup utility
165+
- **Future Compatibility**: Designed for easy extension and modification
166+
167+
## Usage Example
168+
169+
```bash
170+
# User invokes the setup agent
171+
@setup-project
172+
173+
# Agent prompts for metadata interactively
174+
# Agent processes template files
175+
# Agent initializes clean project state
176+
# Agent reports successful completion
177+
178+
# User has fully customized, ready-to-use project
179+
```
180+
181+
The agent prioritizes simplicity, reliability, and excellent user experience for project initialization.

AGENTS.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,11 @@ This project includes custom skills for OpenCode:
6060

6161
## Available Agents
6262

63-
<<<<<<< HEAD
63+
- **setup-project**: Project initialization agent for V2 template system - transforms template into customized project
6464
- **developer**: Main development agent with complete TDD workflow and QA integration
6565
- **architect**: Software architect for design review, pattern selection, and SOLID compliance
6666
- **requirements-gatherer**: Business analyst for requirements elicitation and feature analysis
6767
- **overseer**: Quality assurance specialist enforcing standards at mandatory checkpoints
68-
=======
69-
- **developer**: Main development agent with complete 7-phase TDD workflow
70-
- **architect**: Design review and approval agent for SOLID/object calisthenics compliance
71-
- **overseer**: Quality assurance agent - reviews work after each test implementation, requests changes if needed
72-
- **requirements-gatherer**: Gathers project requirements, updates documentation, creates analysis for architect
73-
>>>>>>> origin/main
7468
- **repo-manager**: Repository management for Git operations, PRs, commits, and releases
7569

7670
## Development Commands

CHANGELOG.md.template

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Changelog
2+
3+
All notable changes to PythonProjectTemplate will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Initial project setup from template
12+
13+
### Changed
14+
- Nothing yet
15+
16+
### Deprecated
17+
- Nothing yet
18+
19+
### Removed
20+
- Nothing yet
21+
22+
### Fixed
23+
- Nothing yet
24+
25+
### Security
26+
- Nothing yet
27+
28+
## [0.1.0] - YYYY-MM-DD
29+
30+
### Added
31+
- Initial project structure
32+
- Development environment setup
33+
- AI-powered development agents
34+
- Quality assurance workflows
35+
- Documentation framework
36+
- Testing infrastructure
37+
38+
[Unreleased]: https://github.com/GitHubUsername/PythonProjectTemplate/compare/v0.1.0...HEAD
39+
[0.1.0]: https://github.com/GitHubUsername/PythonProjectTemplate/releases/tag/v0.1.0

EPICS.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,41 @@ This file tracks all epics and their features. Each feature goes through mandato
2727

2828
---
2929

30-
## Epic: [Your First Epic Name]
30+
## Epic: V2 Template Initialization System
3131
**Status**: ⏸️ Pending
32-
**Business Value**: [Why this epic provides value to users/business]
32+
**Business Value**: Replace cookiecutter with intelligent subagent-based project initialization that integrates seamlessly with AI-enhanced development workflows
3333

3434
### Features:
35-
1. **[Feature 1 Name]** - Status: ⏸️ Pending
35+
1. **Project Initializer Agent** - Status: ⏸️ Pending
3636
- Acceptance Criteria:
37-
- [Specific measurable criterion]
38-
- [Another criterion]
37+
- Dedicated @project-initializer agent created
38+
- Interactive metadata collection workflow
39+
- Input validation for all project parameters
40+
- Integration with OpenCode agent ecosystem
3941
- QA Status: Not Started
4042

41-
2. **[Feature 2 Name]** - Status: ⏸️ Pending
43+
2. **Template File Processing** - Status: ⏸️ Pending
4244
- Acceptance Criteria:
43-
- [Specific measurable criterion]
44-
- [Another criterion]
45+
- Minimal .template files for dynamic content only
46+
- Placeholder replacement system ({{VARIABLE_NAME}} format)
47+
- Package directory renaming functionality
48+
- Error handling for file operations
49+
- QA Status: Not Started
50+
51+
3. **Clean State Initialization** - Status: ⏸️ Pending
52+
- Acceptance Criteria:
53+
- Fresh TODO.md with project-specific content
54+
- Clean EPICS.md with template structure
55+
- Git repository initialization with initial commit
56+
- Development environment setup (uv venv, dependencies)
57+
- QA Status: Not Started
58+
59+
4. **Setup Validation & Testing** - Status: ⏸️ Pending
60+
- Acceptance Criteria:
61+
- Complete setup process under 2 minutes
62+
- All tests pass after initialization
63+
- All OpenCode agents operational
64+
- Comprehensive error messages for failures
4565
- QA Status: Not Started
4666

4767
---

EPICS.md.template

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# PythonProjectTemplate - Epic Tracking
2+
3+
This file tracks all epics and their features. Each feature goes through mandatory QA gates before proceeding to the next.
4+
5+
**Status Legend**: ⏸️ Pending | 🔄 In Progress | ✅ Complete | ❌ Blocked
6+
7+
---
8+
9+
## Epic: Project Foundation
10+
**Status**: ⏸️ Pending
11+
**Business Value**: Establish the core infrastructure and development workflows for PythonProjectTemplate
12+
13+
### Features:
14+
1. **Project Setup** - Status: ⏸️ Pending
15+
- Acceptance Criteria:
16+
- Development environment configured
17+
- All dependencies installed and verified
18+
- Base tests passing
19+
- Core functionality implemented
20+
- QA Status: Not Started
21+
22+
2. **Development Workflow** - Status: ⏸️ Pending
23+
- Acceptance Criteria:
24+
- All agents and skills operational
25+
- Epic/feature workflow established
26+
- QA gates functioning
27+
- Documentation complete
28+
- QA Status: Not Started
29+
30+
3. **Quality Standards** - Status: ⏸️ Pending
31+
- Acceptance Criteria:
32+
- 100% test coverage achieved
33+
- All linting rules pass
34+
- Type checking with no errors
35+
- Performance benchmarks met
36+
- QA Status: Not Started
37+
38+
---
39+
40+
## Epic: Core Features
41+
**Status**: ⏸️ Pending
42+
**Business Value**: Implement the primary functionality that delivers value to users
43+
44+
### Features:
45+
1. **Core Feature 1** - Status: ⏸️ Pending
46+
- Acceptance Criteria:
47+
- [Define specific criteria based on project needs]
48+
- [Include measurable outcomes]
49+
- [Specify quality requirements]
50+
- QA Status: Not Started
51+
52+
2. **Core Feature 2** - Status: ⏸️ Pending
53+
- Acceptance Criteria:
54+
- [Define specific criteria based on project needs]
55+
- [Include measurable outcomes]
56+
- [Specify quality requirements]
57+
- QA Status: Not Started
58+
59+
---
60+
61+
## QA History
62+
63+
| Date | Feature | Epic | QA Result | Reviewer |
64+
|------|---------|------|-----------|----------|
65+
| YYYY-MM-DD | Initial Setup | Project Foundation | Approved | @setup-project |
66+
67+
---
68+
69+
## Notes
70+
71+
- Each feature must pass all QA gates before marked complete
72+
- Features automatically flow to the next upon completion
73+
- Epics complete when all contained features are done
74+
- Use `@developer /skill epic-workflow` to manage epic progression
75+
- Customize epics and features based on your specific project requirements

0 commit comments

Comments
 (0)