Annotate our own device with its hash on the route line, the per-trace From→To table, and the per-hop medians table, truncated to the command's path-hash width like every other hop. Unify link rendering on _route_node_text so all three reads consistently as name (hash). In the info panel, replace the standalone node-hash line with a Nodes table: our node listed first with its name highlighted, and every node's full public key shown with its path-hash prefix highlighted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
67 lines
2.2 KiB
Python
67 lines
2.2 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 ..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
|
|
from ..ui.widgets import nodes_table
|
|
|
|
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)
|
|
|
|
# List our own node (first, highlighted) and contacts, each with its full key and
|
|
# the path-hash prefix — the slice a forced path addresses — highlighted.
|
|
mode = snapshot.get("path_hash_mode")
|
|
prefix_bytes = (mode + 1) if isinstance(mode, int) and 0 <= mode <= 3 else 0
|
|
self_name = str(snapshot.get("name") or "this node")
|
|
self_key = str(snapshot.get("public_key") or "")
|
|
ctx.console.print(nodes_table(self_name, self_key, contacts, prefix_bytes))
|
|
|
|
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, {})
|