Solar Dashboard - One CLI and doctor commands for agentic output

Early in the project I instructed the agent to codify any operational steps such as setup, configuration, status, diagnostics and remediation (for the expected types of challenges). I didn't want to remember every single technology, OS, framework or tool's commands. I also didn't want to remember the sequence of these commands, their attributes or any extra, optional checks that need to be performed before. I knew my memory would be stretched beyond comfortable.

Basically, I want infrastructure as code, as much as it is possible in this context.

A week into the project, operating solar-dash had become a memory test anyway.

The scripts kept arriving, some for the relay box, some for the forwarder, for the database sources and so on. Next to them sat the Python tools for Grafana, the scraper and the verification. Each of them was perfectly reasonable on its own. Together, they required me to remember things that were far too granular, and the link between the script and the task started to become unclear.

Another problem was that each command had a slightly different structure and mechanism, as each was responsible for different actions and concepts, and operated on different components and levels.

I needed some serious help.

One tool to rule them all

I wanted a command-line tool that becomes a single point of entry for most typical operations that had come up so far or were expected to.

I wanted a much more consistent and discoverable interface and a little bit of structure to help guide me towards the right command, parameters or values.

It will have traditional help built-in anyway. It will cover different contexts such as relay, forwarder, database, and more. It will handle secret plumbing with SOPS.

That's what the sd command promises.

It organizes operations into a hierarchy of subcommands. Depending on the operation, a subcommand may also require a target and extra options. For example, sd box doctor <box> checks a box (Raspberry Pi), while sd rollout <instance> runs a first ever deployment to a fresh homelab instance. Updates are a tad more granular, just dropping to component level, depending on what needs updating.

The setup of local environments and Raspberry Pi is much more opinionated and involved, so I'll skip the detail for brevity. To be fair, the part that changes most sits in the homelab, the box with the relay has run uninterrupted for the last two months with no tweaking, exactly as planned.

As an example, have a look at the invocation that installs the part of the product running outside of Raspberry Pi:

1sd rollout <instance>            # 1/5 forwarder (DB, schema, views, role passwords, build/push/deploy pod)
2                                 # 2/5 Grafana datasource configuration
3                                 # 3/5 Grafana dashboards
4                                 # 4/5 Grafana alerts 
5                                 # 5/5 end to end verification data are rendered in Grafana panels as expected 

For comparison, a common update of homelab components involves:

1sd sink schema <instance>               # schema + views (idempotent)
2
3sd forwarder deploy <instance>          # build, push, roll the forwarder pod
4
5sd grafana push <instance> --overwrite  # datasource, dashboards, alert group, then panel check

And even though this was enormously helpful, I still desired a smoother workflow.

CLI tools with autocomplete

CLI commands first and foremost need to be invokable in a definitive (final) shape. That's how they are used within scripts and other non-interactive contexts.

For interactive context, commands with multiple nesting levels and many arguments (like sd command) could employ the --help switch to help the user decide what option to pick for every level. However, it quickly becomes impractical and the workflow choppy.

In my experience, there were a few CLI tools that used autocomplete in such an interactive and inspiring way that I now cannot imagine using complex CLI without autocompletion. The autocomplete for docker and kubectl commands stuck in my head as particularly good, but also the autocomplete or even the interactive tooling for AWS and GCP (awscli and gcloud) was a nice upgrade from traditional CLI tools.

Claude implemented it, and again it did a great job. I would struggle without it now.

Easy diagnostics

You may have noticed the term doctor weaved into the CLI conversation.

With the rapidly growing volume of code (complexity), operator machine supporting Linux and Windows, product architecture spanning SBC and Kubernetes and product deployed into multiple environments I needed a painless method to diagnose and troubleshoot issues.

That's why I asked for a doctor. It is a command that will run a series of checks or tests to verify the functionality is healthy. For many of the items it will remind me of the most likely problem or even provide a command that is likely to be helpful as the next step.

Very importantly, the doctor tool is helping to steer the agent. As a quick and cheap, reliable and deterministic check of product's health it is often the first to raise awareness about breaking changes. It is not as thorough as a full suite of regression tests, it mainly targets the parts of the product that break most often or are expected to be flaky.

Most areas have their own specialized version:

1sd doctor self                   # health check of the local operator setup (shell, WSL interop., Python venv 
2                                 # and requirements, PATH/SOPS/.env setup, homelab reachability etc.)    
3sd box doctor <box>              # health check of the box (most likely a Raspberry Pi)
4sd doctor <instance>             # health check of the rest of the product (on a homelab instance)
5
6sd sink sources <instance>       # (optional) generate IDE data sources so that all environments' data 
7                                 # are conveniently accessible (prod via tunnel only)

There are well over 100 checks like that in the solar dash project.

Many of them I asked for right after a failure: whatever bit me once got a check. Doctor commands are good at proactively spotting recurring problems, and providing likely solutions.

It saved my skin endless times.


Other posts in solar-dash series