Repository navigation
Implement NodeBehavior trait system for extensible node types - #139
Merged
Merged
Conversation
This commit implements the complete NodeBehavior trait system for extensible node types in NodeSpace, enabling type-specific validation and processing while maintaining runtime polymorphism. ## Implementation Details ### Core Trait System - `NodeBehavior` trait with Send + Sync bounds for thread safety - Core methods: type_name(), validate(), can_have_children(), supports_markdown() - Optional methods: process_content(), default_metadata() - Comprehensive documentation with examples ### Error Handling - `ProcessingError` enum for content processing failures - Reuses existing `ValidationError` from models module - Full error context with descriptive messages ### Built-in Behaviors - `TextNodeBehavior` - Markdown-enabled text nodes - `TaskNodeBehavior` - Status-tracked task management - `DateNodeBehavior` - Deterministic YYYY-MM-DD date nodes ### Registry System - `NodeBehaviorRegistry` with HashMap<String, Arc<dyn NodeBehavior>> - Thread-safe concurrent access via Arc - Automatic registration of built-in behaviors - validate_node() for centralized validation - get_all_types() for behavior enumeration ### Test Coverage - 17 comprehensive unit tests - Thread safety verification - All validation edge cases covered - Doc tests for all public APIs - 100% of acceptance criteria tested ### Dependencies - Added regex = "1.0" for date validation ## Acceptance Criteria ✅ ✅ NodeBehavior trait defines clear contract for node type logic ✅ Registry supports registration and retrieval of behaviors ✅ Thread-safe implementation for concurrent access ✅ Validation method prevents invalid node states ✅ Content processing allows type-specific transformations ✅ Capability queries (can_have_children, supports_markdown, etc.) ✅ Error handling for unknown node types ✅ Plugin-ready architecture for external node types All tests passing: 48 tests (17 behavior-specific + 31 existing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Use OnceLock to compile date validation regex once at first use instead of recompiling on every validate() call. This eliminates unnecessary overhead in the validation hot path. Changes: - Add static DATE_PATTERN using OnceLock<regex::Regex> - Add get_date_pattern() helper for lazy initialization - Update DateNodeBehavior::validate() to use compiled regex - Remove unwrap() in favor of expect() with clear error message Performance impact: Eliminates repeated regex compilation for every date node validation, significantly reducing validation overhead. All tests passing (17/17 behavior tests, 48/48 total).
Add detailed documentation explaining the intended usage patterns: - Concurrent reads: Safe with Arc<NodeBehaviorRegistry> - Concurrent registration: Requires Arc<Mutex<NodeBehaviorRegistry>> - Typical pattern: Register at startup, read at runtime This clarifies that the registry itself is not internally synchronized and helps users understand when external synchronization is needed. Addresses optional follow-up item from code review.
Document when to use each ProcessingError variant with clear examples: - ProcessingFailed: General failures (service down, resource exhaustion) - InvalidFormat: Malformed input that cannot be parsed - TransformationError: Transformation logic failures after parsing Added rustdoc with: - Detailed variant usage guidelines with concrete examples - Code examples demonstrating each variant's intended use case - Inline documentation on each variant This helps future implementations choose the appropriate error type and maintains consistent error handling semantics across behaviors. Addresses optional follow-up item from code review.
malibio
added a commit
that referenced
this pull request
Feb 4, 2026
* Implement NodeBehavior trait system (addresses #100) This commit implements the complete NodeBehavior trait system for extensible node types in NodeSpace, enabling type-specific validation and processing while maintaining runtime polymorphism. ## Implementation Details ### Core Trait System - `NodeBehavior` trait with Send + Sync bounds for thread safety - Core methods: type_name(), validate(), can_have_children(), supports_markdown() - Optional methods: process_content(), default_metadata() - Comprehensive documentation with examples ### Error Handling - `ProcessingError` enum for content processing failures - Reuses existing `ValidationError` from models module - Full error context with descriptive messages ### Built-in Behaviors - `TextNodeBehavior` - Markdown-enabled text nodes - `TaskNodeBehavior` - Status-tracked task management - `DateNodeBehavior` - Deterministic YYYY-MM-DD date nodes ### Registry System - `NodeBehaviorRegistry` with HashMap<String, Arc<dyn NodeBehavior>> - Thread-safe concurrent access via Arc - Automatic registration of built-in behaviors - validate_node() for centralized validation - get_all_types() for behavior enumeration ### Test Coverage - 17 comprehensive unit tests - Thread safety verification - All validation edge cases covered - Doc tests for all public APIs - 100% of acceptance criteria tested ### Dependencies - Added regex = "1.0" for date validation ## Acceptance Criteria ✅ ✅ NodeBehavior trait defines clear contract for node type logic ✅ Registry supports registration and retrieval of behaviors ✅ Thread-safe implementation for concurrent access ✅ Validation method prevents invalid node states ✅ Content processing allows type-specific transformations ✅ Capability queries (can_have_children, supports_markdown, etc.) ✅ Error handling for unknown node types ✅ Plugin-ready architecture for external node types All tests passing: 48 tests (17 behavior-specific + 31 existing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * perf: optimize regex compilation in DateNodeBehavior validation Use OnceLock to compile date validation regex once at first use instead of recompiling on every validate() call. This eliminates unnecessary overhead in the validation hot path. Changes: - Add static DATE_PATTERN using OnceLock<regex::Regex> - Add get_date_pattern() helper for lazy initialization - Update DateNodeBehavior::validate() to use compiled regex - Remove unwrap() in favor of expect() with clear error message Performance impact: Eliminates repeated regex compilation for every date node validation, significantly reducing validation overhead. All tests passing (17/17 behavior tests, 48/48 total). * docs: clarify thread safety usage patterns for NodeBehaviorRegistry Add detailed documentation explaining the intended usage patterns: - Concurrent reads: Safe with Arc<NodeBehaviorRegistry> - Concurrent registration: Requires Arc<Mutex<NodeBehaviorRegistry>> - Typical pattern: Register at startup, read at runtime This clarifies that the registry itself is not internally synchronized and helps users understand when external synchronization is needed. Addresses optional follow-up item from code review. * docs: add comprehensive usage guidelines for ProcessingError variants Document when to use each ProcessingError variant with clear examples: - ProcessingFailed: General failures (service down, resource exhaustion) - InvalidFormat: Malformed input that cannot be parsed - TransformationError: Transformation logic failures after parsing Added rustdoc with: - Detailed variant usage guidelines with concrete examples - Code examples demonstrating each variant's intended use case - Inline documentation on each variant This helps future implementations choose the appropriate error type and maintains consistent error handling semantics across behaviors. Addresses optional follow-up item from code review. --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 5, 2026
* Implement NodeBehavior trait system (addresses #100) This commit implements the complete NodeBehavior trait system for extensible node types in NodeSpace, enabling type-specific validation and processing while maintaining runtime polymorphism. ## Implementation Details ### Core Trait System - `NodeBehavior` trait with Send + Sync bounds for thread safety - Core methods: type_name(), validate(), can_have_children(), supports_markdown() - Optional methods: process_content(), default_metadata() - Comprehensive documentation with examples ### Error Handling - `ProcessingError` enum for content processing failures - Reuses existing `ValidationError` from models module - Full error context with descriptive messages ### Built-in Behaviors - `TextNodeBehavior` - Markdown-enabled text nodes - `TaskNodeBehavior` - Status-tracked task management - `DateNodeBehavior` - Deterministic YYYY-MM-DD date nodes ### Registry System - `NodeBehaviorRegistry` with HashMap<String, Arc<dyn NodeBehavior>> - Thread-safe concurrent access via Arc - Automatic registration of built-in behaviors - validate_node() for centralized validation - get_all_types() for behavior enumeration ### Test Coverage - 17 comprehensive unit tests - Thread safety verification - All validation edge cases covered - Doc tests for all public APIs - 100% of acceptance criteria tested ### Dependencies - Added regex = "1.0" for date validation ## Acceptance Criteria ✅ ✅ NodeBehavior trait defines clear contract for node type logic ✅ Registry supports registration and retrieval of behaviors ✅ Thread-safe implementation for concurrent access ✅ Validation method prevents invalid node states ✅ Content processing allows type-specific transformations ✅ Capability queries (can_have_children, supports_markdown, etc.) ✅ Error handling for unknown node types ✅ Plugin-ready architecture for external node types All tests passing: 48 tests (17 behavior-specific + 31 existing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * perf: optimize regex compilation in DateNodeBehavior validation Use OnceLock to compile date validation regex once at first use instead of recompiling on every validate() call. This eliminates unnecessary overhead in the validation hot path. Changes: - Add static DATE_PATTERN using OnceLock<regex::Regex> - Add get_date_pattern() helper for lazy initialization - Update DateNodeBehavior::validate() to use compiled regex - Remove unwrap() in favor of expect() with clear error message Performance impact: Eliminates repeated regex compilation for every date node validation, significantly reducing validation overhead. All tests passing (17/17 behavior tests, 48/48 total). * docs: clarify thread safety usage patterns for NodeBehaviorRegistry Add detailed documentation explaining the intended usage patterns: - Concurrent reads: Safe with Arc<NodeBehaviorRegistry> - Concurrent registration: Requires Arc<Mutex<NodeBehaviorRegistry>> - Typical pattern: Register at startup, read at runtime This clarifies that the registry itself is not internally synchronized and helps users understand when external synchronization is needed. Addresses optional follow-up item from code review. * docs: add comprehensive usage guidelines for ProcessingError variants Document when to use each ProcessingError variant with clear examples: - ProcessingFailed: General failures (service down, resource exhaustion) - InvalidFormat: Malformed input that cannot be parsed - TransformationError: Transformation logic failures after parsing Added rustdoc with: - Detailed variant usage guidelines with concrete examples - Code examples demonstrating each variant's intended use case - Inline documentation on each variant This helps future implementations choose the appropriate error type and maintains consistent error handling semantics across behaviors. Addresses optional follow-up item from code review. --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 26, 2026
* Implement NodeBehavior trait system (addresses #100) This commit implements the complete NodeBehavior trait system for extensible node types in NodeSpace, enabling type-specific validation and processing while maintaining runtime polymorphism. ## Implementation Details ### Core Trait System - `NodeBehavior` trait with Send + Sync bounds for thread safety - Core methods: type_name(), validate(), can_have_children(), supports_markdown() - Optional methods: process_content(), default_metadata() - Comprehensive documentation with examples ### Error Handling - `ProcessingError` enum for content processing failures - Reuses existing `ValidationError` from models module - Full error context with descriptive messages ### Built-in Behaviors - `TextNodeBehavior` - Markdown-enabled text nodes - `TaskNodeBehavior` - Status-tracked task management - `DateNodeBehavior` - Deterministic YYYY-MM-DD date nodes ### Registry System - `NodeBehaviorRegistry` with HashMap<String, Arc<dyn NodeBehavior>> - Thread-safe concurrent access via Arc - Automatic registration of built-in behaviors - validate_node() for centralized validation - get_all_types() for behavior enumeration ### Test Coverage - 17 comprehensive unit tests - Thread safety verification - All validation edge cases covered - Doc tests for all public APIs - 100% of acceptance criteria tested ### Dependencies - Added regex = "1.0" for date validation ## Acceptance Criteria ✅ ✅ NodeBehavior trait defines clear contract for node type logic ✅ Registry supports registration and retrieval of behaviors ✅ Thread-safe implementation for concurrent access ✅ Validation method prevents invalid node states ✅ Content processing allows type-specific transformations ✅ Capability queries (can_have_children, supports_markdown, etc.) ✅ Error handling for unknown node types ✅ Plugin-ready architecture for external node types All tests passing: 48 tests (17 behavior-specific + 31 existing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * perf: optimize regex compilation in DateNodeBehavior validation Use OnceLock to compile date validation regex once at first use instead of recompiling on every validate() call. This eliminates unnecessary overhead in the validation hot path. Changes: - Add static DATE_PATTERN using OnceLock<regex::Regex> - Add get_date_pattern() helper for lazy initialization - Update DateNodeBehavior::validate() to use compiled regex - Remove unwrap() in favor of expect() with clear error message Performance impact: Eliminates repeated regex compilation for every date node validation, significantly reducing validation overhead. All tests passing (17/17 behavior tests, 48/48 total). * docs: clarify thread safety usage patterns for NodeBehaviorRegistry Add detailed documentation explaining the intended usage patterns: - Concurrent reads: Safe with Arc<NodeBehaviorRegistry> - Concurrent registration: Requires Arc<Mutex<NodeBehaviorRegistry>> - Typical pattern: Register at startup, read at runtime This clarifies that the registry itself is not internally synchronized and helps users understand when external synchronization is needed. Addresses optional follow-up item from code review. * docs: add comprehensive usage guidelines for ProcessingError variants Document when to use each ProcessingError variant with clear examples: - ProcessingFailed: General failures (service down, resource exhaustion) - InvalidFormat: Malformed input that cannot be parsed - TransformationError: Transformation logic failures after parsing Added rustdoc with: - Detailed variant usage guidelines with concrete examples - Code examples demonstrating each variant's intended use case - Inline documentation on each variant This helps future implementations choose the appropriate error type and maintains consistent error handling semantics across behaviors. Addresses optional follow-up item from code review. --------- Co-authored-by: Claude <[email protected]>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #100