mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix(cli): render frontmatter and observations in Rich TTY output
- `_display_read_note`: render frontmatter key/value panel when present so `--include-frontmatter` is not silently dropped in the Rich path - `_display_build_context`: render ContextResult.observations under each primary node (category + truncated content) so interactive users see the same core facts as `--json` output; update subtitle to include count - Update BUILD_CONTEXT_RESULT fixture with real ObservationSummary shape (type/category/content/permalink/file_path/created_at) - Add test_read_note_rich_include_frontmatter asserting frontmatter keys appear - Add test_build_context_rich_renders_observations asserting category/content visible Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
This commit is contained in:
@@ -113,10 +113,11 @@ def _display_search_results(result: dict[str, Any], query: str = "") -> None:
|
||||
|
||||
|
||||
def _display_read_note(result: dict[str, Any]) -> None:
|
||||
"""Render read-note result: header panel + rendered Markdown content."""
|
||||
"""Render read-note result: header panel + optional frontmatter + rendered Markdown content."""
|
||||
title = result.get("title", "")
|
||||
permalink = result.get("permalink", "")
|
||||
content = result.get("content", "")
|
||||
frontmatter: dict[str, Any] = result.get("frontmatter") or {}
|
||||
|
||||
header = Text()
|
||||
header.append(title, style="bold cyan")
|
||||
@@ -125,6 +126,18 @@ def _display_read_note(result: dict[str, Any]) -> None:
|
||||
|
||||
console.print(Panel(header, expand=False))
|
||||
|
||||
# Trigger: --include-frontmatter was passed; the MCP tool populates "frontmatter".
|
||||
# Why: without rendering it here, the explicitly requested metadata is silently
|
||||
# dropped in the Rich path — users must also know to add --json to see it.
|
||||
# Outcome: print a dim key/value block above the content when frontmatter is present.
|
||||
if frontmatter:
|
||||
fm_table = Table(show_header=False, box=None, padding=(0, 1), expand=False)
|
||||
fm_table.add_column("key", style="dim")
|
||||
fm_table.add_column("value", style="dim")
|
||||
for key, value in frontmatter.items():
|
||||
fm_table.add_row(str(key), str(value))
|
||||
console.print(Panel(fm_table, title="[dim]frontmatter[/dim]", expand=False))
|
||||
|
||||
if content:
|
||||
console.print(Markdown(content))
|
||||
else:
|
||||
@@ -165,6 +178,24 @@ def _display_build_context(result: dict[str, Any]) -> None:
|
||||
primary_label = f"[dim]{p_type}[/dim] {primary_label}"
|
||||
primary_node = tree.add(primary_label)
|
||||
|
||||
# --- Observations as children (category + truncated content) ---
|
||||
# Trigger: ContextResult.observations exists in the JSON output but was
|
||||
# never rendered in the Rich path.
|
||||
# Why: users running interactively lost core entity facts (observations)
|
||||
# that the --json path exposes; the TTY view must be at least as
|
||||
# informative as the JSON view for the primary entity.
|
||||
# Outcome: each observation appears as a dim "[category] content" leaf
|
||||
# under its primary node, truncated at 120 chars.
|
||||
observations: list[dict[str, Any]] = list(context_result.get("observations", []))
|
||||
for obs in observations:
|
||||
category = obs.get("category", "")
|
||||
obs_content = obs.get("content", "")
|
||||
# Truncate long observations so the tree stays readable.
|
||||
if len(obs_content) > 120:
|
||||
obs_content = obs_content[:117] + "..."
|
||||
obs_label = f"[dim][{category}] {obs_content}[/dim]"
|
||||
primary_node.add(obs_label)
|
||||
|
||||
# --- Related items as children ---
|
||||
related: list[dict[str, Any]] = list(context_result.get("related_results", []))
|
||||
for rel_item in related:
|
||||
@@ -182,7 +213,8 @@ def _display_build_context(result: dict[str, Any]) -> None:
|
||||
|
||||
# Count total related items across all primary results.
|
||||
total_related = sum(len(cr.get("related_results", [])) for cr in context_items)
|
||||
subtitle = f"{len(context_items)} primary • {total_related} related"
|
||||
total_observations = sum(len(cr.get("observations", [])) for cr in context_items)
|
||||
subtitle = f"{len(context_items)} primary • {total_observations} observations • {total_related} related"
|
||||
console.print(Panel(tree, subtitle=subtitle, expand=False))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user