Skip to content

A registry of labs: --lab on every command, the one lab as the default, a picker among several (an agentlab.yaml in the current directory still wins) #120

Description

@teemow

Part of #119.

Problem

A lab is a directory — agentlab.yaml, certs/, state/ — and every command reads it from the current directory: config.Load reads config.File relative to it, caCertPath/tlsCertPath (certs.go), labKubeconfig() (kubeconfig.go) and some thirty other sites are cwd-relative. The binary does not know which labs exist on the machine, so list (#121) has nothing to list, and open, pods or logs from anywhere else fail with "no agentlab.yaml found". With one lab — the common case — the person still has to cd into it first.

Proposed solution

  • A registry under os.UserConfigDir()/agentlab/ (~/.config/agentlab/ on Linux, ~/Library/Application Support/agentlab/ on macOS; the sibling of the update check's cache directory): one entry per cluster name → the absolute lab directory. configure and up write or refresh the entry for their lab; reading prunes entries whose directory or agentlab.yaml is gone. down leaves the entry — the lab still exists as a directory, and list shows its cluster as not created.
  • One resolution order, in one place (loadConfig in main.go, so every command gets it): --lab <name> (a persistent flag on the root) → an agentlab.yaml in the current directory → the single registered lab → on a terminal a huh select among the registered labs (the form's accessible mode applies: ACCESSIBLE, --accessible) → off a terminal a refusal that names the labs and --lab. A --lab that is not registered is refused naming the registered ones. Commands that touch no lab (self-update, completion, help, and list itself) never resolve one.
  • The command then runs against that lab's directory. The smallest change that keeps the cwd-relative sites correct is to change into the lab directory before anything touches a path; a lab-directory root threaded through the package is the cleaner shape and can follow. Either way nothing moves and nothing is written outside the lab directory and the registry.
  • A name collision is refused. configure in a directory whose clusterName is registered to a different directory stops, naming both directories and asking for another clusterName — a second lab of that name would collide on the cluster and its ports anyway (today the discovery then treats the other lab's published ports as its own).
  • agentlab.yaml's clusterName is the lab's name everywhere: the registry, --lab, list, the picker.

Acceptance criteria

  • With one registered lab, agentlab pods and agentlab logs muster from an unrelated directory use it. With two, a terminal gets a picker and < /dev/null gets a refusal naming both labs and --lab; --lab <name> skips the picker.
  • In a lab directory the local agentlab.yaml is used without a question, whatever the registry says.
  • configure with a clusterName registered to another directory is refused naming both directories.
  • Entries whose directory has vanished are neither offered nor listed.
  • Unit tests cover the resolution order, the pruning and the refusal; the picker is driven like the form's tests (internal/forms, scripted keystrokes).
  • docs/cli.md's intro paragraph (today: "every command reads agentlab.yaml…") describes the order above and --lab.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions