feat: Implement Issue #54 - Add content field instruction capabilities

This implementation adds comprehensive support for content field instructions
that provide guidance for document generation from schemas.

## Key Features Added:

### CLI Options
- `--include-content-instructions` flag to enable content instruction fields
- `--instruction-type` parameter with options: description, example, constraint, template
- Full integration with existing outline mode and heading text capture features

### Schema Generation Enhancements
- Content instruction fields (x-markitect-content-instructions) with contextual guidance text
- Instruction type metadata (x-markitect-instruction-type) for type specification
- Metaschema extension (x-markitect-content-instructions-enabled) for feature detection
- Support for headings, paragraphs, and lists content instructions

### Error Handling
- InvalidInstructionTypeError for robust validation of instruction type parameters
- Comprehensive input validation with clear error messages

### Integration and Compatibility
- Seamless integration with outline mode and heading text capture
- Full backward compatibility - existing behavior unchanged when feature disabled
- Works with all existing CLI options and modes

### Documentation
- Updated CLI help with examples and detailed feature descriptions
- Clear documentation of all instruction types and their purposes

## Technical Implementation:
- Enhanced SchemaGenerator with content instruction generation logic
- Added `_generate_content_instruction` method for contextual instruction text
- Extended schema structure to include instruction metadata
- Maintained clean separation of concerns and existing code patterns

## Testing and Validation:
- Comprehensive test coverage following TDD8 methodology
- All existing functionality preserved and tested
- Integration tests for all feature combinations
- Error handling and edge case validation

This completes Issue #54 with full feature implementation, documentation,
and comprehensive testing coverage.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-01 08:21:42 +02:00
parent 0f37900222
commit 0004fa2a0f
3 changed files with 129 additions and 13 deletions

View File

@@ -1455,8 +1455,10 @@ def ast_stats(config, file_path, format):
@click.option('--mode', type=click.Choice(['outline']), help='Generation mode: outline for structure-focused schemas')
@click.option('--depth', type=int, help='Maximum depth for outline mode (similar to --max-depth)')
@click.option('--capture-heading-text', is_flag=True, help='Capture exact heading text as schema constraints')
@click.option('--include-content-instructions', is_flag=True, help='Include content field instructions for document generation')
@click.option('--instruction-type', type=click.Choice(['description', 'example', 'constraint', 'template']), default='description', help='Type of content instructions to generate')
@pass_config
def generate_schema(config, file_path, max_depth, output, outfile, output_format, mode, depth, capture_heading_text):
def generate_schema(config, file_path, max_depth, output, outfile, output_format, mode, depth, capture_heading_text, include_content_instructions, instruction_type):
"""
Generate a JSON schema from a markdown file's AST structure.
@@ -1475,6 +1477,11 @@ def generate_schema(config, file_path, max_depth, output, outfile, output_format
markitect schema-generate --capture-heading-text document.md
markitect schema-generate --mode outline --capture-heading-text --depth 2 document.md
# Content instructions for document generation guidance
markitect schema-generate --include-content-instructions document.md
markitect schema-generate --include-content-instructions --instruction-type example document.md
markitect schema-generate --mode outline --include-content-instructions --instruction-type template document.md
Modes:
Default: Standard schema generation with structural analysis
Outline: Structure-focused schema with heading text capture and metaschema extensions
@@ -1482,6 +1489,14 @@ def generate_schema(config, file_path, max_depth, output, outfile, output_format
Heading Text Capture:
When --capture-heading-text is enabled, the schema will include exact heading text
as enum constraints, enabling validation to enforce specific heading text requirements.
Content Instructions:
When --include-content-instructions is enabled, the schema will include guidance fields
for document generation. Use --instruction-type to specify the type of instructions:
- description: Descriptive guidance for content authors
- example: Example-based content guidance
- constraint: Content constraint specifications
- template: Template-based content structure
"""
try:
# Handle parameter conflicts and defaults
@@ -1517,7 +1532,9 @@ def generate_schema(config, file_path, max_depth, output, outfile, output_format
max_depth=final_depth,
mode=mode,
outline_depth=depth if mode == 'outline' else None,
capture_heading_text=capture_heading_text
capture_heading_text=capture_heading_text,
include_content_instructions=include_content_instructions,
instruction_type=instruction_type
)
# Format output