Documentation
¶
Overview ¶
Package cmd holds `loom workspace migrate` and the subprocess seam the rest of Loom shells out through.
MigrateCmd (workspace_migrate.go), which main.go attaches under the workspace command (internal/cli), moves instances from the global state.json into the config dirs of their matching workspaces. It writes state.json directly, holding the global dir's lock (StateWriteGuard), rather than asking the daemon as the other workspace and account subcommands do: those live in internal/cli, since core imports this package and cannot be imported back. migrate decodes records into its own typed mirror of session.InstanceData; workspace_migrate_shape_test.go guards that mirror against schema drift.
The subprocess seam is Executor, re-exported from internal/exec so callers that shell out (git operations, tmux calls, the claude command lookup) can be unit-tested against a fake executor without spawning real subprocesses. The production implementation is internal/exec.Default, aliased here as Exec and returned by MakeExecutor; tests supply a recorder or cmd/cmd_test.MockCmdExec that returns scripted output. Build git and gh commands with internal/exec.GitCommand/GhCommand and tmux commands with session/tmux.Command (tests enforce both), then run them through an Executor rather than calling exec.Command directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MigrateCmd = &cobra.Command{ Use: "migrate", Short: "Move global instances to their matching workspace directories", RunE: func(cmd *cobra.Command, args []string) error { if StateWriteGuard != nil { release, err := StateWriteGuard() if err != nil { return err } defer release() } globalDir, err := config.GetGlobalConfigDir() if err != nil { return err } reg, err := config.LoadWorkspaceRegistry() if err != nil { return err } if len(reg.Workspaces) == 0 { return fmt.Errorf("no workspaces registered — register workspaces first with 'workspace add'") } plan, err := planMigration(globalDir, reg) if err != nil { return err } if plan == nil { fmt.Println("No instances to migrate.") return nil } if migrateDryRun { fmt.Println("Dry run — no files will be modified.") plan.printPlan(os.Stdout) return nil } plan.printPlan(os.Stdout) migrated, err := plan.apply(reg, migrateBackup) if err != nil { return fmt.Errorf("migration failed after migrating %d instance(s): %w", migrated, err) } fmt.Printf("Migration complete. %d instance(s) migrated, %d remain in global storage.\n", migrated, len(plan.unmatchedData)) return nil }, }
MigrateCmd is `loom workspace migrate`, which main attaches under the workspace command. It writes state.json directly, under the lock (StateWriteGuard), rather than through the daemon.
var StateWriteGuard func() (release func(), err error)
StateWriteGuard is run, when set, before a command that writes a workspace's state.json itself (workspace migrate): it holds the global dir's lock for the command, which then calls release, and its error refuses the command. main sets it to take the lock the daemon holds, so the command refuses while the daemon serves the global dir (it would overwrite what the command wrote) and no daemon starts meanwhile; cmd cannot take it itself (the daemon's package imports this one).
Functions ¶
Types ¶
type Exec ¶
type Exec = internalexec.Default
Exec is the production implementation, aliased from internal/exec.Default.
type Executor ¶
type Executor = internalexec.Executor
Executor is re-exported from internal/exec so session/git and cmd share the same interface without either importing the other (cmd imports session/git already).