You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
write_note should preserve frontmatter passed in via content of note #47
The write_note tool currently ignores any frontmatter passed in via the content of the note. It should try to preserve it.
For example
{
`title`: `Custom Frontmatter Test`,
`folder`: `tests`,
`content`: `---
Status: In Progress
Priority: High
CustomField: TestValue
Version: 1.0
DueDate: 2025-04-30
---
# Custom Frontmatter Test
This is a test note to verify that custom frontmatter fields are preserved when updating notes.
- [task] Test frontmatter preservation #test #bug
- [note] This note has several custom fields (Status, Priority, CustomField, Version, DueDate)
`
}
will only contain the following frontmatter fields:
title: Custom Frontmatter Test
type: note
permalink: tests/custom-frontmatter-test
Based on my analysis of the issue and the codebase, here's what's happening with the frontmatter preservation problem:
Problem Analysis
When using the write_note tool with content that contains frontmatter, the custom frontmatter fields are being stripped out during processing. The issue is in how incoming content with frontmatter is handled:
In schema_to_markdown (markdown/utils.py lines 83-84), any frontmatter in the incoming content is detected and removed:
# if the content contains frontmatter, remove it and mergeifhas_frontmatter(content):
content=remove_frontmatter(content)
Then a new Post is created with only the standard fields (title, type, permalink) plus any metadata from entity_metadata:
For existing notes, the system correctly merges with existing frontmatter, but for new notes or when creating the initial Post object, it discards any frontmatter in the content.
Proposed Solution
The fix would require modifying the schema_to_markdown function in src/basic_memory/markdown/utils.py to parse and preserve frontmatter from the incoming content:
asyncdefschema_to_markdown(schema: Any) ->Post:
"""Convert schema to markdown Post object."""# Extract content and metadatacontent=schema.contentor""frontmatter_metadata=dict(schema.entity_metadataor {})
# Parse frontmatter from content if presentcontent_frontmatter= {}
ifhas_frontmatter(content):
content_frontmatter=parse_frontmatter(content)
content=remove_frontmatter(content)
# Merge content frontmatter with entity metadata# (entity_metadata takes precedence for conflicts)content_frontmatter.update(frontmatter_metadata)
frontmatter_metadata=content_frontmatter# Remove special fields for ordered frontmatterforfieldin ["type", "title", "permalink"]:
frontmatter_metadata.pop(field, None)
# Create Post with ordered fieldspost=Post(
content,
title=schema.title,
type=schema.entity_type,
permalink=schema.permalink,
**frontmatter_metadata,
)
returnpost
This change would:
Detect if the incoming content has frontmatter
Parse that frontmatter into a dictionary
Merge it with any entity_metadata that was passed separately
Use the merged metadata when creating the Post object
Verify the frontmatter fields are preserved in the saved file
Update the note with modified frontmatter
Verify all fields (original and updated) are present
The current issue happens because the write_note tool discards any frontmatter in the incoming content, rather than parsing and including it in the note's metadata.
Activity
phernandez commentedon Apr 6, 2025
claude: how can we fix this?
github-actions commentedon Apr 6, 2025
Claude Code Analysis
Based on my analysis of the issue and the codebase, here's what's happening with the frontmatter preservation problem:
Problem Analysis
When using the
write_notetool with content that contains frontmatter, the custom frontmatter fields are being stripped out during processing. The issue is in how incoming content with frontmatter is handled:In
schema_to_markdown(markdown/utils.py lines 83-84), any frontmatter in the incoming content is detected and removed:Then a new Post is created with only the standard fields (title, type, permalink) plus any metadata from
entity_metadata:For existing notes, the system correctly merges with existing frontmatter, but for new notes or when creating the initial Post object, it discards any frontmatter in the content.
Proposed Solution
The fix would require modifying the
schema_to_markdownfunction insrc/basic_memory/markdown/utils.pyto parse and preserve frontmatter from the incoming content:This change would:
Files to Modify
Only one file needs to be modified:
/home/runner/work/basic-memory/basic-memory/src/basic_memory/markdown/utils.pyTesting
A test could be added to verify this behavior:
The current issue happens because the write_note tool discards any frontmatter in the incoming content, rather than parsing and including it in the note's metadata.
🤖 Generated with Claude Code GitHub Action