feat: Complete Issue #51 - Add outline mode to schema generation
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / security-scan (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 / test-summary (push) Has been cancelled

Implement comprehensive outline mode functionality for schema generation with:

• New CLI options: --mode outline, --depth parameter, --outfile alias
• Schema title format: "Schema from file.md" instead of "Schema for file.md"
• Metaschema extensions: x-markitect-outline-mode, x-markitect-outline-depth
• Depth control with validation (--depth must be >= 1)
• Parameter conflict detection and error handling
• Full backward compatibility with existing --max-depth option
• Comprehensive test coverage (10 new tests, all passing)
• Enhanced CLI help documentation with examples

Technical implementation:
- Extended SchemaGenerator.generate_schema_from_file() with mode/outline_depth parameters
- Updated CLI command with new options and parameter validation
- Maintained 100% compatibility with existing 493 tests
- Integrated with Issue #50 metaschema validation

Usage examples:
  markitect schema-generate --mode outline document.md
  markitect schema-generate --mode outline --depth 3 --outfile schema.json document.md

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-01 02:59:40 +02:00
parent 22008875d3
commit b5f510f9c7
3 changed files with 443 additions and 14 deletions

View File

@@ -1450,27 +1450,65 @@ def ast_stats(config, file_path, format):
@click.argument('file_path', type=click.Path(exists=True, path_type=Path))
@click.option('--max-depth', '-d', type=int, help='Maximum heading depth to include in schema')
@click.option('--output', '-o', type=click.Path(path_type=Path), help='Output file path (default: stdout)')
@click.option('--outfile', type=click.Path(path_type=Path), help='Output file path (alias for --output)')
@click.option('--format', 'output_format', type=click.Choice(['json', 'yaml']), default='json', help='Output 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)')
@pass_config
def generate_schema(config, file_path, max_depth, output, output_format):
def generate_schema(config, file_path, max_depth, output, outfile, output_format, mode, depth):
"""
Generate a JSON schema from a markdown file's AST structure.
FILE_PATH: Path to the markdown file to analyze
Example:
Examples:
markitect schema-generate document.md
markitect schema-generate document.md --max-depth 2
markitect schema-generate document.md --output schema.json
# Outline mode for structure-focused schemas
markitect schema-generate --mode outline document.md
markitect schema-generate --mode outline --depth 3 --outfile schema.json document.md
Modes:
Default: Standard schema generation with structural analysis
Outline: Structure-focused schema with heading text capture and metaschema extensions
"""
try:
# Handle parameter conflicts and defaults
if outfile and output:
click.echo("Error: Cannot specify both --output and --outfile", err=True)
sys.exit(1)
# Use outfile as output if specified
final_output = outfile or output
# Handle depth parameter for outline mode
if mode == 'outline':
if depth is not None and max_depth is not None:
click.echo("Error: Cannot specify both --depth and --max-depth with outline mode", err=True)
sys.exit(1)
final_depth = depth if depth is not None else max_depth
else:
final_depth = max_depth
# Validate depth parameter
if final_depth is not None and final_depth < 1:
click.echo("Invalid depth parameter: depth must be >= 1", err=True)
sys.exit(1)
# Initialize schema generator and associated files manager
generator = SchemaGenerator()
from .associated_files import AssociatedFilesManager
associated_files = AssociatedFilesManager()
# Generate schema
schema = generator.generate_schema_from_file(file_path, max_depth=max_depth)
# Generate schema with mode support
schema = generator.generate_schema_from_file(
file_path,
max_depth=final_depth,
mode=mode,
outline_depth=depth if mode == 'outline' else None
)
# Format output
if output_format == 'json':
@@ -1481,18 +1519,18 @@ def generate_schema(config, file_path, max_depth, output, output_format):
formatted_output = json.dumps(schema, indent=2, ensure_ascii=False)
# Mode-based output logic
if not output and should_use_associated_files():
if not final_output and should_use_associated_files():
# Interactive mode: use associated file path
from .associated_files import AssociatedFilesManager
associated_files = AssociatedFilesManager()
output = associated_files.get_associated_schema_path(file_path)
final_output = associated_files.get_associated_schema_path(file_path)
if config.get('verbose'):
click.echo(f"Interactive mode: using associated file path: {output}", err=True)
click.echo(f"Interactive mode: using associated file path: {final_output}", err=True)
# Write to output
if output:
output.write_text(formatted_output, encoding='utf-8')
click.echo(f"Schema written to: {output}")
if final_output:
final_output.write_text(formatted_output, encoding='utf-8')
click.echo(f"Schema written to: {final_output}")
# Show summary
properties = schema.get('properties', {})