Skip to content

fix: write_note preserves frontmatter fields in content - #84

Merged
phernandez merged 2 commits into
mainfrom
issues/47/save-frontmatter-on-write-note
Apr 6, 2025
Merged

fix: write_note preserves frontmatter fields in content#84
phernandez merged 2 commits into
mainfrom
issues/47/save-frontmatter-on-write-note

Conversation

@phernandez

@phernandez phernandez commented Apr 6, 2025

Copy link
Copy Markdown
Member

This PR enhances the write_note tool to preserve any frontmatter fields that already exist in the content being written. Previously when writing or updating a note, any frontmatter in the content would be removed and replaced with only the metadata provided in the entity_metadata field, causing user-specified frontmatter to be lost.

Fixes #47

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

claude: can you give a PR description?

@github-actions

github-actions Bot commented Apr 6, 2025

Copy link
Copy Markdown
Contributor

Based on my analysis of the PR, here's a comprehensive PR description:

Fix: write_note preserves frontmatter fields in content

Summary

This PR enhances the write_note tool to preserve any frontmatter fields that already exist in the content being written. Previously when writing or updating a note, any frontmatter in the content would be removed and replaced with only the metadata provided in the entity_metadata field, causing user-specified frontmatter to be lost.

Changes

  • Modified the schema_to_markdown function to parse frontmatter from the content
  • Added logic to merge frontmatter from content with entity metadata
  • Ensured entity metadata takes precedence in case of conflicts
  • Added comprehensive test case that verifies frontmatter preservation

Technical Details

  • Uses the existing parse_frontmatter function from file_utils.py
  • Maintains the existing precedence rules (entity metadata takes priority)
  • Preserves custom fields like version and author that users may include

Testing

Added a new test case test_write_note_preserves_content_frontmatter that verifies:

  • Frontmatter fields from content are preserved
  • Entity metadata is still correctly applied
  • The resulting note contains the merged frontmatter

Fixes

Resolves issue #47

@phernandez
phernandez merged commit 3f4d9e4 into main Apr 6, 2025
@phernandez
phernandez deleted the issues/47/save-frontmatter-on-write-note branch April 6, 2025 23:39
@phernandez phernandez removed this from basic-memory Apr 7, 2025
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.

write_note should preserve frontmatter passed in via content of note

1 participant