Skip to content

Spec Templates with Placeholders#173

Open
OBenner wants to merge 14 commits intodevelopfrom
auto-claude/200-spec-templates-with-placeholders
Open

Spec Templates with Placeholders#173
OBenner wants to merge 14 commits intodevelopfrom
auto-claude/200-spec-templates-with-placeholders

Conversation

@OBenner
Copy link
Copy Markdown
Owner

@OBenner OBenner commented Mar 23, 2026

Template system for common spec patterns (add authentication, create API endpoint, setup database) with user-friendly placeholders for project-specific values.

Test User and others added 14 commits March 20, 2026 12:49
Implemented PlaceholderParser class with comprehensive functionality:
- extract_placeholders(): Extracts {{PLACEHOLDER}} syntax from text
- validate_values(): Validates placeholder values are present and non-empty
- replace(): Replaces placeholders with provided values
- Additional utility methods for placeholder info and suggestions
- Supports common placeholders: PROJECT_NAME, AUTHOR, VERSION, etc.
- Full validation with proper error handling

Subtask: subtask-1-1 - Create placeholder parser and validator

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add placeholders field to Template.__init__() and get_placeholders() method.
Supports both explicit placeholder lists and auto-extraction from template content.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Import PlaceholderParser from placeholders module
- Initialize parser in SpecGenerator.__init__
- Add _replace_placeholders_in_content method for recursive replacement
- Apply placeholder replacement in generate_spec after template generation
- Handle strings, dicts, and lists recursively
- Gracefully handle missing placeholders

Subtask: subtask-1-3
Implemented comprehensive spec template validator that validates:
- Template structure, parameters, and placeholders
- Content safety to prevent injection attacks
- Import validation for external template sources

Follows patterns from agent template validator.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add validate() method to TemplateLibrary wrapping validator
- Add validation to save_custom_template() before saving
- Add validation to create_spec_from_template() before generation
- Import validate_template from validator module
- Add logging for validation errors

Subtask: subtask-2-2
Add io.py module for importing/exporting spec templates to/from JSON format.
Includes CustomTemplate class for dynamic templates and helper functions for
file-based import/export.

Implements subtask-3-1.
Adds import/export functionality to TemplateLibrary class:
- export_template() - export template to dict
- import_template_data() - import template from dict
- export_template_file() - export template to JSON file
- import_template_file() - import template from JSON file
- Updated save_custom_template() to use io module
- Updated _load_custom_templates() to use io module

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added three new CLI commands for spec template management:
- validate_template_command: Validates spec templates for security and correctness
- export_template_command: Exports templates to JSON format
- import_template_command: Imports templates from JSON files

Implements subtask-4-1 of spec 200.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implements prompt_for_template_parameters() function that:
- Collects template parameters interactively from user
- Shows parameter descriptions, types, defaults
- Validates input types (str, int, bool, list)
- Handles required vs optional parameters
- Provides user-friendly prompts and error messages

Follows patterns from cli/input_handlers.py for consistent UX.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Create test suite for PlaceholderParser class (subtask-5-1)
- Cover extraction, validation, replacement, and utility methods
- Include edge cases: unicode, special chars, adjacent placeholders
- All 65 tests passing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added test suite for spec template import/export functionality:

- Export tests: template serialization to JSON with all fields
- Import tests: template deserialization from JSON with validation
- Round-trip tests: verify data preservation through export/import cycle
- Parameter serialization/deserialization: type conversion tests
- File-based import/export: file handling and error cases
- TemplateLibrary integration: library methods for import/export
- CustomTemplate tests: custom template class functionality
- Edge cases: unicode, special characters, complex data structures

54 tests covering all import/export scenarios including:
- Basic template fields (name, description, category)
- Placeholders preservation
- Parameter type serialization (str, int, bool, list, dict, float)
- Template content for CustomTemplate instances
- Validation during import via TemplateLibrary
- File operations with error handling
- Export version compatibility

Subtask: subtask-5-3

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…PI templates

- Added PROJECT_NAME and ORGANIZATION placeholders to AuthenticationTemplate
- Added PROJECT_NAME placeholder to CrudApiTemplate
- Placeholders embedded in description and rationale fields
- Follows placeholder pattern from placeholders.py module

Subtask: subtask-5-4
Fixes:
- Test coverage validation blocked due to pywin32 import error

Resolution:
- Verified pywin32 is installed and working (version 311)
- Confirmed pytest-cov can measure coverage without ImportError
- All 207 tests pass successfully with coverage measurement

Coverage Results:
- Overall module coverage: 59%
- NEW code coverage: 90-100% (placeholders: 100%, io: 100%, validator: 90%)
- Coverage report generated successfully

Context:
The overall 59% coverage includes pre-existing untested code in the spec templates
module (library.py, generator.py, registry.py, built-in templates). The NEW code
created for this spec has excellent coverage with 207 comprehensive tests.

The pywin32 dependency issue blocking coverage measurement is resolved.

Verified:
- pytest-cov runs without ImportError ✓
- Coverage report shows percentage for each module ✓
- All 207 unit tests pass ✓
- NEW code has 90-100% coverage ✓

QA Fix Session: 1

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Warning

Rate limit exceeded

@OBenner has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7dd7e0c0-a552-48d0-a50a-200c8e23b4ce

📥 Commits

Reviewing files that changed from the base of the PR and between aa0d6f5 and 8587279.

📒 Files selected for processing (14)
  • apps/backend/cli/spec_commands.py
  • apps/backend/spec/templates/builtin/authentication.py
  • apps/backend/spec/templates/builtin/crud_api.py
  • apps/backend/spec/templates/generator.py
  • apps/backend/spec/templates/io.py
  • apps/backend/spec/templates/library.py
  • apps/backend/spec/templates/placeholders.py
  • apps/backend/spec/templates/registry.py
  • apps/backend/spec/templates/validator.py
  • coverage_analysis.txt
  • coverage_output.txt
  • tests/test_spec_templates_import_export.py
  • tests/test_spec_templates_placeholders.py
  • tests/test_spec_templates_validation.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auto-claude/200-spec-templates-with-placeholders

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

sys.path.insert(0, str(_PARENT_DIR))

from progress import count_subtasks
from ui import Icons, box, icon, muted, print_status

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'box' is not used.

Copilot Autofix

AI 22 days ago

To fix an unused import, remove only the unused symbol from the import statement, keeping the rest of the imports intact. This eliminates the unnecessary dependency without affecting existing functionality.

In this file, the best fix is to edit apps/backend/cli/spec_commands.py at the import line currently reading from ui import Icons, box, icon, muted, print_status and remove box from the imported names. The rest of the file does not need changes, since removing an unused import does not alter behavior. No new methods, imports, or definitions are required; we are only simplifying an existing import.

Suggested changeset 1
apps/backend/cli/spec_commands.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/backend/cli/spec_commands.py b/apps/backend/cli/spec_commands.py
--- a/apps/backend/cli/spec_commands.py
+++ b/apps/backend/cli/spec_commands.py
@@ -16,7 +16,7 @@
     sys.path.insert(0, str(_PARENT_DIR))
 
 from progress import count_subtasks
-from ui import Icons, box, icon, muted, print_status
+from ui import Icons, icon, muted, print_status
 from workspace import get_existing_build_worktree
 
 from .utils import get_specs_dir
EOF
@@ -16,7 +16,7 @@
sys.path.insert(0, str(_PARENT_DIR))

from progress import count_subtasks
from ui import Icons, box, icon, muted, print_status
from ui import Icons, icon, muted, print_status
from workspace import get_existing_build_worktree

from .utils import get_specs_dir
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants