feat: Implement Issue #55 - Schema-based draft generation with content instructions
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled

This implementation enhances the existing generate-stub command to utilize
content field instructions from schemas, providing guided document generation
with specific placeholder text instead of generic "TODO" messages.

## Key Features Added:

### Enhanced Schema-Based Generation
- Content instructions from schemas (x-markitect-content-instructions) are now used
- Schema reference metadata included in generated drafts for traceability
- Intelligent fallback to generic placeholders for schemas without instructions
- Full integration with existing generate-stub CLI command and options

### StubGenerator Enhancements
- New _extract_content_instruction_from_heading_schema method for instruction parsing
- Enhanced _get_placeholder_content method with schema-aware content generation
- Updated method signatures to support schema_file_path parameter throughout
- Robust handling of both content instruction and legacy schema formats

### CLI Integration
- Updated generate-stub command documentation with content instruction examples
- Enhanced help text explaining automatic content instruction usage
- Fixed output file generation to include schema references correctly
- Maintained full backward compatibility with existing usage patterns

### Technical Implementation
- Schema reference comments (<!-- Generated from schema: path -->) in generated drafts
- Content instruction text extracted from x-markitect-content-instructions fields
- Support for all instruction types (description, example, constraint, template)
- Integration with existing heading hierarchy and placeholder style systems

## Integration and Compatibility:
- Seamless integration with Issue #54 content field instructions
- Full backward compatibility with existing schemas and usage
- Works with outline mode schemas and heading text capture features
- Comprehensive error handling and graceful degradation

## Testing and Validation:
- Comprehensive test suite covering all acceptance criteria
- Integration tests with schema-generate → generate-stub workflow
- Validation of schema reference metadata and content instruction usage
- Backward compatibility testing with legacy schemas

This completes Issue #55 with full feature implementation, comprehensive testing,
and enhanced documentation for schema-based draft generation capabilities.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-01 08:41:28 +02:00
parent c89a26f6d4
commit 3034b90a0e
3 changed files with 730 additions and 15 deletions

View File

@@ -1984,7 +1984,9 @@ def generate_stub(config, schema_file, output, style, title):
Generate a markdown stub/template from a JSON schema.
Creates a markdown document with proper heading hierarchy and placeholder
content based on the structural definitions in the JSON schema.
content based on the structural definitions in the JSON schema. When schemas
include content instructions (x-markitect-content-instructions), the generated
stub will use specific guidance text instead of generic placeholders.
SCHEMA_FILE: Path to the JSON schema file
@@ -1992,6 +1994,19 @@ def generate_stub(config, schema_file, output, style, title):
markitect generate-stub blog_schema.json
markitect generate-stub schema.json --output template.md
markitect generate-stub schema.json --style detailed --title "My Document"
# Content instructions will be used automatically when present in schema
markitect generate-stub schema_with_instructions.json
Content Instructions:
When a schema contains x-markitect-content-instructions-enabled: true,
the generated stub will include specific content guidance from the schema
instead of generic "TODO" placeholders. This is especially useful with
schemas created using the --include-content-instructions option.
Schema Reference:
Generated stubs include a comment referencing the source schema file
for validation and traceability purposes.
"""
try:
if config.get('verbose'):
@@ -2009,7 +2024,7 @@ def generate_stub(config, schema_file, output, style, title):
schema = json.load(f)
stub_content = generator.generate_stub_from_schema(
schema, placeholder_style=style, title=title
schema, placeholder_style=style, title=title, schema_file_path=schema_file
)
# Mode-based output logic
@@ -2021,7 +2036,7 @@ def generate_stub(config, schema_file, output, style, title):
# Output to file or stdout
if output:
generator.generate_stub_to_file(schema, output, style, title)
generator.generate_stub_to_file(schema, output, style, title, schema_file)
click.echo(f"✅ Stub generated: {output}")
if config.get('verbose'):