cli

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

README

internal/cli

The loom workspace, loom account and loom session subcommands, and the client half of loom reset: clients of the loom daemon. Each joins it as the TUI's startup join does, makes its request, prints the answer and exits. core imports cmd, so cmd cannot import the wire; these commands live here and main.go attaches them (rootCmd.AddCommand(cli.WorkspaceCmd), cli.AccountCmd, cli.SessionCmd), with workspace migrate (cmd.MigrateCmd, direct under the lock) added under the workspace command.

Files

File Holds
join.go Join (the join seam main.go sets to joinCLI), withDaemon, client (events, await, awaitReply, awaitStart, request; ctx, which ends a wait), accountWait
workspace.go WorkspaceCmd and add, list, remove, use, rename, status; client.resolveWorkspace, client.served
session.go SessionCmd (built by newSessionCmd) and list, new, kill, pause, resume; findSession, client.launchOptions, sessionJSON (the --json row)
account.go AccountCmd and add, login, list, use, sync, remove; the environment guards and credential warnings
reset.go Reset, the client half of loom reset while a daemon runs

How a command runs

withDaemon calls Join, which starts the daemon when none runs (the newer build wins, replaceGuard applies), runs the command's function over the client and closes it. The client keeps a replica of the daemon's published state, so a read (Registry, Workspaces, Views, AccountUsage) is answered locally and only a request crosses the wire. The notices the daemon gives the connection are written to stderr, except one naming the command's own request, which the command gets instead (events) and reports with the request's outcome.

Command Request or read
workspace add Register
workspace list ReloadRegistry, then Registry
workspace remove Unregister
workspace use SetLastUsed
workspace rename RenameWorkspace
workspace status ReloadRegistry, then Workspaces and Views
account add AddAccount, then claude auth login in the command's terminal unless --no-login
account login claude auth login, then a refresh of the daemon's auth
account list RequestUsageProbe and a wait, then the published accounts and usage
account use SetDefaultAccount
account sync RequestAccountsRefresh, then a wait for each account's AccountSync report
account remove RemoveAccount (with force for --force)
reset (Reset) Reset, then a wait for its Reply
session list ReloadRegistry, then Views
session new ReloadRegistry, ReloadAccounts, then Create and a wait for its Started or its notices (awaitStart)
session kill, pause, resume ReloadRegistry, then Kill, Pause or Resume and a wait for its Reply (request)

A command waits for a round the daemon runs by its data, not by the next event, for up to accountWait; a request with a ReqID waits for its Reply. The daemon probes usage only once an extra account exists, so account list with only the default account shows no usage.

Tests

The commands run against a daemon served in process (serveDaemon, daemon_test.go): Join returns an in-process client over a booted model, and a test asserts the model's state after the request, not the files. testmain_test.go isolates the loom dirs and the Claude config dir. workspace_test.go, account_test.go, reset_test.go and session_test.go hold the commands' tests; the session tests that start sessions run the daemon on a private real tmux server (serveDaemonLive) with a fake claude (fakeAgent) in a committed repository (liveWorkspace); e2e/clients_test.go runs them against real builds.

Documentation

Overview

Package cli holds the `loom workspace` and `loom account` subcommands, which are clients of the loom daemon (daemon stage 3C+4), and the daemon half of `loom reset` (Reset).

Each command joins the daemon as the TUI does (Join, which main sets: the daemon is started when none runs, the newer build wins, and a loom inside loom never replaces it), makes its request, prints the answer and exits. The daemon owns the workspace and account registries while it runs, so every change goes through it and it serves the result at once: a workspace added is served, one removed is unloaded, one renamed keeps its ID. What a command reads of its own environment (the shell's CLAUDE_CONFIG_DIR, a credential override, the working directory) stays its own, and `account login` runs Claude's interactive login in its own terminal. `workspace migrate` is the exception: it lives in cmd and writes state.json directly, under the lock.

Index

Constants

This section is empty.

Variables

View Source
var AccountCmd = &cobra.Command{
	Use:   "account",
	Short: "Manage the Claude accounts sessions can run on",
}

AccountCmd is the parent command for Claude account management. Its commands are clients of the daemon, which creates, removes, links and probes the accounts; each reads its registry from disk only for the guards on its own environment (guardAgainstAccountEnv) and remove's checks before its prompt.

View Source
var Join func() (*rpc.Client, error)

Join connects to the loom daemon, starting one when none runs, as the TUI's startup join does: the newer build wins (an older daemon is replaced, a newer one refuses this loom), and the client uses the daemon's tmux server from then on. main sets it; tests serve a model in process.

View Source
var SessionCmd = newSessionCmd()

SessionCmd is `loom session`: create, list and drive the sessions of a registered workspace, as clients of the daemon. main attaches it.

View Source
var WorkspaceCmd = &cobra.Command{
	Use:   "workspace",
	Short: "Manage workspaces",
}

WorkspaceCmd is the parent command for workspace management. main attaches `migrate` (cmd.MigrateCmd) to it.

Functions

func Reset

func Reset(c *cobra.Command, out io.Writer, name string) error

Reset has the daemon reset the workspace registered as name ("" the global one), as `loom reset --force` does while a daemon serves the global dir, waits for the reset to finish (its Reply) and says so on out. The daemon drops the workspace's sessions at once, then deletes their records, kills the tmux sessions started in its roots and removes its worktrees and their branches; it refuses while one of them is busy, and for a workspace whose sessions failed to load.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL