mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix(cli): route string tool results to JSON path to satisfy ty narrowing
MCP tools return str | dict depending on output_format; the Rich display helpers require the dict (or list) shape. String payloads keep main's behavior of printing through the JSON path. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
This commit is contained in:
@@ -181,9 +181,7 @@ def _display_build_context(result: dict[str, Any]) -> None:
|
||||
primary_node.add(" ".join(parts))
|
||||
|
||||
# Count total related items across all primary results.
|
||||
total_related = sum(
|
||||
len(cr.get("related_results", [])) for cr in context_items
|
||||
)
|
||||
total_related = sum(len(cr.get("related_results", [])) for cr in context_items)
|
||||
subtitle = f"{len(context_items)} primary • {total_related} related"
|
||||
console.print(Panel(tree, subtitle=subtitle, expand=False))
|
||||
|
||||
@@ -414,7 +412,7 @@ def read_note(
|
||||
# Why: scripts and downstream tools need parseable JSON; Rich markup
|
||||
# would corrupt those pipelines.
|
||||
# Outcome: raw JSON for machine consumers; formatted display for humans.
|
||||
if json_output or not _use_rich():
|
||||
if json_output or not _use_rich() or isinstance(result, str):
|
||||
_print_json(result)
|
||||
else:
|
||||
_display_read_note(result)
|
||||
@@ -627,7 +625,7 @@ def build_context(
|
||||
# Why: scripts and downstream tools need parseable JSON; Rich markup
|
||||
# would corrupt those pipelines.
|
||||
# Outcome: raw JSON for machine consumers; formatted display for humans.
|
||||
if json_output or not _use_rich():
|
||||
if json_output or not _use_rich() or isinstance(result, str):
|
||||
_print_json(result)
|
||||
else:
|
||||
_display_build_context(result)
|
||||
@@ -704,7 +702,7 @@ def recent_activity(
|
||||
# Why: scripts and downstream tools need parseable JSON; Rich markup
|
||||
# would corrupt those pipelines.
|
||||
# Outcome: raw JSON for machine consumers; formatted display for humans.
|
||||
if json_output or not _use_rich():
|
||||
if json_output or not _use_rich() or isinstance(result, str):
|
||||
_print_json(result)
|
||||
else:
|
||||
_display_recent_activity(result)
|
||||
|
||||
Reference in New Issue
Block a user