Skip to content

Add index-based child operations and fix sibling chain integrity - #339

Merged
malibio merged 2 commits into
mainfrom
feature/issue-338-index-based-child-operations
Oct 23, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-338-index-based-child-operations

Conversation

@malibio

@malibio malibio commented Oct 23, 2025

Copy link
Copy Markdown
Collaborator

Closes #338

malibio and others added 2 commits October 23, 2025 21:18
## Critical Bug Fix
- Fix sibling chain integrity in delete_node() operation
- Previously, deleting a node left dangling before_sibling_id references
- Now properly updates next sibling to maintain chain integrity
- Added comprehensive tests for delete operations (middle, first, last, with children)

## New MCP Tools (Index-Based Operations)
- get_children: Get all children with 0-based indexes
- get_child_at_index: Get specific child by position
- insert_child_at_index: Insert child at specific position
- move_child_to_index: Reorder child within siblings
- get_node_tree: Get hierarchical tree structure with descendants

## Helper Functions
- get_children_ordered: Follow sibling chain to build ordered list
- ensure_parent_exists: Auto-create date nodes (YYYY-MM-DD format)
- is_valid_date_format: Validate date strings
- build_tree_node: Recursive tree builder with circular chain detection

## Date Node Auto-Creation
- Date nodes (YYYY-MM-DD) now auto-create when referenced as parent_id
- Example: insert_child_at_index(parent_id='2025-10-23', ...) automatically creates date container

## Tool Registration
- Updated tools.rs with routing for 5 new tools
- Added comprehensive JSON schemas following MCP 2024-11-05 spec
- Organized tools into logical sections (CRUD, Hierarchy, Markdown, Search)

## Initialize Response
- Added instructions about date nodes, node types, and hierarchy
- Helps AI agents understand virtual date containers and index-based operations

## Testing
- All existing tests pass (15 operation tests)
- Delete operation tests verify sibling chain integrity
- Quality checks pass (oxlint, clippy, prettier, svelte-check)

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

Co-Authored-By: Claude <[email protected]>
## Code Review Improvements Applied

### Performance Optimization
- Optimize get_children_ordered from O(n²) to O(n) using HashMap
- Added clear documentation explaining the constant-time lookup optimization

### Code Style
- Move chrono::NaiveDate import to top of nodes.rs file
- Remove inline use statement for cleaner code organization

### Comprehensive Test Coverage
Added 8 new integration tests for index-based operations:
- test_insert_child_at_index_with_date_auto_creation
- test_insert_child_at_index_with_invalid_date_format
- test_insert_child_at_index_with_non_date_invalid_parent
- test_move_child_to_index_beyond_sibling_count
- test_get_node_tree_with_max_depth_1
- test_get_child_at_index_out_of_bounds
- test_get_children_ordered_with_multiple_insertions
- test_get_node_tree_max_depth_validation

## Critical Bug Fixes Discovered

### Fixed reorder_node() Sibling Chain Integrity
- Previously: Moving a node could create circular chains or orphaned references
- Now: Properly fixes the sibling chain before moving (like delete_node does)
- Impact: Prevents data corruption during node reordering operations

### Fixed insert_child_at_index() Chain Integrity
- Previously: Inserting at specific positions created duplicate first nodes
- Now: Updates displaced node's before_sibling_id to maintain chain
- Impact: HashMap-based get_children_ordered now works correctly

## Quality Verification
- All quality checks pass (bun run quality:fix)
- All 1,286 tests pass (100% success rate)
- All 18 integration tests pass
- Zero lint suppressions added
- Code follows all project standards

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

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 47a21b0 into main Oct 23, 2025
@malibio
malibio deleted the feature/issue-338-index-based-child-operations branch October 23, 2025 22:25
malibio added a commit that referenced this pull request Feb 4, 2026
* Add index-based child operations and fix sibling chain integrity (#338)

## Critical Bug Fix
- Fix sibling chain integrity in delete_node() operation
- Previously, deleting a node left dangling before_sibling_id references
- Now properly updates next sibling to maintain chain integrity
- Added comprehensive tests for delete operations (middle, first, last, with children)

## New MCP Tools (Index-Based Operations)
- get_children: Get all children with 0-based indexes
- get_child_at_index: Get specific child by position
- insert_child_at_index: Insert child at specific position
- move_child_to_index: Reorder child within siblings
- get_node_tree: Get hierarchical tree structure with descendants

## Helper Functions
- get_children_ordered: Follow sibling chain to build ordered list
- ensure_parent_exists: Auto-create date nodes (YYYY-MM-DD format)
- is_valid_date_format: Validate date strings
- build_tree_node: Recursive tree builder with circular chain detection

## Date Node Auto-Creation
- Date nodes (YYYY-MM-DD) now auto-create when referenced as parent_id
- Example: insert_child_at_index(parent_id='2025-10-23', ...) automatically creates date container

## Tool Registration
- Updated tools.rs with routing for 5 new tools
- Added comprehensive JSON schemas following MCP 2024-11-05 spec
- Organized tools into logical sections (CRUD, Hierarchy, Markdown, Search)

## Initialize Response
- Added instructions about date nodes, node types, and hierarchy
- Helps AI agents understand virtual date containers and index-based operations

## Testing
- All existing tests pass (15 operation tests)
- Delete operation tests verify sibling chain integrity
- Quality checks pass (oxlint, clippy, prettier, svelte-check)

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

Co-Authored-By: Claude <[email protected]>

* refactor: Apply code review improvements and fix sibling chain bugs

## Code Review Improvements Applied

### Performance Optimization
- Optimize get_children_ordered from O(n²) to O(n) using HashMap
- Added clear documentation explaining the constant-time lookup optimization

### Code Style
- Move chrono::NaiveDate import to top of nodes.rs file
- Remove inline use statement for cleaner code organization

### Comprehensive Test Coverage
Added 8 new integration tests for index-based operations:
- test_insert_child_at_index_with_date_auto_creation
- test_insert_child_at_index_with_invalid_date_format
- test_insert_child_at_index_with_non_date_invalid_parent
- test_move_child_to_index_beyond_sibling_count
- test_get_node_tree_with_max_depth_1
- test_get_child_at_index_out_of_bounds
- test_get_children_ordered_with_multiple_insertions
- test_get_node_tree_max_depth_validation

## Critical Bug Fixes Discovered

### Fixed reorder_node() Sibling Chain Integrity
- Previously: Moving a node could create circular chains or orphaned references
- Now: Properly fixes the sibling chain before moving (like delete_node does)
- Impact: Prevents data corruption during node reordering operations

### Fixed insert_child_at_index() Chain Integrity
- Previously: Inserting at specific positions created duplicate first nodes
- Now: Updates displaced node's before_sibling_id to maintain chain
- Impact: HashMap-based get_children_ordered now works correctly

## Quality Verification
- All quality checks pass (bun run quality:fix)
- All 1,286 tests pass (100% success rate)
- All 18 integration tests pass
- Zero lint suppressions added
- Code follows all project standards

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Add index-based child operations and fix sibling chain integrity (#338)

## Critical Bug Fix
- Fix sibling chain integrity in delete_node() operation
- Previously, deleting a node left dangling before_sibling_id references
- Now properly updates next sibling to maintain chain integrity
- Added comprehensive tests for delete operations (middle, first, last, with children)

## New MCP Tools (Index-Based Operations)
- get_children: Get all children with 0-based indexes
- get_child_at_index: Get specific child by position
- insert_child_at_index: Insert child at specific position
- move_child_to_index: Reorder child within siblings
- get_node_tree: Get hierarchical tree structure with descendants

## Helper Functions
- get_children_ordered: Follow sibling chain to build ordered list
- ensure_parent_exists: Auto-create date nodes (YYYY-MM-DD format)
- is_valid_date_format: Validate date strings
- build_tree_node: Recursive tree builder with circular chain detection

## Date Node Auto-Creation
- Date nodes (YYYY-MM-DD) now auto-create when referenced as parent_id
- Example: insert_child_at_index(parent_id='2025-10-23', ...) automatically creates date container

## Tool Registration
- Updated tools.rs with routing for 5 new tools
- Added comprehensive JSON schemas following MCP 2024-11-05 spec
- Organized tools into logical sections (CRUD, Hierarchy, Markdown, Search)

## Initialize Response
- Added instructions about date nodes, node types, and hierarchy
- Helps AI agents understand virtual date containers and index-based operations

## Testing
- All existing tests pass (15 operation tests)
- Delete operation tests verify sibling chain integrity
- Quality checks pass (oxlint, clippy, prettier, svelte-check)

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

Co-Authored-By: Claude <[email protected]>

* refactor: Apply code review improvements and fix sibling chain bugs

## Code Review Improvements Applied

### Performance Optimization
- Optimize get_children_ordered from O(n²) to O(n) using HashMap
- Added clear documentation explaining the constant-time lookup optimization

### Code Style
- Move chrono::NaiveDate import to top of nodes.rs file
- Remove inline use statement for cleaner code organization

### Comprehensive Test Coverage
Added 8 new integration tests for index-based operations:
- test_insert_child_at_index_with_date_auto_creation
- test_insert_child_at_index_with_invalid_date_format
- test_insert_child_at_index_with_non_date_invalid_parent
- test_move_child_to_index_beyond_sibling_count
- test_get_node_tree_with_max_depth_1
- test_get_child_at_index_out_of_bounds
- test_get_children_ordered_with_multiple_insertions
- test_get_node_tree_max_depth_validation

## Critical Bug Fixes Discovered

### Fixed reorder_node() Sibling Chain Integrity
- Previously: Moving a node could create circular chains or orphaned references
- Now: Properly fixes the sibling chain before moving (like delete_node does)
- Impact: Prevents data corruption during node reordering operations

### Fixed insert_child_at_index() Chain Integrity
- Previously: Inserting at specific positions created duplicate first nodes
- Now: Updates displaced node's before_sibling_id to maintain chain
- Impact: HashMap-based get_children_ordered now works correctly

## Quality Verification
- All quality checks pass (bun run quality:fix)
- All 1,286 tests pass (100% success rate)
- All 18 integration tests pass
- Zero lint suppressions added
- Code follows all project standards

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Add index-based child operations and fix sibling chain integrity (#338)

## Critical Bug Fix
- Fix sibling chain integrity in delete_node() operation
- Previously, deleting a node left dangling before_sibling_id references
- Now properly updates next sibling to maintain chain integrity
- Added comprehensive tests for delete operations (middle, first, last, with children)

## New MCP Tools (Index-Based Operations)
- get_children: Get all children with 0-based indexes
- get_child_at_index: Get specific child by position
- insert_child_at_index: Insert child at specific position
- move_child_to_index: Reorder child within siblings
- get_node_tree: Get hierarchical tree structure with descendants

## Helper Functions
- get_children_ordered: Follow sibling chain to build ordered list
- ensure_parent_exists: Auto-create date nodes (YYYY-MM-DD format)
- is_valid_date_format: Validate date strings
- build_tree_node: Recursive tree builder with circular chain detection

## Date Node Auto-Creation
- Date nodes (YYYY-MM-DD) now auto-create when referenced as parent_id
- Example: insert_child_at_index(parent_id='2025-10-23', ...) automatically creates date container

## Tool Registration
- Updated tools.rs with routing for 5 new tools
- Added comprehensive JSON schemas following MCP 2024-11-05 spec
- Organized tools into logical sections (CRUD, Hierarchy, Markdown, Search)

## Initialize Response
- Added instructions about date nodes, node types, and hierarchy
- Helps AI agents understand virtual date containers and index-based operations

## Testing
- All existing tests pass (15 operation tests)
- Delete operation tests verify sibling chain integrity
- Quality checks pass (oxlint, clippy, prettier, svelte-check)

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

Co-Authored-By: Claude <[email protected]>

* refactor: Apply code review improvements and fix sibling chain bugs

## Code Review Improvements Applied

### Performance Optimization
- Optimize get_children_ordered from O(n²) to O(n) using HashMap
- Added clear documentation explaining the constant-time lookup optimization

### Code Style
- Move chrono::NaiveDate import to top of nodes.rs file
- Remove inline use statement for cleaner code organization

### Comprehensive Test Coverage
Added 8 new integration tests for index-based operations:
- test_insert_child_at_index_with_date_auto_creation
- test_insert_child_at_index_with_invalid_date_format
- test_insert_child_at_index_with_non_date_invalid_parent
- test_move_child_to_index_beyond_sibling_count
- test_get_node_tree_with_max_depth_1
- test_get_child_at_index_out_of_bounds
- test_get_children_ordered_with_multiple_insertions
- test_get_node_tree_max_depth_validation

## Critical Bug Fixes Discovered

### Fixed reorder_node() Sibling Chain Integrity
- Previously: Moving a node could create circular chains or orphaned references
- Now: Properly fixes the sibling chain before moving (like delete_node does)
- Impact: Prevents data corruption during node reordering operations

### Fixed insert_child_at_index() Chain Integrity
- Previously: Inserting at specific positions created duplicate first nodes
- Now: Updates displaced node's before_sibling_id to maintain chain
- Impact: HashMap-based get_children_ordered now works correctly

## Quality Verification
- All quality checks pass (bun run quality:fix)
- All 1,286 tests pass (100% success rate)
- All 18 integration tests pass
- Zero lint suppressions added
- Code follows all project standards

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

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add index-based child operations and fix sibling chain integrity

1 participant