Watch a connector in a terminal, and talk to its orchestrator

Merged
RO
21d ago
+3669-26

What this does

basecamp connect console -P <profile> opens a full-screen view of a profile's connector in the terminal, with four screens:

  • Activity. The orchestrator while it takes its turn, the workers running, waiting and done, the requests held for a person, and the latest requests the connector heard. A row opens in full, and o opens its recording in the browser.

  • Health. The connector's process, the checks basecamp connect doctor runs, and each supported coding agent's CLI with the version it answers.

  • Settings. Who does the work, the runner.json rules, Pings, who may give the agent work and the projects served, as they are on disk. Read-only in this PR.

  • Talk. The whole conversation with the orchestrator, for as long as the console is open.

A line at the bottom takes what the person types to the orchestrator, the way basecamp connect say does, and the end of its answer shows under whichever screen is open.

connect stays hidden, so the console is hidden with it. No existing command, flag or output changes.

Why

Seeing what a connector is doing today means reading its log lines or running status, doctor and workers list in turn. The console puts those in one place that updates as the connector works. A terminal view needs no port, link or token, which a web page would.

How it is put together

  • internal/connector/console (new). The Bubble Tea model, its view and the snapshot types. It is given functions to read a snapshot, run the health checks, talk to the orchestrator and open an address, so its tests run on stand-ins.
  • internal/commands/connect_console.go (new). Reads the snapshot from the same places connect status does: connect.json, the instance lock, the ledger, the runner's state file, and the runner's socket for what is live.
  • connect doctor. Its checks move into connectDoctorChecks, which doctor and the console both call. Doctor's output is unchanged.
  • Runner. Read-only helpers: ReadActivity for the state file and InstalledAgents, which runs each adapter's CLI with --version and nothing else.
  • The skill. A few lines saying the person can run the console in a terminal of their own.

Worth a reviewer's attention

  • It is a separate process that only reads, apart from the talk line. It runs beside a connector, before one starts and after one stops, and closing it leaves the connector as it was. It listens on nothing.
  • What it draws is not trusted. A recording's title and a worker's report are stripped of terminal control sequences before they are drawn, and o opens only an https:// address.
  • A connector started without an orchestrator shows as "Listening · no orchestrator", and the Activity screen gives the command that starts one that does the work. The console tells this from whether the runner's socket answers, because a start does not record it. It does not record --project narrowing either, so the console cannot show that.
  • What a refresh costs. The console reads its state about once a second, so each read has to stay cheap as a ledger grows. The hold, connection and held records come from a new light read, Ledger.Glance, not the full status. The latest requests are read off each state's index, and the search among discarded records stops 10,000 back: on a month-old ledger of a busy account (137,000 records) that read went from 72 ms to 12 ms. A request closed longer ago than that reach is not listed under "Heard".
  • The launcher rule. console.Run is the package's one Bubble Tea launcher, is listed in internal/tui/launchers_test.go, and refuses without a terminal on both standard input and output.

Verified

  • bin/ci on this branch, again after the review fixes and with main merged in.
  • The rewritten latest-requests query returns the same 30 rows as the one it replaces on a real ledger of 137,000 records.
  • A narrow window (44 columns) beside the running connector: rows keep the worker's name.
  • On Linux, beside a real profile's running connector: the three screens against a connector running with an orchestrator, and against one started without, including the health checks, the installed CLIs' versions and rows for real finished workers.
  • A worker as it runs: two small workers were dispatched on that connector, and each showed under "Working now" within about a second, with the tool it was running and a timer, then moved to "Done". The orchestrator's turn that followed showed on its own line.
  • The talk line against a live orchestrator, by the connector's owner.

Not verified

  • Most of the review fixes in a live console (a long answer on the Talk screen, the narrow-window layouts, following a state directory that moves): they are covered by tests. The four screens were opened once more beside the running connector after the fixes.

  • The cap on workers as a running connector reports it: the connector available was started on an older build, which does not report one.

  • Watching a connector come up from a stopped state, which is covered only by the model's tests on stand-ins.

  • macOS.