Skip to content

Commit 82d6303

Browse files
groksrcclaude
authored andcommitted
fix(cli): plain read-note renders the payload faithfully, no decoration
Drop the synthesized title/permalink header and the (no content) placeholder: plain mode is the content verbatim (note body, or the literal file with --include-frontmatter). Decoration belongs to the Rich path. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
1 parent 6315201 commit 82d6303

2 files changed

Lines changed: 18 additions & 31 deletions

File tree

src/basic_memory/cli/commands/tool.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -381,28 +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], *, include_frontmatter: bool = False) -> None:
385-
"""Render read-note as a plain title/permalink header, optional frontmatter, then body."""
386-
title = result.get("title", "")
387-
permalink = result.get("permalink", "")
384+
def _plain_read_note(result: dict[str, Any]) -> None:
385+
"""Render read-note content faithfully: the note body, or the literal file.
386+
387+
Plain mode adds NO decoration: no header line, no synthesized frontmatter
388+
block, no placeholder for empty notes. Without --include-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 --include-frontmatter > note.md``).
393+
"""
388394
content = result.get("content", "")
389-
390-
# Trigger: --include-frontmatter makes the API return the literal file
391-
# (frontmatter block included) as content.
392-
# Why: plain mode should show that file verbatim -- the file's own
393-
# frontmatter already carries title/permalink, so a header line and a
394-
# synthesized key/value block would both duplicate it.
395-
# Outcome: with the flag, emit ONLY the file; without it, a title/permalink
396-
# header then the body, trimmed to keep the gap a single blank line.
397-
if not include_frontmatter:
398-
header = f"{title} [{permalink}]" if permalink else title
399-
print(header)
400-
print()
401395
body = content.strip("\n") if content else ""
402396
if body:
403397
print(body)
404-
else:
405-
print("(no content)")
406398

407399

408400
def _plain_build_context(result: dict[str, Any]) -> None:
@@ -677,7 +669,7 @@ def read_note(
677669
if mode == "json" or isinstance(result, str):
678670
_print_json(result)
679671
elif mode == "plain":
680-
_plain_read_note(result, include_frontmatter=include_frontmatter)
672+
_plain_read_note(result)
681673
else:
682674
_display_read_note(result, include_frontmatter=include_frontmatter)
683675
except ValueError as e:

tests/cli/test_cli_tool_rich_output.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -755,19 +755,14 @@ def test_search_notes_plain_empty(mock_mcp):
755755
return_value=READ_NOTE_RESULT,
756756
)
757757
def test_read_note_plain_output(mock_mcp):
758-
"""read-note --plain emits a header line and the raw markdown body."""
758+
"""read-note --plain emits the note body faithfully, with no decoration."""
759759
result = _tty_runner(["tool", "read-note", "test-note", "--plain"])
760760

761761
assert result.exit_code == 0, f"CLI failed: {result.output}"
762-
assert "Test Note [notes/test-note]" in result.output
763-
# Raw markdown body, not Rich-rendered
764-
assert "# Test Note" in result.output
765-
assert "hello world" in result.output
766-
# No frontmatter without the flag
767-
assert "tags:" not in result.output
768-
# Exactly one blank line between header and body: the payload's leading
769-
# newline (frontmatter-strip artifact) must not stack with the renderer's.
770-
assert "Test Note [notes/test-note]\n\n# Test Note" in result.output
762+
# No synthesized header line -- plain mode is the payload, faithfully.
763+
assert "[notes/test-note]" not in result.output
764+
# The body verbatim, trimmed of the API's frontmatter-strip newline artifact.
765+
assert result.output == "# Test Note\n\nhello world\n"
771766

772767

773768
@patch(
@@ -798,11 +793,11 @@ def test_read_note_plain_include_frontmatter(mock_mcp):
798793
return_value={"title": "", "permalink": "", "content": "", "frontmatter": {}},
799794
)
800795
def test_read_note_plain_empty_content(mock_mcp):
801-
"""read-note --plain handles empty content."""
796+
"""read-note --plain prints nothing for an empty note (no placeholder)."""
802797
result = _tty_runner(["tool", "read-note", "empty-note", "--plain"])
803798

804799
assert result.exit_code == 0, f"CLI failed: {result.output}"
805-
assert "(no content)" in result.output
800+
assert result.output == ""
806801

807802

808803
@patch(

0 commit comments

Comments
 (0)