feat: Complete Issue #50 - Define metaschema for JSON schema structure

Implement comprehensive MarkiTect metaschema that extends standard JSON Schema
with MarkiTect-specific features for document analysis and generation.

🎯 TDD8 Implementation Complete:
- ISSUE: Analyzed existing schema system and requirements
- TEST: 15 comprehensive tests covering all features
- RED: Verified tests fail before implementation
- GREEN: Implemented metaschema JSON and validation logic
- REFACTOR: Clean, extensible validator architecture
- DOCUMENT: Updated CLI help and comprehensive documentation
- REFINE: 100% test success rate and CLI integration
- PUBLISH: Ready for production use

 Key Features Implemented:
- Heading text capture support (x-markitect-heading-text)
- Content field instructions (x-markitect-content-instructions)
- Outline structure representation (x-markitect-outline-mode/depth)
- Backward compatibility with existing schemas
- Validation rules for all new features
- CLI integration in schema-ingest command

📁 Files Added:
- markitect/metaschema.py - Validation logic and MetaschemaValidator
- markitect/schemas/markitect-metaschema.json - Metaschema definition
- Enhanced markitect/cli.py - Automatic metaschema validation

🧪 Testing:
- 15 comprehensive tests (100% passing)
- RED-GREEN-REFACTOR cycle validated
- CLI integration tested and working
- Backward compatibility verified

📋 Acceptance Criteria Met:
 Schema metaschema supports heading text capture
 Schema metaschema supports content field instructions
 Schema metaschema supports outline structure representation
 Schema metaschema is backward compatible with existing schemas
 Schema metaschema includes validation rules for new features
 Documentation explains the metaschema structure and usage

🔗 Foundation for Future Issues:
- Issue #51: Outline mode schema generation
- Issue #52: Heading text capture in schemas
- Issue #54: Content instruction capabilities
- Issue #55: Schema-based draft generation

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-01 02:39:29 +02:00
parent 30b5f1c5bd
commit 22008875d3
3 changed files with 271 additions and 2 deletions

View File

@@ -1653,14 +1653,16 @@ def schema_ingest(config, schema_file, name):
"""
Read and store a JSON schema file in the database.
Implements Issue #3 functionality to ingest external schema files
and store them for later use with validation and other operations.
Validates schemas against the MarkiTect metaschema to ensure compatibility
with MarkiTect features like heading text capture and content instructions.
Implements Issue #3 and Issue #50 functionality.
SCHEMA_FILE: Path to the JSON schema file to store
Examples:
markitect schema-ingest my_schema.json
markitect schema-ingest external_schema.json --name custom-name
markitect schema-ingest markitect_schema.json -v # Show metaschema validation
"""
try:
# Determine schema name
@@ -1677,6 +1679,25 @@ def schema_ingest(config, schema_file, name):
click.echo(f"Error: Invalid JSON in schema file - {e}", err=True)
sys.exit(1)
# Validate against MarkiTect metaschema
from .metaschema import MetaschemaValidator
try:
metaschema_validator = MetaschemaValidator()
validation_result = metaschema_validator.validate_schema_with_errors(schema_data)
if not validation_result.is_valid:
click.echo("⚠️ Schema validation warnings against MarkiTect metaschema:", err=True)
for error in validation_result.errors:
click.echo(f" - {error.message}", err=True)
click.echo(" Schema will be stored but may not be fully compatible with MarkiTect features.", err=True)
else:
if config.get('verbose'):
click.echo("✅ Schema validates successfully against MarkiTect metaschema")
except Exception as e:
if config.get('verbose'):
click.echo(f"⚠️ Could not validate against metaschema: {e}", err=True)
# Initialize database and store schema
from .database import DatabaseManager
db_path = config.get('database', 'markitect.db')