Skip to content

Conversation

@ahmet-cetinkaya
Copy link
Contributor

@ahmet-cetinkaya ahmet-cetinkaya commented Oct 28, 2025

Summary

  • Add --spec-dir option to specify init command for custom specification directories
  • Implement comprehensive validation with helpful error messages and edge case handling
  • Update templates and scripts to support dynamic spec directory references
  • Maintain full backward compatibility with default specs/ directory

Description

This feature introduces significant flexibility to Spec Kit by allowing users to specify custom directory paths for their specifications instead of being limited to the default specs/ directory.

Key Features

  • Custom Directory Support: Use --spec-dir documentation, --spec-dir requirements, or any valid relative path
  • Robust Validation: Comprehensive validation prevents:
    • Absolute paths and parent directory traversal attacks
    • Invalid characters with detailed error messages
    • Reserved names (Windows/Unix compatibility)
    • Excessive path lengths and filesystem constraints
  • Unicode Support: Full international character support with proper validation
  • Template Integration: Automatic replacement of hardcoded specs/ references with custom directory names
  • Script Compatibility: Bash and PowerShell scripts support custom directories via SPECIFY_SPEC_DIR environment variable

Implementation Details

  • Core Changes: Enhanced validate_spec_dir() function and init command in src/specify_cli/__init__.py
  • Template Updates: Dynamic {SPEC_DIR} placeholder support in template files
  • Script Integration: Updated shell scripts with environment variable support
  • Comprehensive Testing: 38 tests covering validation, integration, and edge cases

Usage Examples

# Default specs/ directory (unchanged behavior)
specify init my-project

# Custom spec directory
specify init my-project --spec-dir docs/specs
specify init my-project --ai claude --spec-dir requirements
specify init --here --ai copilot --spec-dir docs/feature-specs

# Environment variable override
export SPECIFY_SPEC_DIR="docs/specs"
# Scripts automatically use the custom directory

Test Plan

  • CLI functionality verification with --help command
  • init command testing with various spec directory scenarios
  • check command functionality verification
  • Full test suite execution (38 passed, 1 skipped for Windows-specific test)
  • Code quality and syntax validation
  • Integration testing with edge cases and error handling

Test Coverage

  • Unit Tests: Spec directory validation with comprehensive edge cases
  • Integration Tests: CLI command testing with various scenarios
  • Template Processing: Reference update functionality testing
  • Error Handling: User-friendly error message validation

Impact

  • Breaking Changes: None - fully backward compatible
  • Migration: Existing projects continue working with default specs/ directory
  • Documentation: Updated README with examples and command documentation
  • Compatibility: Maintains compatibility with existing workflows and scripts

Files Changed

  • Core Implementation: src/specify_cli/__init__.py (+262 lines)
  • Templates: Update to support dynamic {SPEC_DIR} placeholder
  • Scripts: Bash and PowerShell integration with environment variable support
  • Tests: Comprehensive test suite with 38 tests (1,023 new lines of test code)
  • Documentation: Updated README and command templates

This enhancement represents a significant improvement to Spec Kit's flexibility while maintaining the robust specification-driven development workflow and ensuring excellent user experience through comprehensive validation and error handling.

Adds ability to specify custom spec directory via --spec-dir parameter in specify init command. Updates CLI help documentation, refactors bash and PowerShell scripts to support custom directories via SPECIFY_SPEC_DIR environment variable, updates templates to use {SPEC_DIR} placeholder instead of hardcoded "specs", and adds validation for custom directory paths. Maintains backward compatibility by defaulting to "specs" directory.
Introduce pytest-based testing framework with dependencies and comprehensive validation suite for the new --spec-dir capability:

- Add pytest and pytest-cov to project dependencies in pyproject.toml
- Create test fixtures and configuration in conftest.py for consistent test setup
- Implement 1100+ lines of test coverage across 5 specialized test modules
- Cover edge cases including path traversal prevention, character validation, and unicode handling
- Test both CLI integration and unit-level function validation
- Verify file reference updates and directory renaming behavior

The test infrastructure ensures reliability of the spec directory customization feature through thorough validation of input constraints, error handling, and functional correctness across multiple scenarios.
…ges and edge case handling

Enhance the spec directory validation system to provide better user experience and handle edge cases more robustly:

- Improved validation with detailed error messages and helpful tips
- Added support for Unicode characters in directory names
- Enhanced parent traversal and absolute path detection
- Added reserved Windows system name validation
- Better control character and invalid character detection
- More precise regex patterns in update_spec_directory_references function
- Consolidated test coverage in test_validate_spec_dir.py with comprehensive scenarios
- Removed redundant test file test_spec_dir_validation.py
- Minor improvements to helper function sourcing in bash/powershell scripts

These changes make validation more comprehensive while maintaining backward compatibility and providing clearer feedback to users when validation fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant