Skip to content

Spec: starting work and administering a machine through the Console API #1768

Closed
6 of 6 issues completed

Description

@JacobStephens2

This was generated by AI during triage.

Spec C of four from the #1142 grilling (grilling, Q2.1 (c), ADR 0026). It's built on Spec A, the Console API (#1753), and absorbs #952 (a readable and writable User config in the Console). Spec B, the Fleet in the Console (#1142), runs alongside. Adding these controls to the Fleet view is a follow-up blocked by both Specs.

Problem Statement

After #1753, a Console's API and page can read everything and Stop or dismiss, but they can't start anything or change the machine. To start a Ticket run, run a Pass now instead of waiting for cron, kick off a Custom process, change a User config setting or update thirdshift, the Day shift still needs a shell on that machine. From a phone that's impractical. Across the Fleet it means an SSH session per machine. The User config can only be changed by editing the file or re-running setup, and there's no config command at all (#952).

Solution

The run and admin scopes from #1753 get their endpoints. With run, a client can start any Command the CLI can start: a Ticket run or Spec run on an issue with the shared options, an Architect run, Pickup run, Security run or Review run, a Custom process, a skill run, a Scoring run and the like. Each behaves exactly like the typed command, starts detached, and is recorded as started by the person or token that asked. With admin, a client can read and change the User config through a new thirdshift config command and its twins, and run update. The Console page gets matching controls for a signed-in person with those scopes: a "Start" form, "Run now" on each Pass, a User config page, and an "Update thirdshift" action. Issuing tokens, the sign-in list, address scopes, console install and setup stay CLI-only (ADR 0026).

User Stories

  1. As the Day shift, I want to start a Ticket run on an issue through the API, with the same shared options as the CLI (merge, email, harness, model, effort, base-fix, security review and fix), so that I can start work from anywhere.
  2. As the Day shift, I want an issue with sub-issues to start a Spec run through the API, as the CLI does, so that the API never behaves differently.
  3. As the Day shift, I want to run an Architect run, Pickup run or Security run now through the API, with their own options (base branch, focus, plan-only, order), so that I don't wait for cron.
  4. As the Day shift, I want a Pass started through the API to be skipped for the same reasons as one started by cron, Command limit included, so that the API can't pile up work cron wouldn't.
  5. As the Day shift, I want a Ticket run started through the API on an Issue URL always to run, as a typed command does, so that the API is a person's command, not a Pass.
  6. As the Day shift, I want to start a Review run on a pull request, or by author, through the API, so that reviews start remotely too.
  7. As the Day shift, I want to start a Custom process by name, with an issue or pull request, through the API, so that my own Processes are startable too.
  8. As the Day shift, I want to run a skill, a Scoring run, a triage of a Report (sent as text, not a file path), and the other Command-starting CLI commands through the API, so that nothing that starts work is CLI-only.
  9. As the Day shift, I want a started Command to run detached from the Console with a login environment, so that a Console restart or update doesn't end it.
  10. As the Day shift, I want the start call to return the new Command's name once its Command record exists, or the skip outcome if it was skipped first, so that I know at once what happened.
  11. As the Day shift, I want the started Command to appear in the Inbox like any other, so that I follow it the usual way.
  12. As the Day shift, I want the Activity log's start line to name who started it, for example "by from the Console on " or "by token ", so that remote starts are traceable.
  13. As the Day shift, I want every start written to the Console log, so that starts are audited with the other changes.
  14. As the machine's owner, I want a start to run only in one of this machine's known Launch directories, so that a token holder can't point thirdshift at an arbitrary folder.
  15. As the machine's owner, I want the known Launch directories to be those my thirdshift cron jobs already use, plus any I list in the User config, so that the usual repositories work with no setup.
  16. As a client, I want to name the repository (owner/name), and have the machine find its Launch directory, so that I don't need to know the machine's paths.
  17. As a client, I want the list of startable repositories and their Launch directories through the API, so that a start form can offer them.
  18. As a client, I want a start refused with a clear error when the repository has no known Launch directory, so that I know what to fix.
  19. As the Day shift, I want a "Start" form on the Console page, for a person with run, to start a Ticket run on an issue number or URL with the shared options, so that I can start work from my phone.
  20. As the Day shift, I want "Run now" next to each Pass on the cron jobs page, for a person with run, so that I can bring a Pass forward.
  21. As the Day shift, I want a confirm step before any start from the page, so that a stray tap doesn't spend a Harness subscription.
  22. As the Day shift, I want start controls hidden for a person without run, so that I'm never offered what will be refused.
  23. As the Day shift, I want a thirdshift config command that shows every User config setting with its value and default, so that I can read the config without opening the file (make user config readable and writeable on thirdshift console web ui #952).
  24. As the Day shift, I want thirdshift config <key> to show one setting and thirdshift config <key> <value> to set it, validated as setup validates, so that I can change one setting safely.
  25. As the Day shift, I want thirdshift config --json and its API twin, so that clients can read the config.
  26. As the Day shift, I want setting a value to keep the file's comments and layout, as setup and the console settings commands do, so that the file stays readable.
  27. As the machine's owner, I want config refused for the Console sign-in list and address scopes, so that the API can't widen anyone's access (ADR 0026).
  28. As the machine's owner, I want a secret never to appear in config output, so that the config page leaks nothing (the User config holds no secrets, and the Credentials stay unreadable through it).
  29. As the Day shift, I want a User config page in the Console, for a person with admin, that shows every setting and lets me change one, so that make user config readable and writeable on thirdshift console web ui #952 is done.
  30. As the Day shift, I want the User config page read-only for a person with read but not admin, so that make user config readable and writeable on thirdshift console web ui #952's read/write split holds.
  31. As the Day shift, I want every config change written to the Console log with old and new values, so that I can see who changed what.
  32. As the Day shift, I want update through the API, for admin, so that I can update a machine without a shell.
  33. As the Day shift, I want the update call to answer before the Console re-executes itself, then the Console to come back on the new version, so that the client isn't left hanging.
  34. As the Day shift, I want an "Update thirdshift" action on the page showing the current and latest versions, for a person with admin, so that I can see and act on updates.
  35. As the Day shift, I want a Theme imported through the API as JSON content, not a file path, so that console theme import has a twin.
  36. As the machine's owner, I want any CLI command that takes a local path to accept its content in the request instead, or stay CLI-only when it writes to a local path (such as logs --export), so that the API never reads or writes arbitrary files.
  37. As the machine's owner, I want console install, setup, tokens, the sign-in list and address scopes to have no API endpoint, so that the machine's shell stays the root of trust.
  38. As a client author, I want every new endpoint in the OpenAPI description with its scope and CLI twin, so that the API stays discoverable.
  39. As an agent working in this repository, I want the parity test to fail when a Command-starting or machine-changing CLI command has neither an API twin nor a listed exclusion, so that "everything the CLI can do" stays true as commands are added.

Implementation Decisions

  • Scopes. Every CLI command that starts a Command or a Harness session, or writes to GitHub, is run. Every one that changes the machine (the User config, update, Theme import, Eval data management) is admin. The route table declares each one, as Spec: the Console API, /api/v1 behind scoped tokens #1753 set up.

  • Exclusions are explicit. The parity test walks every CLI command. Each must have an API twin or appear on a short, reasoned exclusion list: token management, the sign-in list, address scopes, console install, setup, console password, and commands that write to a local path (logs --export). A new CLI command with neither fails the test.

  • Starting a Command. The endpoint takes the CLI command's arguments as structured JSON, with the repository named as owner/name in place of the current directory. The Console resolves the repository to a known Launch directory, then spawns the same thirdshift binary with those arguments in that directory: detached in its own session, with the account's login environment, output appended to the same log cron uses, so it outlives the Console. The response waits briefly (bounded, e.g. 30 seconds) for the Command record to appear, or for the process to exit with a skip, and returns the Command's name or the skip outcome. The Command decides everything else itself, exactly as when typed.

  • Who started it. The spawned Command is given the requester's identity (person and machine, or token holder) through its environment. Its Activity log start line names them alongside today's wording. A Command started from cron or a terminal is unchanged.

  • Known Launch directories. These are the directories this account's thirdshift cron jobs cd into, plus a launch_directories list in the User config, each resolved to its repository through its origin remote. An endpoint lists them. A start for any other repository is refused.

  • thirdshift config. This is a new CLI command (config, config <key>, config <key> <value>, --json) built on the existing User config document editing that setup and the console settings commands use, with the same validation and comment-preserving writes. It refuses the sign-in list and address scopes. Its API twins are a GET for the whole config and one setting, and a POST to set one setting.

  • update. The API twin runs the same update. It responds once the new binary is in place, then the Console re-executes itself as it already does after an update.

  • Content instead of paths. triage --file takes the Report's text, and console theme import takes the Theme's JSON, in the request body.

  • Page controls.

    • A Start form on the Inbox: repository (from the known list), issue number or URL, and the shared options, with a confirm step.
    • "Run now" for each Pass on the cron jobs page.
    • A User config page: every setting, its value and its default, editable with admin and read-only otherwise.
    • Update: current and latest version, and an Update action.

    All of these are hidden without the scope they need.

  • Auditing. Starts, config changes (with old and new values) and updates go in the Console log with who asked.

  • Docs. docs/guide.md documents starting work and administering a machine through the API and the page, plus thirdshift config. The hand-written site pages say the Console can start work where they say it can't (they echo ADR 0016's old "never starts work").

Testing Decisions

  • Good tests exercise external behaviour: the binary, HTTP, fake gh and fake Harnesses on PATH, fixture clones. Nothing reaches into the spawner or the config writer.

  • Seam 1, the Console over HTTP (tests/console.rs, with the repository's fake gh and fake Harness binaries). With a run token:

    • start a Ticket run in a fixture clone named by a fixture cron job, and see its Command record appear with the Activity log line naming the token holder;
    • start a Pass that's skipped for its Command limit and get the skip outcome;
    • see a repository with no known Launch directory refused;
    • see the started Command survive a Console restart.

    With an admin token:

    • read and set a User config value, with comments preserved, and see the sign-in list refused;
    • run update against the existing update test fixtures.

    Scope refusals for read and act tokens. Prior art: tests/console/stop.rs, the fakes used by the Run and Spec run tests, and the update and packaging tests.

  • Seam 2, the route-table parity test, extended to walk every CLI command and require an API twin or a listed exclusion (with a should-panic twin).

  • thirdshift config is tested through the binary, as tests/user_config.rs does.

  • Site browser tests cover the Start form's confirm step and the User config page being read-only for a read person.

Out of Scope

  • Start and admin controls on other machines' rows in the Fleet view. That's a follow-up Ticket blocked by Spec: the Fleet in the Console #1142 and this Spec.
  • Scheduling: the API starts a Command now, and never schedules one (ADR 0009). Editing cron jobs through the API is out too.
  • Token management, the sign-in list, address scopes, console install, setup and console password, permanently (ADR 0026).
  • Commands that write to a local path.
  • Streaming a started Command's output through the API. The client follows it through the existing views.

Further Notes

Sub-issues

Sub-issues

6 of 6 Issues completed
Loading 6 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions