Repository navigation
Closed
Description
Overview
The create_nodes_from_markdown MCP method incorrectly nests same-level headers under each other instead of making them siblings under their parent. For example, multiple H2 headers should all be children of the H1, but currently H2[2] is a child of H2[1], H2[3] is a child of H2[2], etc.
Current (Incorrect) Structure
From database after MCP import:
Container: # Product Launch Campaign Strategy (H1)
id: 482fbcf2-916b-48ec-b8db-37cc8a383196
parent_id: NULL
container_node_id: NULL
├─ text: "This comprehensive product launch..."
│ parent_id: 482fbcf2... (CORRECT - child of container)
│
├─ ## Launch Overview (H2)
│ id: 7839aca9...
│ parent_id: 482fbcf2... (CORRECT - child of H1)
│
└─ ## Executive Summary (H2) ❌ WRONG
id: 25be8813...
parent_id: 7839aca9... (WRONG - should be 482fbcf2, not previous H2!)
└─ ## Target Audience Analysis (H2) ❌ WRONG
id: 08f0b97c...
parent_id: 25be8813... (WRONG - should be 482fbcf2!)
└─ ### Primary Target Segment (H3) ✅ CORRECT
parent_id: 08f0b97c... (CORRECT - child of H2)
Problem
Same-level headers are being nested sequentially instead of as siblings:
- H2[1] → child of H1 ✅
- H2[2] → child of H2[1] ❌ (should be child of H1)
- H2[3] → child of H2[2] ❌ (should be child of H1)
Expected behavior:
- All H2 headers should be siblings, all children of the H1 parent
- H3 headers should be children of their preceding H2
- H4 headers should be children of their preceding H3
Expected (Correct) Structure
Container: # Product Launch Campaign Strategy (H1)
├─ text: "This comprehensive..."
├─ ## Launch Overview (H2)
│ ├─ text: (any content under Launch Overview)
│ └─ ### Subsection (H3) - if exists
├─ ## Executive Summary (H2)
│ ├─ text: (any content under Executive Summary)
│ └─ ### Subsection (H3) - if exists
└─ ## Target Audience Analysis (H2)
├─ text: (any content)
└─ ### Primary Target Segment (H3)
└─ text: demographic info
Investigation Required
Need to analyze the heading hierarchy tracking in parse_markdown() function:
File: packages/core/src/mcp/handlers/markdown.rs
Suspected Issue:
heading_stacklogic might not be popping correctly- When seeing same-level heading (e.g., H2 after H2), should pop to parent (H1)
- Currently seems to be keeping previous H2 as parent
Key Code Section:
The heading_stack management around line 300-450 in markdown.rs handles heading hierarchy. Need to verify:
- When H2 is encountered after H2, does it pop back to H1?
- When H3 is encountered after H2, does it correctly use H2 as parent?
- When H2 is encountered after H3, does it pop back to H1?
Acceptance Criteria
- Same-level headers are siblings (same parent)
- H2 headers all have H1 as parent
- H3 headers have their preceding H2 as parent
- H4 headers have their preceding H3 as parent
- Test with multiple H2s, nested H3s, back to H2, etc.
- Verify with the Product Launch document structure
- All 116 nodes have correct parent relationships
Technical Specifications
Reference Files
- Markdown Parser:
packages/core/src/mcp/handlers/markdown.rs - Test Database:
/Users/malibio/.nodespace/database/nodespace.db
Current Database State
Total nodes: 116
- Container: 482fbcf2-916b-48ec-b8db-37cc8a383196 (H1)
- Headers: 20 nodes
- Text: 89 nodes
- Date: 1 node (2025-10-24)
Query to see current structure:
SELECT id, node_type, parent_id, SUBSTR(content, 1, 50)
FROM nodes
WHERE container_node_id = '482fbcf2-916b-48ec-b8db-37cc8a383196'
OR id = '482fbcf2-916b-48ec-b8db-37cc8a383196'
ORDER BY created_at;Example Incorrect Parent Relationships
- H1 Container:
482fbcf2...parent: NULL ✅ - H2 "Launch Overview":
7839aca9...parent:482fbcf2...✅ - H2 "Executive Summary":
25be8813...parent:7839aca9...❌ (should be482fbcf2...) - H2 "Target Audience":
08f0b97c...parent:25be8813...❌ (should be482fbcf2...)
Definition of Done
- Heading hierarchy logic fixed in markdown parser
- Test import creates correct parent-child relationships
- Same-level headers are siblings
- Nested headers have correct parent
- Product Launch document re-imported with correct structure
- All tests pass
- Code review completed
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix: Correct heading hierarchy in markdown parser (issue #350)
fix: Correct heading hierarchy in markdown parser (issue #350)
fix: Rewrite markdown parser with line-by-line approach (issue #350)
fix: Implement required markdown parser corrections (issue #350)
fix: Preserve bullet prefixes in markdown import/export (issue #350)
fix: Prevent bullets from nesting sequentially (issue #350)
fix: Format ordered lists with '1. ' prefix on each line (issue #350)
fix: Prevent bullets from updating last_text_node (issue #350)
fix: Strip bullet prefixes during import, restore during export (issue …
fix: Bullet link detection and ordered list/indented bullet hierarchy…
fix: Support indented bullets and improve ordered list parent detecti…
refactor: Improve markdown parser quality and maintainability (issue #…
Fix create_nodes_from_markdown hierarchy: Same-level headers incorrec…
Improve: Address code review feedback with tests and documentation
Improve: Address code review feedback with tests and documentation
Fix create_nodes_from_markdown hierarchy: Same-level headers incorrec…
Improve: Address code review feedback with tests and documentation
Fix create_nodes_from_markdown hierarchy: Same-level headers incorrec…
Improve: Address code review feedback with tests and documentation
Fix create_nodes_from_markdown hierarchy: Same-level headers incorrec…