Skip to content

Commit a5114ae

Browse files
groksrcclaude
andcommitted
fix(cli): trim frontmatter-strip newlines in plain read-note body
The API content field keeps the blank line left by frontmatter stripping; plain print() rendered it as a double gap under the header. JSON mode stays byte-faithful. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
1 parent eedafd6 commit a5114ae

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/basic_memory/cli/commands/tool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@ def _plain_read_note(result: dict[str, Any], *, include_frontmatter: bool = Fals
401401
print(f"{key}: {value}")
402402

403403
print()
404-
if content:
405-
print(content)
404+
# The API's content field keeps the blank line left by frontmatter
405+
# stripping; trim newlines so the header gap stays a single blank line.
406+
body = content.strip("\n") if content else ""
407+
if body:
408+
print(body)
406409
else:
407410
print("(no content)")
408411

tests/cli/test_cli_tool_rich_output.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"title": "Test Note",
2424
"permalink": "notes/test-note",
2525
"file_path": "notes/Test Note.md",
26-
"content": "# Test Note\n\nhello world",
26+
# Real payloads keep the leading newline left by frontmatter stripping.
27+
"content": "\n# Test Note\n\nhello world",
2728
"frontmatter": {"title": "Test Note", "tags": ["test"]},
2829
}
2930

@@ -263,7 +264,9 @@ def test_read_note_json_flag_overrides_tty(mock_mcp):
263264
assert result.exit_code == 0, f"CLI failed: {result.output}"
264265
data = json.loads(result.output)
265266
assert data["title"] == "Test Note"
266-
assert data["content"] == "# Test Note\n\nhello world"
267+
# JSON mode is byte-faithful: the payload's leading newline (frontmatter-strip
268+
# artifact) is preserved here even though display modes trim it.
269+
assert data["content"] == "\n# Test Note\n\nhello world"
267270

268271

269272
@patch(
@@ -747,6 +750,9 @@ def test_read_note_plain_output(mock_mcp):
747750
assert "hello world" in result.output
748751
# No frontmatter without the flag
749752
assert "tags:" not in result.output
753+
# Exactly one blank line between header and body: the payload's leading
754+
# newline (frontmatter-strip artifact) must not stack with the renderer's.
755+
assert "Test Note [notes/test-note]\n\n# Test Note" in result.output
750756

751757

752758
@patch(

0 commit comments

Comments
 (0)