Files
MeshTerm/meshtools/tools/info.py
T
Jean-Pierre MartineauandClaude Opus 4.8 421781f13d Fix auto-path traces, harden contacts retrieval, add device config tooling
Trace:
- Auto-path now ends every route at the target's own hash (verified on
  hardware: a trace only replies when its destination is the final hop), so
  direct neighbors and learned multi-hop routes both resolve correctly.
- Retry the transient "no event received during contacts retrieval" blip and
  surface a clean DeviceCommandError instead of a raw traceback.
- Route summary annotates each node with its hash at the command's path-hash
  width, wrapping after an arrow when the line is too long.
- Default trace count changed from 5 to 3.

Also includes the in-progress device-config feature (config_io, device_config,
config tool, config editor UI, tests) and related supporting edits.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 11:19:21 -04:00

67 lines
2.0 KiB
Python

"""The ``info`` tool: show the connected companion device's identity and contacts."""
from __future__ import annotations
from typing import Any
import typer
from rich.table import Table
from ..context import AppContext
from .base import Tool, ToolResult, register
@register
class InfoTool(Tool):
"""Display device identity, radio configuration, and known contacts."""
name = "info"
help = "Show device identity, radio config, and contacts."
category = "Device"
order = 10
async def run(self, ctx: AppContext, params: dict[str, Any]) -> ToolResult:
"""Query the device and render its full configuration and contacts.
Args:
ctx: Shared application context.
params: Unused.
Returns:
A :class:`ToolResult` summarizing device name and contact count.
"""
from ..core.device_config import build_snapshot
from ..ui.config_editor import render_config
device = await ctx.device()
snapshot = await build_snapshot(device)
custom = await device.get_custom_vars()
contacts = await device.get_contacts()
# Render every current setting with a short explanation of each.
render_config(ctx.console, snapshot, custom)
if contacts:
ctable = Table(title=f"Contacts ({len(contacts)})", border_style="muted")
ctable.add_column("Name", style="brand")
ctable.add_column("Key prefix", style="muted")
for c in contacts:
ctable.add_row(c.name, c.key_prefix or "[muted]?[/muted]")
ctx.console.print(ctable)
return ToolResult(
summary={"name": snapshot.get("name"), "contacts": len(contacts)},
)
def register_cli(self, app: typer.Typer) -> None:
"""Register the ``info`` subcommand.
Args:
app: The Typer application.
"""
from ..cli import run_tool_command
@app.command(name=self.name, help=self.help)
def _info() -> None:
run_tool_command(self, {})