Skip to content

Commit cab4bf1

Browse files
groksrcclaude
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 30c6721 commit cab4bf1

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
@@ -395,16 +395,17 @@ def _plain_read_note(result: dict[str, Any], *, include_frontmatter: bool = Fals
395395
permalink = result.get("permalink", "")
396396
content = result.get("content", "")
397397

398-
header = f"{title} [{permalink}]" if permalink else title
399-
print(header)
400-
401-
print()
402398
# Trigger: --include-frontmatter makes the API return the literal file
403399
# (frontmatter block included) as content.
404-
# Why: plain mode should show that file verbatim -- synthesizing a separate
405-
# key/value block would print the frontmatter twice.
406-
# Outcome: with the flag, the body IS the frontmatter view; either way trim
407-
# surrounding newlines so the header gap stays a single blank line.
400+
# Why: plain mode should show that file verbatim -- the file's own
401+
# frontmatter already carries title/permalink, so a header line and a
402+
# synthesized key/value block would both duplicate it.
403+
# Outcome: with the flag, emit ONLY the file; without it, a title/permalink
404+
# header then the body, trimmed to keep the gap a single blank line.
405+
if not include_frontmatter:
406+
header = f"{title} [{permalink}]" if permalink else title
407+
print(header)
408+
print()
408409
body = content.strip("\n") if content else ""
409410
if body:
410411
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)