Skip to content

Commit 6315201

Browse files
groksrcclaude
authored andcommitted
fix(cli): emit only the literal file for plain read-note with --include-frontmatter
The file's own frontmatter carries title/permalink, so the header line duplicated it. Plain without the flag keeps the header. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
1 parent f6558f7 commit 6315201

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/basic_memory/cli/commands/tool.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,17 @@ def _plain_read_note(result: dict[str, Any], *, include_frontmatter: bool = Fals
387387
permalink = result.get("permalink", "")
388388
content = result.get("content", "")
389389

390-
header = f"{title} [{permalink}]" if permalink else title
391-
print(header)
392-
393-
print()
394390
# Trigger: --include-frontmatter makes the API return the literal file
395391
# (frontmatter block included) as content.
396-
# Why: plain mode should show that file verbatim -- synthesizing a separate
397-
# key/value block would print the frontmatter twice.
398-
# Outcome: with the flag, the body IS the frontmatter view; either way trim
399-
# surrounding newlines so the header gap stays a single blank line.
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()
400401
body = content.strip("\n") if content else ""
401402
if body:
402403
print(body)

tests/cli/test_cli_tool_rich_output.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,11 @@ def test_read_note_plain_include_frontmatter(mock_mcp):
784784
result = _tty_runner(["tool", "read-note", "test-note", "--plain", "--include-frontmatter"])
785785

786786
assert result.exit_code == 0, f"CLI failed: {result.output}"
787-
# The literal file: fences and YAML lines exactly as stored
788-
assert "---\ntitle: Test Note\ntags:\n- test\n---" in result.output
787+
# ONLY the literal file: no header line, output starts at the fence
788+
assert "Test Note [notes/test-note]" not in result.output
789+
assert result.output.startswith("---\ntitle: Test Note\ntags:\n- test\n---")
789790
assert "hello world" in result.output
790-
# No duplicated frontmatter from a synthesized block
791+
# No duplicated frontmatter from a synthesized block or header
791792
assert result.output.count("title: Test Note") == 1
792793

793794

0 commit comments

Comments
 (0)