Skip to content

Commit af94435

Browse files
committed
fix(cli): preserve plain frontmatter output exactly
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 1df1ad3 commit af94435

2 files changed

Lines changed: 59 additions & 61 deletions

File tree

src/basic_memory/cli/commands/tool.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,20 @@ def _plain_search_results(result: dict[str, Any], query: str = "") -> None:
381381
print(f" {snippet}")
382382

383383

384-
def _plain_read_note(result: dict[str, Any]) -> None:
385-
"""Render read-note content faithfully: the note body, or the literal file.
384+
def _plain_read_note(result: dict[str, Any], *, include_frontmatter: bool = False) -> None:
385+
"""Render the note body for humans or the literal file for round-tripping.
386386
387387
Plain mode adds NO decoration: no header line, no synthesized frontmatter
388-
block, no placeholder for empty notes. Without --frontmatter the
389-
API returns the note body; with it, the literal file (frontmatter block
390-
included). Either is printed verbatim, trimmed only of the surrounding
391-
newline artifacts the API keeps from frontmatter stripping, so the output
392-
round-trips (e.g. ``read-note X --plain --frontmatter > note.md``).
388+
block, no placeholder for empty notes. Without --frontmatter, trim the
389+
surrounding newline artifacts left by the API's frontmatter removal. With
390+
--frontmatter, write the literal file exactly so redirection round-trips
391+
every boundary newline (e.g. ``read-note X --plain --frontmatter > note.md``).
393392
"""
394393
content = result.get("content", "")
394+
if include_frontmatter:
395+
sys.stdout.write(content)
396+
return
397+
395398
body = content.strip("\n") if content else ""
396399
if body:
397400
print(body)
@@ -672,7 +675,7 @@ def read_note(
672675
if mode == "json" or isinstance(result, str):
673676
_print_json(result)
674677
elif mode == "plain":
675-
_plain_read_note(result)
678+
_plain_read_note(result, include_frontmatter=include_frontmatter)
676679
else:
677680
_display_read_note(result, include_frontmatter=include_frontmatter)
678681
except ValueError as e:

0 commit comments

Comments
 (0)