MeshTools is a Rich+Questionary interactive / Typer-scriptable toolkit for tuning a MeshCore mesh over a serial companion device, with SQLite-logged runs and Plotly visualizations. Includes the skeleton (trace, info, history), TX-power optimization, and a MockDevice simulator (--mock). Device discovery & selection: - core/discovery.py: enumerate serial ports (pyserial), flag/sort likely LoRa hardware by USB vendor id, stable_id for replug-safe identity. - core/device_store.py: remember the last successfully connected device in <config_dir>/devices.json (independent of --db). - core/selection.py: non-interactive resolver (--port > profile > remembered > sole device > guidance error) for the CLI. - ui/device_picker.py + menu startup: interactive picker preselecting the remembered default; banner reflects the choice. - tools/devices.py: `meshtools devices` lists/marks attached devices. - AppContext resolves the port and records last-known-good on connect success. Fixes: - theme.py: force UTF-8 on stdout/stderr so glyphs don't crash legacy consoles. - connection.py: friendly message when meshcore is missing; pin meshcore>=2.3. - trace/tx-optimize: fall back to free-text target entry when the device reports no contacts (autocomplete requires non-empty choices). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""The ``history`` tool: browse logged tool executions from the database."""
|
|
|
|
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
|
|
|
|
_STATUS_STYLE = {"ok": "ok", "error": "err", "running": "warn"}
|
|
|
|
|
|
@register
|
|
class HistoryTool(Tool):
|
|
"""List recent runs recorded in the database (no device needed)."""
|
|
|
|
name = "history"
|
|
help = "Show recent tool executions and their outcomes."
|
|
category = "Data"
|
|
order = 10
|
|
|
|
async def run(self, ctx: AppContext, params: dict[str, Any]) -> ToolResult:
|
|
"""Render the most recent runs as a table.
|
|
|
|
Args:
|
|
ctx: Shared application context.
|
|
params: Optional ``limit`` (int) controlling row count.
|
|
|
|
Returns:
|
|
A :class:`ToolResult` noting how many runs were shown.
|
|
"""
|
|
limit = int(params.get("limit", 20))
|
|
runs = ctx.repo.list_runs(limit=limit)
|
|
|
|
table = Table(title=f"Recent runs (last {limit})", border_style="muted")
|
|
table.add_column("#", justify="right", style="muted")
|
|
table.add_column("Tool", style="brand")
|
|
table.add_column("Profile", style="muted")
|
|
table.add_column("Status")
|
|
table.add_column("Started")
|
|
for r in runs:
|
|
style = _STATUS_STYLE.get(r.status, "muted")
|
|
table.add_row(
|
|
str(r.id),
|
|
r.tool,
|
|
r.profile or "-",
|
|
f"[{style}]{r.status}[/{style}]",
|
|
r.started_at.replace("T", " ")[:19],
|
|
)
|
|
ctx.console.print(table)
|
|
return ToolResult(summary={"shown": len(runs)})
|
|
|
|
def register_cli(self, app: typer.Typer) -> None:
|
|
"""Register the ``history`` subcommand.
|
|
|
|
Args:
|
|
app: The Typer application.
|
|
"""
|
|
from ..cli import run_tool_command
|
|
|
|
@app.command(name=self.name, help=self.help)
|
|
def _history(
|
|
limit: int = typer.Option(20, "--limit", "-n", help="Number of runs to show."),
|
|
) -> None:
|
|
run_tool_command(self, {"limit": limit})
|