Documentation
¶
Overview ¶
Package core is loom's session model: the loaded workspaces and their instances, and everything that acts on them without a terminal: loading and saving, reconcile and the sweeps, the lifecycle operations and their completions, the health tick and the background jobs.
Since daemon stage 1E the model runs on a goroutine of its own: a Loop owns it, serves every Core method as a round trip over that goroutine, starts the Jobs the model queues on goroutines of their own and delivers their results on the loop (Deliver), and fires the health tick from its own timer. A Job reads no model state. The model reports to its client (the TUI, package app) through Events, which the client drains (Sync) when the loop wakes it (Loop.Wakes) and after each of its own messages. Core's own tests drive a Model directly, on their own goroutine, with Sync, Drain and Deliver.
core imports nothing of the TUI (TestCoreImportsNoUI): the daemon (loom serve) runs it with no terminal. Focus is the TUI's: where an operation needs "the workspace the user is looking at", the caller passes it.
Index ¶
- Constants
- Variables
- func AccountsRefreshedForTest(defaultAuth *session.RemoteControlAuth, ...) any
- func CausedForTest(req ReqID, result any) any
- func CheckNewTitle(title string, ws WorkspaceView) error
- func CheckPreservedTitle(title string, ws WorkspaceView) error
- func CheckRoom(rows int) error
- func CheckWritable(ws WorkspaceView) error
- func ChooseLaunchAccount(c Core, opts launch.Options, program string) (launch.Options, string)
- func FetchedIssueForTest(req ReqID, issue github.Issue, err error) any
- func FromWire(w *WireError) error
- func GitHubAliasesForTest(result any, aliases map[string]string) any
- func GitHubResultForTest(available bool, reason string, snapshots map[string]github.Snapshot, ...) any
- func Persistable(instances []*session.Instance) []*session.Instance
- func RemovedAccountNotice(removed, now string) string
- func RosterResultForTest(entries map[string]session.RosterEntry, err error, at time.Time) any
- func TrackedForTest(req ReqID, id InstanceID, result any) any
- func UntrackedForTest(result any) any
- func UsageResultForTest(results map[string]account.Usage, errs map[string]error) any
- type AccountNames
- type AccountsChanged
- type AccountsView
- func (v AccountsView) Account(name string) (account.Account, bool)
- func (v AccountsView) AccountEnv(name string) ([]string, error)
- func (v AccountsView) AccountLoggedOut(acct string) bool
- func (v AccountsView) AccountNames() AccountNames
- func (v AccountsView) AccountSync(name string) (account.SyncReport, bool)
- func (v AccountsView) AccountUsage(name string) (account.Usage, error)
- func (v AccountsView) AccountsLoaded() bool
- func (v AccountsView) Clone() AccountsView
- func (v AccountsView) HasExtraAccounts() bool
- func (v AccountsView) RCAuthFor(acct string) session.RemoteControlAuth
- type Alive
- type ClientsStale
- type Core
- type DeadVerified
- type Event
- type GitHubChanged
- type GitHubView
- type HealthChecked
- type HealthResult
- type InstanceID
- type InstanceView
- type InstancesChanged
- type Job
- type KillResult
- type Loop
- func (l *Loop) Account(name string) (account.Account, bool)
- func (l *Loop) AccountEnv(name string) ([]string, error)
- func (l *Loop) AccountLoggedOut(acct string) bool
- func (l *Loop) AccountNames() AccountNames
- func (l *Loop) AccountSync(name string) (account.SyncReport, bool)
- func (l *Loop) AccountUsage(name string) (account.Usage, error)
- func (l *Loop) AccountsLoaded() bool
- func (l *Loop) AddAccount(name string) (string, error)
- func (l *Loop) Begin()
- func (l *Loop) ClaudeProgram() string
- func (l *Loop) Create(id WorkspaceID, spec NewInstance, req ReqID)
- func (l *Loop) CredentialOverride() string
- func (l *Loop) DeliverForTest(result any)
- func (l *Loop) ExpediteGitHub()
- func (l *Loop) FetchIssue(repo string, n int, req ReqID)
- func (l *Loop) GitHubErr(repo string) error
- func (l *Loop) GitHubSnapshot(repo string) (github.Snapshot, bool)
- func (l *Loop) GitHubUnavailable() bool
- func (l *Loop) GitHubUnavailableReason() string
- func (l *Loop) HasExtraAccounts() bool
- func (l *Loop) HookTickForTest()
- func (l *Loop) IsLoaded(id WorkspaceID) bool
- func (l *Loop) JobsForTest() []Job
- func (l *Loop) Kill(id InstanceID, req ReqID)
- func (l *Loop) MarkOutput(sessionName string)
- func (l *Loop) Merge(target, source InstanceID, req ReqID)
- func (l *Loop) ModelForTest() *Model
- func (l *Loop) Open(id WorkspaceID) (WorkspaceView, error)
- func (l *Loop) OpenedForTest(id WorkspaceID) bool
- func (l *Loop) PaneOutput(id InstanceID)
- func (l *Loop) PaneQuiet(id InstanceID)
- func (l *Loop) Pause(id InstanceID, req ReqID)
- func (l *Loop) PersistOpenList(names []string)
- func (l *Loop) Push(id InstanceID, req ReqID)
- func (l *Loop) Quiesce(timeout time.Duration) bool
- func (l *Loop) RCAuth() session.RemoteControlAuth
- func (l *Loop) RCAuthFor(acct string) session.RemoteControlAuth
- func (l *Loop) Recover(id InstanceID, req ReqID)
- func (l *Loop) Register(name, dir string) (WorkspaceView, error)
- func (l *Loop) Registry() RegistryView
- func (l *Loop) ReloadAccounts()
- func (l *Loop) ReloadRegistry() error
- func (l *Loop) RemoveAccount(name string, force bool) error
- func (l *Loop) RenameWorkspace(from, to string) error
- func (l *Loop) RequestAccountsRefresh(withDefault bool)
- func (l *Loop) RequestUsageProbe()
- func (l *Loop) Reset(id WorkspaceID, req ReqID) error
- func (l *Loop) Resume(id InstanceID, req ReqID)
- func (l *Loop) ResumeWith(id InstanceID, opts launch.Options, base string, req ReqID)
- func (l *Loop) RunningAsAccount() string
- func (l *Loop) SaveForQuit() error
- func (l *Loop) SaveSettings(id WorkspaceID, s config.Settings) error
- func (l *Loop) SelectedForTest() []InstanceID
- func (l *Loop) SendPrompt(id InstanceID, text string, req ReqID)
- func (l *Loop) SetDefaultAccount(name string) error
- func (l *Loop) SetHelpScreensSeen(id WorkspaceID, seen uint32) error
- func (l *Loop) SetLastUsed(name string) error
- func (l *Loop) SetRCAuthForTest(a session.RemoteControlAuth)
- func (l *Loop) SetSelected(id InstanceID)
- func (l *Loop) SetSelection(ids []InstanceID)
- func (l *Loop) SetUIPrefs(id WorkspaceID, p config.UIPrefs) error
- func (l *Loop) SpawnForTest(job Job, background bool)
- func (l *Loop) Stop()
- func (l *Loop) Sync() []Event
- func (l *Loop) SyncAndSnapshot() (published, snapshot []Event)
- func (l *Loop) TickForTest()
- func (l *Loop) Unregister(name string) error
- func (l *Loop) VerifyDead(id InstanceID)
- func (l *Loop) View(id InstanceID) (InstanceView, bool)
- func (l *Loop) Views(id WorkspaceID) []InstanceView
- func (l *Loop) Wakes() <-chan struct{}
- func (l *Loop) WatchGitHub(repo string)
- func (l *Loop) Workspace(id WorkspaceID) (WorkspaceView, bool)
- func (l *Loop) Workspaces() []WorkspaceView
- type LoopPanic
- type MergeResult
- type Model
- func (m *Model) Account(name string) (account.Account, bool)
- func (m *Model) AccountEnv(name string) ([]string, error)
- func (m *Model) AccountLoggedOut(acct string) bool
- func (m *Model) AccountNames() AccountNames
- func (m *Model) AccountSync(name string) (account.SyncReport, bool)
- func (m *Model) AccountUsage(name string) (account.Usage, error)
- func (m *Model) AccountsLoaded() bool
- func (m *Model) AccountsRegistryForTest() *account.Registry
- func (m *Model) AddAccount(name string) (string, error)
- func (m *Model) AdoptAccountsForTest(reg *account.Registry)
- func (m *Model) AgeGitHubWatchesForTest(d time.Duration)
- func (m *Model) ApplyClaudeStatusForTest(inst *session.Instance)
- func (m *Model) Begin()
- func (m *Model) Boot() []Event
- func (m *Model) ClaudeProgram() string
- func (m *Model) Create(id WorkspaceID, spec NewInstance, req ReqID)
- func (m *Model) CredentialOverride() string
- func (m *Model) Deliver(msg any)
- func (m *Model) Drain() Out
- func (m *Model) ExpediteGitHub()
- func (m *Model) FetchIssue(repo string, n int, req ReqID)
- func (m *Model) GateForTest(kind string, now time.Time) (inFlight, pending, due bool)
- func (m *Model) GitHubErr(repo string) error
- func (m *Model) GitHubReposForTest() []string
- func (m *Model) GitHubSnapshot(repo string) (github.Snapshot, bool)
- func (m *Model) GitHubUnavailable() bool
- func (m *Model) GitHubUnavailableReason() string
- func (m *Model) HasExtraAccounts() bool
- func (m *Model) HookTick()
- func (m *Model) IDOfForTest(inst *session.Instance) InstanceID
- func (m *Model) InitAccounts()
- func (m *Model) InstanceForTest(id InstanceID) *session.Instance
- func (m *Model) IsLoaded(id WorkspaceID) bool
- func (m *Model) Kill(id InstanceID, req ReqID)
- func (m *Model) Loaded() []*Workspace
- func (m *Model) MainConfigDir() string
- func (m *Model) MarkOutput(sessionName string)
- func (m *Model) Merge(target, source InstanceID, req ReqID)
- func (m *Model) Open(id WorkspaceID) (WorkspaceView, error)
- func (m *Model) OutputMarkedForTest(sessionName string) bool
- func (m *Model) PaneOutput(id InstanceID)
- func (m *Model) PaneQuiet(id InstanceID)
- func (m *Model) Pause(id InstanceID, req ReqID)
- func (m *Model) PersistOpenList(names []string)
- func (m *Model) Push(id InstanceID, req ReqID)
- func (m *Model) RCAuth() session.RemoteControlAuth
- func (m *Model) RCAuthFor(acct string) session.RemoteControlAuth
- func (m *Model) Recover(id InstanceID, req ReqID)
- func (m *Model) RefreshDefaultAuthForTest() bool
- func (m *Model) Register(name, dir string) (WorkspaceView, error)
- func (m *Model) Registry() RegistryView
- func (m *Model) ReloadAccounts()
- func (m *Model) ReloadRegistry() error
- func (m *Model) RemoveAccount(name string, force bool) error
- func (m *Model) RenameWorkspace(from, to string) error
- func (m *Model) RequestAccountsRefresh(withDefault bool)
- func (m *Model) RequestUsageProbe()
- func (m *Model) Reset(id WorkspaceID, req ReqID) error
- func (m *Model) Resume(id InstanceID, req ReqID)
- func (m *Model) ResumeWith(id InstanceID, opts launch.Options, base string, req ReqID)
- func (m *Model) RunningAsAccount() string
- func (m *Model) SaveForQuit() error
- func (m *Model) SaveSettings(id WorkspaceID, s config.Settings) error
- func (m *Model) SelectedForTest() []InstanceID
- func (m *Model) SendPrompt(id InstanceID, text string, req ReqID)
- func (m *Model) SetAccountAuthForTest(auth map[string]session.RemoteControlAuth)
- func (m *Model) SetAccountSyncForTest(name string, rep account.SyncReport)
- func (m *Model) SetAccountUsageForTest(name string, u account.Usage, err error)
- func (m *Model) SetAccountsForTest(reg *account.Registry)
- func (m *Model) SetDefaultAccount(name string) error
- func (m *Model) SetExecForTest(e cmd2.Executor)
- func (m *Model) SetGateForTest(kind string, inFlight bool, last time.Time)
- func (m *Model) SetHelpScreensSeen(id WorkspaceID, seen uint32) error
- func (m *Model) SetLastUsed(name string) error
- func (m *Model) SetRCAuth(a session.RemoteControlAuth)
- func (m *Model) SetRegistryForTest(r *config.WorkspaceRegistry)
- func (m *Model) SetRunningAsAccountForTest(text string)
- func (m *Model) SetSelected(id InstanceID)
- func (m *Model) SetSelection(ids []InstanceID)
- func (m *Model) SetUIPrefs(id WorkspaceID, p config.UIPrefs) error
- func (m *Model) SetWorkspacesForTest(wss ...*Workspace)
- func (m *Model) Snapshot() []Event
- func (m *Model) Sync() Out
- func (m *Model) Tick()
- func (m *Model) Unregister(name string) error
- func (m *Model) VerifyDead(id InstanceID)
- func (m *Model) View(id InstanceID) (InstanceView, bool)
- func (m *Model) Views(id WorkspaceID) []InstanceView
- func (m *Model) WatchGitHub(repo string)
- func (m *Model) Workspace(id WorkspaceID) (WorkspaceView, bool)
- func (m *Model) WorkspaceForTest(id WorkspaceID) *Workspace
- func (m *Model) WorkspaceIDForTest(ws *Workspace) WorkspaceID
- func (m *Model) Workspaces() []WorkspaceView
- type ModelChanged
- type ModelView
- type NewInstance
- type Notice
- type OpFailed
- type Options
- type Out
- type PauseResult
- type ProbeResult
- type Reactivated
- type RecoverResult
- type Recovered
- type RecoverySummary
- type RegistryView
- type Reply
- type ReqID
- type ResetReport
- type ResumeResult
- type SessionLaunched
- type StartResult
- type Started
- type StatusesChanged
- type ViewsChanged
- type WireError
- type Workspace
- func (w *Workspace) AddForTest(inst *session.Instance)
- func (w *Workspace) Config() *config.Config
- func (w *Workspace) Ctx() *config.WorkspaceContext
- func (w *Workspace) InstancesForTest() []*session.Instance
- func (w *Workspace) Label() string
- func (w *Workspace) Name() string
- func (w *Workspace) Recovery() RecoverySummary
- func (w *Workspace) RemoveForTest(inst *session.Instance) bool
- func (w *Workspace) State() config.AppState
- func (w *Workspace) Storage() *session.Storage
- type WorkspaceID
- type WorkspaceParts
- type WorkspaceView
- type WorkspacesChanged
- type WorkspacesView
Constants ¶
const ( // CodeNotFound: the request named a session no loaded workspace holds // (ErrNoSession). CodeNotFound = "not_found" // CodeRefused: the model refused the request (ErrRefused). CodeRefused = "refused" // CodeStorage: the workspace's storage refuses writes // (session.ErrStorageLoadFailed). CodeStorage = "storage" // CodeError: any other failure; only its message survives. CodeError = "error" // CodePanic: the model panicked (LoopPanic); the client re-raises it. CodePanic = "panic" // CodeProtocol: a frame the other side could not use. The two sides // disagree about the wire, so a client treats it as fatal. CodeProtocol = "protocol" // CodeUnsupported: the peer does not know the method. An ordinary // error, never fatal, so a newer client can probe an older server. CodeUnsupported = "unsupported" // CodeMismatch: the two sides speak different protocol versions. CodeMismatch = "mismatch" // (ErrUnavailable, a refusal). An older peer sees only its message. CodeUnavailable = "unavailable" )
Wire error codes: what a client can still tell about an error once it has crossed a process boundary as text (see WireError).
const InstanceLimit = 10
InstanceLimit caps the rows a workspace holds (its terminal and recoverable rows count) before a client creates another. It is a soft guardrail: tmux server memory and git worktree overhead are the real bound, so raise it deliberately.
const MaxTitleWidth = 32
MaxTitleWidth is the widest title, in terminal cells, a new session takes.
Variables ¶
var ErrNoSession error = refusedError{errors.New("no such session")}
ErrNoSession refuses a request naming an ID no loaded workspace holds: the session was removed, or its workspace closed, after the client last saw it. It matches ErrRefused.
var ErrRefused = errors.New("request refused")
ErrRefused marks every refusal: a request the model would not start (its session gone, its precondition failed, its transition refused). A Reply's Err matches it (errors.Is) exactly when the request was refused, which the model reports nowhere but in that Reply; a failure of the request's job does not match it, and the model has already shown that one in a Notice.
ErrUnavailable refuses a request the model cannot take: the daemon is stopping, or the client has lost it. It matches ErrRefused, so the TUI's refusal path shows it.
Functions ¶
func AccountsRefreshedForTest ¶
func AccountsRefreshedForTest(defaultAuth *session.RemoteControlAuth, auth map[string]session.RemoteControlAuth, sync map[string]account.SyncReport) any
AccountsRefreshedForTest is a finished accounts refresh, for Deliver: the default account's auth (nil when not reread) and each extra account's auth and link report.
func CausedForTest ¶
CausedForTest is result as a job serving the request req delivers it: the Started, Recovered and Notice events it produces name req, as when the TUI's own Create or Recover lands. A test that hands the model an operation's result directly wraps it so, or the TUI treats the result as another client's.
func CheckNewTitle ¶
func CheckNewTitle(title string, ws WorkspaceView) error
CheckNewTitle refuses a title a new session in ws can't take: empty, wider than MaxTitleWidth cells, or preserved (CheckPreservedTitle).
func CheckPreservedTitle ¶
func CheckPreservedTitle(title string, ws WorkspaceView) error
CheckPreservedTitle refuses a title that belongs to a record ws's storage preserves on disk but could not load (a reconcile failure, or a newer loom's record after a downgrade). Storage never dedupes against such records, so creating the session would persist a second record under the title, and the two would share a tmux session name.
func CheckRoom ¶
CheckRoom refuses a new session in a workspace that already holds rows rows (InstanceLimit).
func CheckWritable ¶
func CheckWritable(ws WorkspaceView) error
CheckWritable refuses a new session in ws while its storage refuses writes (WorkspaceView.WritesRefused): the session could never be saved.
func ChooseLaunchAccount ¶
ChooseLaunchAccount is opts with the account a launch of program runs on, as the Session Launch Options modal pre-fills it, and the notice to show when it moved the launch off a removed account ("" otherwise). The caller reloads the accounts first (Core.ReloadAccounts).
A Claude launch with no account chosen, or with one no longer registered, takes the registry's default, so R on a session whose account was removed can't relaunch as it again; the notice names the switch (RemovedAccountNotice). A registry that failed to load keeps a named account: it lists no accounts, and rewriting the account would move the session to a subscription the user never saw chosen; kept, its launch fails closed (session.RegistryLoadError). Any other program, or a model with no account registry, records no account.
func FetchedIssueForTest ¶
FetchedIssueForTest is the result FetchIssue's job delivers for request req: issue, or err. A test delivers it in place of running the job, whose gh call it can't make.
func FromWire ¶
FromWire decodes a wire error: nil (a nil interface, never a typed nil pointer) for nil.
func GitHubAliasesForTest ¶
GitHubAliasesForTest is a GitHubResultForTest result whose poll found each key of aliases inside the repository named by its value.
func GitHubResultForTest ¶
func GitHubResultForTest(available bool, reason string, snapshots map[string]github.Snapshot, errs map[string]error) any
GitHubResultForTest is a finished GitHub poll's result, for Deliver: gh checked and found available or not (reason says why not), and each repo's snapshot or error.
func Persistable ¶
Persistable filters out instances whose state should not reach disk: a creation flow's instance that has never started (Ready and not Started), Deleting (kill in progress, about to be removed via DeleteInstance), and Recoverable (an orphan surfaced inline; it is re-derived from disk each load and adopted only on explicit recovery, so persisting it would resurrect a never-confirmed entry). Every other instance is persisted — Loading, Running, Prompting, Paused and a started Ready one — so that a crash or quit during the kill window cannot orphan a live worktree from its JSON record.
Ready is overloaded: a creation flow's instance is Ready before it starts, and the status ladder and Claude's roster report an idle agent or workspace terminal as Ready too. Skipping every Ready instance dropped idle sessions' records on each save, so the next load offered their worktrees as Recoverable orphans and killed and recreated an idle workspace terminal.
func RemovedAccountNotice ¶
RemovedAccountNotice says a launch whose account was removed runs on another one, which the user sees before confirming.
func RosterResultForTest ¶
RosterResultForTest is a finished roster query's result, for Deliver: entries is the default account's roster, err its failure, at when the query started.
func TrackedForTest ¶
func TrackedForTest(req ReqID, id InstanceID, result any) any
TrackedForTest is result as the job of request req, for the instance id, delivers it, so its Reply follows: a test delivers it in place of running the job, whose real work (adopting an orphan, say) it can't do.
func UntrackedForTest ¶
UntrackedForTest is a job's result with a request's tracking removed: a request's job (Kill, Merge, SendPrompt, …) answers with its operation's result wrapped for its Reply, and a job serving a request (a Create's start) with its result wrapped as caused; any other result comes back as it is.
Types ¶
type AccountNames ¶
AccountNames are the registered accounts, default first. Present is false until the account registry is set up (InitAccounts).
type AccountsChanged ¶
type AccountsChanged struct {
View AccountsView
}
AccountsChanged carries the account state whenever the registry, an account's auth, sync report or usage, or the Claude program changed (and on the first Sync): the TUI refreshes every view showing accounts (refreshAccountViews) and whether account UI shows at all (ui.SetShowAccounts), and a replica answers the account queries from it.
type AccountsView ¶
type AccountsView struct {
// Names is AccountNames(): Present is false without a registry.
Names AccountNames
// Loaded: the registry exists and loaded without error.
Loaded bool
// Extra: an account besides default is registered.
Extra bool
// ClaudeProgram is the Claude program the accounts run with ("" when
// neither the agent program nor an active session is Claude).
ClaudeProgram string
// CredentialOverride names the credential in the model's environment
// that overrides every account, "" when none does
// (Core.CredentialOverride).
CredentialOverride string
// RunningAsAccount warns that the model runs as an extra account, ""
// when it does not (Core.RunningAsAccount).
RunningAsAccount string
// Accounts are the registered accounts, by name.
Accounts map[string]account.Account
// DefaultAuth is the default account's remote-control auth, and Auth
// each extra account's that a refresh has read.
DefaultAuth session.RemoteControlAuth
Auth map[string]session.RemoteControlAuth
// Sync is each extra account's last link report.
Sync map[string]account.SyncReport
// Usage is each account's latest usage sample, and UsageErr its last
// probe's failure, if any.
Usage map[string]account.Usage
UsageErr map[string]string
}
AccountsView is the account state (published as AccountsChanged): the registry's accounts and default, each account's remote-control auth, link report, usage and launch env, and the Claude program they run.
func (AccountsView) Account ¶
func (v AccountsView) Account(name string) (account.Account, bool)
Account is the registered account called name (Core.Account).
func (AccountsView) AccountEnv ¶
func (v AccountsView) AccountEnv(name string) ([]string, error)
AccountEnv is the environment that runs Claude as name: nil for the default account, CLAUDE_CONFIG_DIR for a registered one, an error otherwise (Core.AccountEnv; account.Registry.Env).
func (AccountsView) AccountLoggedOut ¶
func (v AccountsView) AccountLoggedOut(acct string) bool
AccountLoggedOut reports that acct's last auth read found it logged out (Core.AccountLoggedOut).
func (AccountsView) AccountNames ¶
func (v AccountsView) AccountNames() AccountNames
AccountNames is the registry's names, default first (Core.AccountNames).
func (AccountsView) AccountSync ¶
func (v AccountsView) AccountSync(name string) (account.SyncReport, bool)
AccountSync is name's last link report (Core.AccountSync).
func (AccountsView) AccountUsage ¶
func (v AccountsView) AccountUsage(name string) (account.Usage, error)
AccountUsage is name's latest usage sample and its last probe's failure (Core.AccountUsage).
func (AccountsView) AccountsLoaded ¶
func (v AccountsView) AccountsLoaded() bool
AccountsLoaded reports that the registry exists and loaded (Core.AccountsLoaded).
func (AccountsView) Clone ¶
func (v AccountsView) Clone() AccountsView
Clone deep-copies v's maps and the reports and samples in them.
func (AccountsView) HasExtraAccounts ¶
func (v AccountsView) HasExtraAccounts() bool
HasExtraAccounts reports that an account besides default is registered (Core.HasExtraAccounts).
func (AccountsView) RCAuthFor ¶
func (v AccountsView) RCAuthFor(acct string) session.RemoteControlAuth
RCAuthFor is acct's remote-control auth: the default account's for "" or default, an extra account's as its last refresh read it, else Unknown (Core.RCAuthFor).
type Alive ¶
type Alive struct {
IDs []InstanceID
Source string
}
Alive lists the IDs of instances whose tmux session a probe found alive. The TUI re-attaches the client of any whose client is not attached (a reattach failed after a full-screen attach, or the client's pump hit EOF on a session since relaunched under its name), unless a full-screen attach owns it. Source names the probe for the TUI's log ("tick", "dead_event").
type ClientsStale ¶
type ClientsStale struct{}
ClientsStale reports that instances stopped being active (killed, paused, reverted): the TUI releases the pane clients no active instance needs (prunePanes).
type Core ¶
type Core interface {
// The loop: the TUI drains the model when the loop wakes it and after
// every message.
Sync() []Event // rpc:client
// Workspaces: every one the model serves, by ID, and the requests that
// open one, save them all, register, unregister, rename or reset one
// and write the registry. Which of them a client shows (its tabs, or
// the workspace it shows while none is open) is the client's own
// state.
Workspaces() []WorkspaceView // rpc:local
Workspace(id WorkspaceID) (WorkspaceView, bool) // rpc:local
IsLoaded(id WorkspaceID) bool // rpc:local
Open(id WorkspaceID) (WorkspaceView, error)
SaveForQuit() error
Registry() RegistryView // rpc:local
ReloadRegistry() error
Register(name, dir string) (WorkspaceView, error)
Unregister(name string) error
RenameWorkspace(from, to string) error
Reset(id WorkspaceID, req ReqID) error
PersistOpenList(names []string)
SetLastUsed(name string) error
// A workspace's settings, UI prefs and help screens.
SaveSettings(id WorkspaceID, settings config.Settings) error
SetUIPrefs(id WorkspaceID, prefs config.UIPrefs) error
SetHelpScreensSeen(id WorkspaceID, seen uint32) error
// Instances: their views, and every lifecycle action as a request by
// ID, answered by a Reply when it carries a ReqID.
Views(id WorkspaceID) []InstanceView // rpc:local
View(id InstanceID) (InstanceView, bool) // rpc:local
Create(id WorkspaceID, spec NewInstance, req ReqID)
Kill(id InstanceID, req ReqID)
Pause(id InstanceID, req ReqID)
Resume(id InstanceID, req ReqID)
ResumeWith(id InstanceID, opts launch.Options, base string, req ReqID)
Recover(id InstanceID, req ReqID)
Merge(target, source InstanceID, req ReqID)
Push(id InstanceID, req ReqID)
SendPrompt(id InstanceID, text string, req ReqID)
FetchIssue(repo string, number int, req ReqID)
// Claude status and the tick: what the TUI's pane events tell the
// model, and the selected row the model's health tick favours.
SetSelected(id InstanceID) // rpc:cast
MarkOutput(sessionName string) // rpc:cast
PaneOutput(id InstanceID) // rpc:cast
PaneQuiet(id InstanceID) // rpc:cast
VerifyDead(id InstanceID) // rpc:cast
// The default account's remote-control auth, which sessions launch
// with.
RCAuth() session.RemoteControlAuth // rpc:local
// GitHub: the poll's results, a poll sooner, and a repository the
// poll covers from now on.
GitHubSnapshot(repo string) (github.Snapshot, bool) // rpc:local
GitHubErr(repo string) error // rpc:local
ExpediteGitHub() // rpc:cast
WatchGitHub(repo string) // rpc:cast
// Accounts: the registry, each account's auth, sync, usage and env,
// and the account requests.
AccountNames() AccountNames // rpc:local
AccountsLoaded() bool // rpc:local
HasExtraAccounts() bool // rpc:local
Account(name string) (account.Account, bool) // rpc:local
RCAuthFor(acct string) session.RemoteControlAuth // rpc:local
AccountLoggedOut(acct string) bool // rpc:local
AccountSync(name string) (account.SyncReport, bool) // rpc:local
AccountUsage(name string) (account.Usage, error) // rpc:local
AccountEnv(name string) ([]string, error) // rpc:local
ClaudeProgram() string // rpc:local
CredentialOverride() string // rpc:local
RunningAsAccount() string // rpc:local
ReloadAccounts()
RequestAccountsRefresh(withDefault bool) // rpc:cast
RequestUsageProbe() // rpc:cast
AddAccount(name string) (string, error)
RemoveAccount(name string, force bool) error
SetDefaultAccount(name string) error
}
Core is the session model as its clients use it: every method the TUI calls. It is value-typed: every parameter and result, and every Event, is plain data a client could be sent from another process, never the model's own objects (TestCoreIsValueTyped). Instances are named by InstanceID and seen as InstanceView values, workspaces by WorkspaceID and WorkspaceView; the registry and accounts cross as copies, and every change is a request. *Loop, the model on its own goroutine, implements it in process: every call is a round trip over that goroutine, the model runs its own jobs and tick, and Loop.Wakes says when to Sync. The core/rpc client implements it over a connection (daemon stage 2). The model is booted before any client connects (Model.Boot) and starts its background work when its loop does (Loop.Begin): neither is a client's.
The rpc package is generated from this file. A method's line comment says how a client serves it:
- rpc:local answers from the client's replica of the published state (Snapshot, then the state events);
- rpc:cast is sent one way, with no reply, and publishes nothing, so a cast must change no published state: it marks, names or starts what publishes on its own when it lands;
- rpc:client never leaves the client (Sync returns the events it received);
- every other method is a request, whose reply follows the events it produced.
Parameter names are the wire's field names.
type DeadVerified ¶
DeadVerified is the probe a pane's Dead event asks for (VerifyDead): a dead attach PTY does not always mean a dead session.
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is something the TUI must apply to its view after a model call. The TUI applies them in order (app.applyCoreEvent).
func EventTypes ¶
func EventTypes() []Event
EventTypes returns a zero value of every concrete Event type: what a codec decodes events into, by type name. TestAllEventsListsEveryEvent keeps it complete.
type GitHubChanged ¶
type GitHubChanged struct {
View GitHubView
}
GitHubChanged carries the GitHub poll's state whenever a poll lands (and on the first Sync): the TUI refreshes an open issue picker, and a replica answers the GitHub queries from it.
type GitHubView ¶
type GitHubView struct {
Snapshots map[string]github.Snapshot
Errs map[string]string
// Aliases maps each polled path (canonical) that lies inside another
// repository's top level, a subdirectory of it, to that top level: a
// lookup by any spelling finds its repository's state.
Aliases map[string]string
// Unavailable: gh was checked and found unusable, for Reason.
Reason string
}
GitHubView is the GitHub poll's state (published as GitHubChanged): each open repo's snapshot or its last poll's failure, keyed by its canonical top level, and whether gh is usable.
func (GitHubView) Clone ¶
func (v GitHubView) Clone() GitHubView
Clone deep-copies v's maps and snapshots.
func (GitHubView) GitHubErr ¶
func (v GitHubView) GitHubErr(repo string) error
GitHubErr is repo's last poll failure (Core.GitHubErr), by any spelling of repo (ghRepoKey).
func (GitHubView) GitHubSnapshot ¶
func (v GitHubView) GitHubSnapshot(repo string) (github.Snapshot, bool)
GitHubSnapshot is repo's latest snapshot (Core.GitHubSnapshot), by any spelling of repo (ghRepoKey).
func (GitHubView) GitHubUnavailable ¶
func (v GitHubView) GitHubUnavailable() bool
GitHubUnavailable reports that gh was found unusable (Core.GitHubUnavailable).
func (GitHubView) GitHubUnavailableReason ¶
func (v GitHubView) GitHubUnavailableReason() string
GitHubUnavailableReason is why gh was found unusable (Core.GitHubUnavailableReason).
type HealthChecked ¶
type HealthChecked struct{}
HealthChecked reports that a health tick's probe landed and was applied. The loop arms the next tick then, so probes never overlap; the TUI refreshes the workbench's diff tab.
type HealthResult ¶
type HealthResult struct {
Results []ProbeResult
}
HealthResult is a health tick probe's result (Tick).
type InstanceID ¶
type InstanceID uint64
InstanceID names one record: a hash of its workspace's canonical config dir, its title and its creation time (idOf), so every daemon over one disk gives it the same ID and a client that rejoins another daemon keeps naming the same sessions. A request naming an ID can't reach another instance: a same-titled one in another workspace differs by config dir, and one created under the title of an instance killed meanwhile by creation time (a collision between two live records probes to the next free value). 0 is never assigned; the TUI uses it for a draft row.
type InstanceView ¶
type InstanceView struct {
ID InstanceID
Title string
// RepoPath is the repository the session works in (Instance.Path).
RepoPath string
WorktreePath string
// WorktreeRepoPath is the repository root its worktree belongs to, as
// git resolved it when the worktree was made (GitWorktree.GetRepoPath):
// RepoPath through symlinks, or the root above a subdirectory. "" until
// the instance has started, and for a workspace terminal. Lua's
// worktree handle is built on it.
WorktreeRepoPath string
Branch string
// TmuxSession is the agent's tmux session name ("" before it has one);
// pane clients attach by it. SessionProgram is the program that session
// was launched with, which picks the client's adapter (its
// pending-prompt pattern); Program can already name a new one after R.
TmuxSession string
SessionProgram string
Program string
Status session.Status
// StatusSince is when Status was entered (zero: not this process).
StatusSince time.Time
// StatusReported is set when Claude's hooks or roster have an opinion
// on the status (Instance.ClaudeStatus). Without one the TUI may show its
// own pane-scraped status instead (its ladder overlay).
StatusReported bool
WaitReason string
LastMessage string
HasLastMessage bool
Subagents []subagent.View
// Diff is the latest diff stats, valid when HasDiff.
Diff git.DiffStats
HasDiff bool
GitHub github.State
Ahead, Behind int
ParityKnown bool
Issue int
Account string
HeadroomProxy bool
CacheTTL1h bool
IsWorkspaceTerminal bool
Started bool
// Bell is the TUI's own overlay (a bell rang in the pane since it was
// last focused). The model never sets it.
Bell bool
}
InstanceView is an instance as a client sees it: a value copied out of the model (viewOf) carrying everything the TUI renders or gates a key on, and nothing that acts. Clients change an instance only through requests that name its ID. The model publishes each workspace's views when they change (Sync, ViewsChanged).
func CloneViews ¶
func CloneViews(views []InstanceView) []InstanceView
CloneViews deep-copies instance views (cloneViews), for a client that hands out its replica's views: the copies share no memory with it.
func ViewForTest ¶
func ViewForTest(inst *session.Instance, id InstanceID) InstanceView
ViewForTest is the view the model would publish for inst, with ID id: for ui tests that build an instance and render it.
func (InstanceView) Active ¶
func (v InstanceView) Active() bool
Active reports whether the instance is running for the purposes of the background jobs and the TUI's pane clients: started, and not Paused, Deleting, Recoverable or Loading. It is activeInstance's and statusEligible's rule, for a view.
func (InstanceView) Paused ¶
func (v InstanceView) Paused() bool
Paused reports whether the view's status is Paused.
func (InstanceView) StatusAge ¶
func (v InstanceView) StatusAge() time.Duration
StatusAge is how long the instance has been in its status, 0 when no transition was observed this process (as Instance.StatusAge).
type InstancesChanged ¶
type InstancesChanged struct{ Relayout bool }
InstancesChanged reports that instances were added, removed or replaced, or that a lifecycle operation moved their status. The TUI repoints its panes and menu at the selection (instanceChanged); with Relayout it also asks for the window size again (tea.RequestWindowSize), as the old completion did.
type Job ¶
type Job func() any
Job is work the model queues for its loop to run off the model's goroutine. It reads no model state and returns one message (nil for none), which the loop (Loop) delivers back to Deliver.
type KillResult ¶
KillResult is a finished kill (Kill): tmux, worktree and branch are gone, or best-effort gone with the failure logged. Notice is what the kill could not finish but the user must see (a stash entry it could not drop).
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop runs a Model on a goroutine of its own (daemon stage 1E). It serves every Core method as a round trip over that goroutine, starts the jobs the model queues on goroutines of their own and delivers their results on the loop, fires the model's health tick and hook timer from timers of its own, and signals Wakes when something it did unprompted (a result, a tick) may have produced events for its client to drain (Sync). It implements Core; nothing else touches its model.
Nothing runs on the loop's goroutine except inside a step, and nothing on it waits on its client or calls the loop: a call made from inside a call deadlocks.
func Start ¶
Start runs m on a goroutine of its own and returns the loop serving it. From here on only the loop touches m, which is booted already (Model.Boot). The health tick and the hook timer start with Begin; Stop ends the loop.
func StartForTest ¶
StartForTest runs m on a loop that keeps every job for the test to run (JobsForTest, then DeliverForTest) and never ticks on its own (TickForTest). Between calls its goroutine is idle, so the test may also reach m directly (ModelForTest): the loop's channel operations order those accesses for the race detector.
func (*Loop) AccountLoggedOut ¶
func (*Loop) AccountNames ¶
func (l *Loop) AccountNames() AccountNames
func (*Loop) AccountSync ¶
func (l *Loop) AccountSync(name string) (account.SyncReport, bool)
func (*Loop) AccountsLoaded ¶
func (*Loop) Begin ¶
func (l *Loop) Begin()
Begin starts the model's first background jobs (Model.Begin) and, the first time, the health tick and the hook timer. Whatever serves the loop calls it once, when it starts serving (the daemon, rpc.InProcess); it is not in Core.
func (*Loop) ClaudeProgram ¶
ClaudeProgram runs Model.ClaudeProgram on the loop.
func (*Loop) Create ¶
func (l *Loop) Create(id WorkspaceID, spec NewInstance, req ReqID)
func (*Loop) CredentialOverride ¶
CredentialOverride runs Model.CredentialOverride on the loop.
func (*Loop) DeliverForTest ¶
DeliverForTest delivers a job's result on the loop, as the goroutine that ran the job would (the health probe's result arming the next tick), and returns once it is applied. Its client is not woken.
func (*Loop) ExpediteGitHub ¶
func (l *Loop) ExpediteGitHub()
func (*Loop) GitHubUnavailable ¶
func (*Loop) GitHubUnavailableReason ¶
func (*Loop) HasExtraAccounts ¶
func (*Loop) HookTickForTest ¶
func (l *Loop) HookTickForTest()
HookTickForTest runs the model's hook timer tick on the loop, as its timer would (a StartForTest loop never fires it on its own).
func (*Loop) IsLoaded ¶
func (l *Loop) IsLoaded(id WorkspaceID) bool
func (*Loop) JobsForTest ¶
JobsForTest starts what the model has queued (a seam called on it directly may have queued jobs no step has taken yet), then takes the jobs a StartForTest loop kept, in the order queued.
func (*Loop) Kill ¶
func (l *Loop) Kill(id InstanceID, req ReqID)
func (*Loop) MarkOutput ¶
func (*Loop) Merge ¶
func (l *Loop) Merge(target, source InstanceID, req ReqID)
func (*Loop) ModelForTest ¶
ModelForTest returns the loop's model, for its seams. Only a loop that is idle between calls (StartForTest, or a production loop with nothing in flight) may be reached this way.
func (*Loop) Open ¶
func (l *Loop) Open(id WorkspaceID) (WorkspaceView, error)
func (*Loop) OpenedForTest ¶
func (l *Loop) OpenedForTest(id WorkspaceID) bool
OpenedForTest reports, on the loop, whether a client has opened the workspace id since the model started (Core.Open: its first open starts its terminal and its GitHub polling).
func (*Loop) PaneOutput ¶
func (l *Loop) PaneOutput(id InstanceID)
func (*Loop) PaneQuiet ¶
func (l *Loop) PaneQuiet(id InstanceID)
func (*Loop) Pause ¶
func (l *Loop) Pause(id InstanceID, req ReqID)
func (*Loop) PersistOpenList ¶
func (*Loop) Push ¶
func (l *Loop) Push(id InstanceID, req ReqID)
func (*Loop) Quiesce ¶
Quiesce readies the loop to stop: no tick or hook tick fires from now on, and it waits until every foreground job has landed (the lifecycle operations a request started, and the jobs their results start), or timeout passes. Background work (polls, probes, scans) is not waited for: its result is dropped at Stop. It reports whether everything landed. A server stopping calls it after it has stopped taking requests, then saves (SaveForQuit), then Stops, so a pause or a kill is never cut off mid-step.
func (*Loop) RCAuth ¶
func (l *Loop) RCAuth() session.RemoteControlAuth
func (*Loop) Recover ¶
func (l *Loop) Recover(id InstanceID, req ReqID)
func (*Loop) Registry ¶
func (l *Loop) Registry() RegistryView
func (*Loop) ReloadAccounts ¶
func (l *Loop) ReloadAccounts()
ReloadAccounts runs Model.ReloadAccounts on the loop.
func (*Loop) ReloadRegistry ¶
func (*Loop) RemoveAccount ¶
RemoveAccount runs Model.RemoveAccount on the loop.
func (*Loop) RenameWorkspace ¶
RenameWorkspace runs Model.RenameWorkspace on the loop.
func (*Loop) RequestAccountsRefresh ¶
func (*Loop) RequestUsageProbe ¶
func (l *Loop) RequestUsageProbe()
func (*Loop) Reset ¶
func (l *Loop) Reset(id WorkspaceID, req ReqID) error
Reset runs Model.Reset on the loop.
func (*Loop) Resume ¶
func (l *Loop) Resume(id InstanceID, req ReqID)
func (*Loop) ResumeWith ¶
func (*Loop) RunningAsAccount ¶
RunningAsAccount runs Model.RunningAsAccount on the loop.
func (*Loop) SaveForQuit ¶
func (*Loop) SaveSettings ¶
func (l *Loop) SaveSettings(id WorkspaceID, s config.Settings) error
func (*Loop) SelectedForTest ¶
func (l *Loop) SelectedForTest() []InstanceID
SelectedForTest is the model's selection (Model.SelectedForTest), read on the loop, so a test may read it while a server is calling the loop.
func (*Loop) SendPrompt ¶
func (l *Loop) SendPrompt(id InstanceID, text string, req ReqID)
func (*Loop) SetDefaultAccount ¶
func (*Loop) SetHelpScreensSeen ¶
func (l *Loop) SetHelpScreensSeen(id WorkspaceID, seen uint32) error
func (*Loop) SetLastUsed ¶
func (*Loop) SetRCAuthForTest ¶
func (l *Loop) SetRCAuthForTest(a session.RemoteControlAuth)
SetRCAuthForTest records the default account's remote-control auth on the loop (Model.SetRCAuth), as Boot's detection does: a change straight to the model, which only the next publish sends to its clients.
func (*Loop) SetSelected ¶
func (l *Loop) SetSelected(id InstanceID)
func (*Loop) SetSelection ¶
func (l *Loop) SetSelection(ids []InstanceID)
SetSelection names every client's selected row at once (Model.SetSelection): a server serving several clients keeps each one's SetSelected and sets their union. It serves the server and is not in Core.
func (*Loop) SetUIPrefs ¶
func (l *Loop) SetUIPrefs(id WorkspaceID, p config.UIPrefs) error
func (*Loop) SpawnForTest ¶
SpawnForTest queues job on the loop as the model would, a foreground job (spawn) or a background one (spawnBackground), and starts it: a test of what waits for jobs in flight (Quiesce, a daemon stopping).
func (*Loop) Stop ¶
func (l *Loop) Stop()
Stop ends the loop. It waits for the step in progress, then drops every later result (as Bubble Tea dropped a Cmd's result after quit) and closes Wakes. A call after Stop runs nothing and returns zero values. Stop is idempotent; never call it from the loop's goroutine.
func (*Loop) SyncAndSnapshot ¶
SyncAndSnapshot is a Sync and a Snapshot in one call on the loop, with nothing between them: the events published since the last Sync, then the whole state as it stands after them. A server uses it when a client connects: it sends the first to the connections it has and the second to the new one, whose replica then starts from exactly the state the next Sync diffs against. (A job landing between a Sync and a Snapshot made as two calls could change the model and undo the change before the next Sync, which would show in no diff and leave the new replica stale.) It serves servers: it is not part of Core.
func (*Loop) TickForTest ¶
func (l *Loop) TickForTest()
TickForTest runs the model's health tick on the loop, as its timer would.
func (*Loop) Unregister ¶
Unregister runs Model.Unregister on the loop.
func (*Loop) VerifyDead ¶
func (l *Loop) VerifyDead(id InstanceID)
func (*Loop) View ¶
func (l *Loop) View(id InstanceID) (InstanceView, bool)
func (*Loop) Views ¶
func (l *Loop) Views(id WorkspaceID) []InstanceView
func (*Loop) Wakes ¶
func (l *Loop) Wakes() <-chan struct{}
Wakes says the loop did something unprompted (a job's result landed, the tick fired, a job panicked), so its client should drain (Sync). Wakes coalesce: one waits, however many happened since the last receive. Stop closes it.
func (*Loop) WatchGitHub ¶
WatchGitHub runs Model.WatchGitHub on the loop.
func (*Loop) Workspace ¶
func (l *Loop) Workspace(id WorkspaceID) (WorkspaceView, bool)
func (*Loop) Workspaces ¶
func (l *Loop) Workspaces() []WorkspaceView
type LoopPanic ¶
type LoopPanic struct {
// Value is what was panicked with.
Value any
// Stack is the panicking goroutine's stack.
Stack string
}
LoopPanic is a panic on the model's goroutine (in a call, a delivery or the tick) or in one of its jobs. The loop re-raises it on the goroutine of the call it happened in, or of the next call after it, so the caller's own recovery sees it: the TUI's Bubble Tea restores the terminal, which a panic on a goroutine of the loop's own would leave in raw mode. The model's state is unknown after one, so every later call re-raises it too, and nothing runs on the model again.
type MergeResult ¶
type MergeResult struct {
Err error
}
MergeResult is a merge job's result (Merge).
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the session model (see the package doc). Methods must be called on one goroutine: its loop's (Loop), or a core test's.
func New ¶
New builds the model, serving no workspace yet: Boot loads them, before the model's loop starts.
func NewForTest ¶
NewForTest builds a model with no workspace and no side effects; a test installs its fixture's workspaces with SetWorkspacesForTest.
func (*Model) AccountEnv ¶
AccountEnv is the environment a command runs with as account name.
func (*Model) AccountLoggedOut ¶
AccountLoggedOut reports that `claude auth status` ran for acct and said it is logged out. Not having asked yet is not logged out.
func (*Model) AccountNames ¶
func (m *Model) AccountNames() AccountNames
AccountNames are the registered accounts, default first; Present is false before InitAccounts.
func (*Model) AccountSync ¶
func (m *Model) AccountSync(name string) (account.SyncReport, bool)
AccountSync returns name's last link report.
func (*Model) AccountUsage ¶
AccountUsage returns name's latest usage sample and the last probe's error (a failed probe keeps the last good sample).
func (*Model) AccountsLoaded ¶
AccountsLoaded reports whether the registry exists and loaded, so its account list can be trusted to be complete.
func (*Model) AccountsRegistryForTest ¶
AccountsRegistryForTest is the model's account registry (nil before InitAccounts): app tests check what an account request did to it.
func (*Model) AddAccount ¶
AddAccount creates account name (linked against the main config dir) and records its first sync report. The TUI then runs its login.
func (*Model) AdoptAccountsForTest ¶
AdoptAccountsForTest installs reg as the registry and publishes it, as InitAccounts does with the one it loads.
func (*Model) AgeGitHubWatchesForTest ¶
AgeGitHubWatchesForTest makes every repository a client asked the poll to cover (WatchGitHub) asked d earlier.
func (*Model) ApplyClaudeStatusForTest ¶
ApplyClaudeStatusForTest moves inst to the status its hooks or the roster last reported, as the model does when a hook scan or a roster answer lands (applyClaudeStatus).
func (*Model) Begin ¶
func (m *Model) Begin()
Begin starts the model's first background jobs, each when due: an accounts refresh and a usage probe. Its loop runs it when it starts serving (Loop.Begin).
func (*Model) Boot ¶
Boot readies the model to serve, before its loop starts (the model is single-goroutine until then). In order, it loads the account registry (InitAccounts); detects the default account's remote-control auth, when the global config enables remote control or an extra account is registered (the identity it reads also locates the main config dir the accounts link to); and loads every workspace the model serves (boot). The detection runs once, up front, so every launch decision after it is synchronous. Boot returns the events it raised (the account registry's notices): no client is connected yet to be sent them, so the caller shows them to its own. A client never boots the model: Boot is not in Core.
func (*Model) ClaudeProgram ¶
ClaudeProgram is the Claude CLI loom runs account commands with: the configured program when it is Claude, else a live Claude session's, else "" (no probes).
func (*Model) Create ¶
func (m *Model) Create(id WorkspaceID, spec NewInstance, req ReqID)
Create builds an instance in the workspace id (CreateWS), which refuses a workspace that is not loaded.
func (*Model) CredentialOverride ¶
CredentialOverride names the credential set in the model's own environment that overrides every account's login (account.ActiveCredentialOverride), "" when none is. The usage probes and auth reads inherit the model's environment and the remote-control block reason reads it. Since the model runs in the daemon (stage 3B), that environment is the one the daemon was spawned with, possibly from another terminal than a client's, so a client warns from this answer, never from its own environment.
An agent's own environment is another matter. These variables, like the default account's CLAUDE_CONFIG_DIR, are neither in tmux's update-environment nor passed with -e (session.InstanceEnv passes only an extra account's), so an agent inherits them from the tmux server's global environment: the environment of whatever started that server, which is the daemon's only when the daemon started it. Under a server something else started (the user's own, or an earlier daemon's, which the next keeps: daemon.TmuxServer), an agent bills by that server's credential, which this answer does not see.
func (*Model) Deliver ¶
Deliver hands the model a job's result. Results the model does not know are logged and dropped.
func (*Model) ExpediteGitHub ¶
func (m *Model) ExpediteGitHub()
ExpediteGitHub makes the next tick poll GitHub at once (an in-flight poll still lands first): after a push, an issue-born session, a newly opened workspace.
func (*Model) FetchIssue ¶
FetchIssue reads issue n of repo through gh (github.View) in a job and answers with the Reply's Issue (or Err).
func (*Model) GateForTest ¶
GateForTest reports the gate of the job kind names (gateKind's String: "roster", "hook_scan", "github", "usage", "accounts_refresh"): whether a dispatch is in flight, a request is pending, and the gate is due at now.
func (*Model) GitHubErr ¶
GitHubErr returns the last poll's error for repo, or nil; repo may be any spelling of it (ghRepoKey).
func (*Model) GitHubReposForTest ¶
GitHubReposForTest lists the repositories the next GitHub poll covers (openedRepos), in the order it polls them.
func (*Model) GitHubSnapshot ¶
GitHubSnapshot returns the latest poll's snapshot of repo, if the last poll of it succeeded; repo may be any spelling of it (ghRepoKey).
func (*Model) GitHubUnavailable ¶
GitHubUnavailable reports that gh was checked and found unusable (missing, or not logged in).
func (*Model) GitHubUnavailableReason ¶
GitHubUnavailableReason is why gh was found unusable (CheckCLI's error), for the issue picker's refusal.
func (*Model) HasExtraAccounts ¶
HasExtraAccounts reports whether an account besides default is registered; all account UI and polling is gated on it.
func (*Model) HookTick ¶
func (m *Model) HookTick()
HookTick is the loop's hook timer (hookInterval): a hook scan when one is due (maybeHookScan: none in flight, hookScanInterval since the last dispatch), and only while an active Claude instance exists, since only a Claude session writes hook events. With none it does nothing: no job, no gate armed. Either way it changes nothing a client sees (noWake): the scan's result wakes the client if it moved anything. The loop's timer calls it; Loop.HookTickForTest runs it in tests.
func (*Model) IDOfForTest ¶
func (m *Model) IDOfForTest(inst *session.Instance) InstanceID
IDOfForTest returns inst's ID (assigning one): for tests that build instances in the model and then find them through the TUI.
func (*Model) InitAccounts ¶
func (m *Model) InitAccounts()
InitAccounts loads the account registry and publishes it. Called once by the boot (Boot), before the startup auth probe.
func (*Model) InstanceForTest ¶
func (m *Model) InstanceForTest(id InstanceID) *session.Instance
InstanceForTest returns the instance id names, nil when no loaded workspace holds it: for tests that act on the instance behind a row.
func (*Model) IsLoaded ¶
func (m *Model) IsLoaded(id WorkspaceID) bool
IsLoaded reports whether the model serves the workspace id.
func (*Model) Kill ¶
func (m *Model) Kill(id InstanceID, req ReqID)
Kill kills the session id: its pre-step moves it to Deleting at once (the spinner shows), and its job checks, kills and deletes the record (killInst), answering with a KillResult or OpFailed. A Recoverable session is discarded. Refused for a workspace terminal and a busy session (precondition), so a second Kill of the same session is refused while the first runs.
func (*Model) Loaded ¶
Loaded is every workspace the model serves (Boot): every registered one and the global one, dropped only when it leaves the registry (Unregister, applyRegistry), so this is more than a client shows (its tabs, or the workspace it shows while none is open). It returns a fresh slice, so a caller may keep iterating it while calling back into the model.
func (*Model) MainConfigDir ¶
MainConfigDir is the default account's config dir, which extra accounts link to (account.MainDir over the identity read at startup).
func (*Model) MarkOutput ¶
MarkOutput records that a session produced output since the last health tick — the tick uses this to gate diff-stat refreshes.
func (*Model) Merge ¶
func (m *Model) Merge(target, source InstanceID, req ReqID)
Merge merges source's branch into target's worktree (mergeInst). Each must pass its precondition, and they must differ, as the merge picker lists neither a busy session nor the target among the sources. The Reply names target.
func (*Model) Open ¶
func (m *Model) Open(id WorkspaceID) (WorkspaceView, error)
Open is a client showing the workspace id, as a tab or as the workspace it shows while none is open, and returns its view. A workspace whose load failed is loaded again first, and its error returned when it still fails: the client then shows nothing of it. The first open of a workspace starts its terminal (open). An unknown id is an error. Which workspaces a client shows is its own state: an open publishes nothing tab-like, so it changes nothing another client shows.
func (*Model) OutputMarkedForTest ¶
OutputMarkedForTest reports whether sessionName's output is recorded for the next health tick's diff refresh (MarkOutput).
func (*Model) PaneOutput ¶
func (m *Model) PaneOutput(id InstanceID)
PaneOutput reports that id's pane produced output (paneOutputInst).
func (*Model) PaneQuiet ¶
func (m *Model) PaneQuiet(id InstanceID)
PaneQuiet reports that id's pane went quiet (paneQuietInst).
func (*Model) Pause ¶
func (m *Model) Pause(id InstanceID, req ReqID)
Pause pauses the session id: it moves to Loading at once (a refused transition is logged and the pause runs anyway, as the TUI's path always did), then the job stashes, kills the session and removes the worktree (pauseInst). pauseInst is called before the transition, as the TUI's path does, so a failed pause reverts to the status the session had, not to Loading. Refused for a workspace terminal and a busy session (precondition).
func (*Model) PersistOpenList ¶
PersistOpenList writes names to the registry's open list, so the next launch restores them: a client's tabs in order, then the workspaces it failed to open and keeps open. The open list is the client's; the model only writes it when asked.
func (*Model) Push ¶
func (m *Model) Push(id InstanceID, req ReqID)
Push commits and pushes the session id's worktree (pushInst). Refused for a workspace terminal and a busy session (precondition).
func (*Model) RCAuth ¶
func (m *Model) RCAuth() session.RemoteControlAuth
RCAuth is the default account's remote-control auth.
func (*Model) RCAuthFor ¶
func (m *Model) RCAuthFor(acct string) session.RemoteControlAuth
RCAuthFor returns acct's remote-control auth: the startup probe for the default account, the refreshed one for an extra account, and Unknown — fail closed, no flag and no prompt — until that has landed.
func (*Model) Recover ¶
func (m *Model) Recover(id InstanceID, req ReqID)
Recover adopts the orphan id, which must be Recoverable (precondition): recoverInst moves it to Loading and its job adopts the worktree, answering with a RecoverResult. Its Reply names the adopted instance, which replaces id's row.
func (*Model) RefreshDefaultAuthForTest ¶
RefreshDefaultAuthForTest reports whether the next accounts refresh rereads the default account's auth too.
func (*Model) Register ¶
func (m *Model) Register(name, dir string) (WorkspaceView, error)
Register adds dir to the registry as workspace name and returns the view of the workspace the model serves for it from now on, like every registered one, for the client to open (Open, which reports a load that failed). The registry has no lock, so this runs on the model's goroutine, never in a job.
func (*Model) Registry ¶
func (m *Model) Registry() RegistryView
Registry is a copy of the workspace registry: the registered workspaces, the open list (resolved, as GetOpenWorkspaces resolves it) and the last used workspace. Zero in bare tests.
func (*Model) ReloadAccounts ¶
func (m *Model) ReloadAccounts()
ReloadAccounts re-reads accounts.json, which another loom or a `loom account` command may have changed, and handles any change (accountsChanged). The health tick calls it when the file changed (maybeReloadAccounts); the user-paced actions that read the registry — Launch Options, Settings, account requests — call it first regardless.
func (*Model) ReloadRegistry ¶
ReloadRegistry rereads the workspace registry from disk, for a caller about to show it (the workspace picker) or open a workspace it lacks: another process may have changed it since (serveRegistry). A workspace registered since is served too; one no longer registered is unloaded (unload; one with a busy session waits for the next reread), and one registered under another name only is renamed in place, keeping its ID.
func (*Model) RemoveAccount ¶
RemoveAccount removes account name. Without force it refuses while a session uses it (accountUsers) or while its dir holds unshared files (the error then names them and the CLI command that can force it); force overrides both, as `loom account remove --force` does, and logs what it overrode.
func (*Model) RenameWorkspace ¶
RenameWorkspace renames registered workspace from to to: in the registry, whose open list and last used workspace follow, and in place in the model, whose workspace keeps its ID (its config dir's, wsIDOf), its sessions and its terminal's title. Refused (ErrRefused) for the global workspace, an unknown from, and a to already registered.
func (*Model) RequestAccountsRefresh ¶
RequestAccountsRefresh asks for an accounts refresh (accountsRefreshJob): now when none is in flight, else once more when the running one lands. withDefault also rereads the default account's auth.
func (*Model) RequestUsageProbe ¶
func (m *Model) RequestUsageProbe()
RequestUsageProbe brings the next probe round forward: the user is about to choose an account (a picker opened) or the accounts changed.
func (*Model) Reset ¶
func (m *Model) Reset(id WorkspaceID, req ReqID) error
Reset resets the served workspace id as `loom reset` does (ResetWorkspace). Its sessions leave the workspace at once, and a job deletes their records, kills the tmux sessions started in its roots and removes its worktrees and their branches. Meanwhile the workspace takes no session (Create) and no terminal (ensureTerminal). The job's outcome is the Reply to req, and a failure is shown as a Notice too; once it lands, an opened workspace gets a fresh terminal, as the next start used to give it.
A refusal (ErrRefused) is returned and, as for every request, is the Reply to req at once (refuse): an unknown workspace, a busy session or a reset already running (busy), and a workspace whose load failed. Its storage refuses writes, since loom can't read its records; the direct path clears that (`loom serve stop`, then `loom reset`).
func (*Model) Resume ¶
func (m *Model) Resume(id InstanceID, req ReqID)
Resume resumes the session id, which must be Paused and not a workspace terminal (precondition; a Recoverable one is Recover's): it moves to Loading at once and the job resumes it (resumeIfLoadingInst), answering with a ResumeResult, or an OpFailed reverting to Paused. The transition can't be refused from Paused; if it were, the request would be refused too.
func (*Model) ResumeWith ¶
ResumeWith resumes the session id with new launch options (the R flow): the program recomposed from base (applyLaunch), then as Resume. Its precondition is Resume's, checked before the options are applied, so a refused request changes nothing.
func (*Model) RunningAsAccount ¶
RunningAsAccount is the warning that loom itself runs as an extra account (noteRunningAsAccount), "" when it does not.
func (*Model) SaveForQuit ¶
SaveForQuit saves every workspace the model serves, as the daemon's last step when it stops (internal/daemon; a TUI quitting saves no session). A failed save of a workspace a client opened in this run is returned, for the daemon to log, except the storage's write latch (quitSkipsSave), which no retry could clear.
A workspace nobody opened is still saved, since its records change without a client (its agents are crash-restarted at boot and paused by the tick), but a registered repository on an unmounted or read-only path is no failure of the stop: its failure is only logged, and when its config dir is gone (a deleted or unmounted repository) it is skipped, since the save would create the dir.
func (*Model) SaveSettings ¶
func (m *Model) SaveSettings(id WorkspaceID, s config.Settings) error
SaveSettings replaces the workspace's settings with s and writes its config.json: to its context's config dir, or to the default config dir for a bare context. Then it applies what a settings change does at once: the two launch toggles the session package keeps per config dir (SetLoomContextEnabled, SetSubagentTrackingEnabled) and, for the global workspace only, the agent program the model runs the accounts' Claude commands and orphan placeholders with (m.program, ClaudeProgram): in a daemon that program is the global config's (Options.Program), so one workspace's save must not replace it for every other. The program a client's drafts default to is the client's to follow. An unknown id is an error. Moved from app/state_settings.go, which did this to the model's own config.
func (*Model) SelectedForTest ¶
func (m *Model) SelectedForTest() []InstanceID
SelectedForTest returns the instances the probe refreshes the full diff of (SetSelected, SetSelection).
func (*Model) SendPrompt ¶
func (m *Model) SendPrompt(id InstanceID, text string, req ReqID)
SendPrompt types text into the session id's pane and presses Enter (sendPromptInst). A failure is a notice, and the Reply's Err; a success replies with none. Refused for a session not started or Paused (precondition).
func (*Model) SetAccountAuthForTest ¶
func (m *Model) SetAccountAuthForTest(auth map[string]session.RemoteControlAuth)
SetAccountAuthForTest replaces every extra account's remote-control auth.
func (*Model) SetAccountSyncForTest ¶
func (m *Model) SetAccountSyncForTest(name string, rep account.SyncReport)
SetAccountSyncForTest records name's last link report.
func (*Model) SetAccountUsageForTest ¶
SetAccountUsageForTest records name's usage sample and last probe error.
func (*Model) SetAccountsForTest ¶
SetAccountsForTest replaces the registry without publishing it.
func (*Model) SetDefaultAccount ¶
SetDefaultAccount makes name the account new sessions preselect.
func (*Model) SetExecForTest ¶
SetExecForTest replaces the executor of the workspace load paths.
func (*Model) SetGateForTest ¶
SetGateForTest sets the in-flight flag and last dispatch of the gate of the job kind names.
func (*Model) SetHelpScreensSeen ¶
func (m *Model) SetHelpScreensSeen(id WorkspaceID, seen uint32) error
SetHelpScreensSeen replaces and persists the workspace's seen help screens.
func (*Model) SetLastUsed ¶
SetLastUsed records name as the workspace the next launch focuses.
func (*Model) SetRCAuth ¶
func (m *Model) SetRCAuth(a session.RemoteControlAuth)
SetRCAuth records the default account's remote-control auth, as Boot's detection does.
func (*Model) SetRegistryForTest ¶
func (m *Model) SetRegistryForTest(r *config.WorkspaceRegistry)
SetRegistryForTest replaces the workspace registry.
func (*Model) SetRunningAsAccountForTest ¶
SetRunningAsAccountForTest sets the warning that loom runs as an extra account, as InitAccounts would from its environment.
func (*Model) SetSelected ¶
func (m *Model) SetSelected(id InstanceID)
SetSelected names the instance whose full diff the health tick's probe refreshes: the TUI's selected row, 0 for none. The loop's tick reads it (Loop). With several clients a server sets them all (SetSelection).
func (*Model) SetSelection ¶
func (m *Model) SetSelection(ids []InstanceID)
SetSelection names every instance whose full diff the health tick's probe refreshes: each client's selected row. A server serving several clients keeps each one's SetSelected and sets their union here.
func (*Model) SetUIPrefs ¶
func (m *Model) SetUIPrefs(id WorkspaceID, p config.UIPrefs) error
SetUIPrefs replaces and persists the workspace's UI prefs.
func (*Model) SetWorkspacesForTest ¶
SetWorkspacesForTest installs a fixture's workspaces, served and opened, in serve order (a nil one and a repeat are skipped). The model has not booted: a Boot loads the global and registered workspaces beside them.
func (*Model) Snapshot ¶
Snapshot is the whole published state as events, in Sync's order: the workspace views, the model, account and GitHub views, and every served workspace's instance views. It leaves what the next Sync diffs against alone: it is what a client needs when it subscribes, before the diffs.
func (*Model) Sync ¶
Sync is syncEvents plus the jobs queued since the last call: everything the model produced, for a caller that runs its jobs itself (core's own tests; until stage 1E, the TUI). The loop (Loop.Sync) uses syncEvents.
func (*Model) Tick ¶
func (m *Model) Tick()
Tick runs the health tick's model half (tickInst), refreshing the full diff of every selected instance (SetSelection) that a loaded workspace holds. The loop's timer calls it.
func (*Model) Unregister ¶
Unregister removes workspace name from the registry and stops serving it, saving it first. Its sessions keep running, untouched: registering its directory again serves them anew, under the same IDs, which the disk derives (stableID). Refused (ErrRefused) for the global workspace, which no entry names, an unknown name, and a workspace with a busy session or a reset running (busy), whose completion must find it served. An entry that is another name for a directory still registered (a twin), or for the global workspace's, only leaves the registry: the workspace stays served, under a name still registered (applyRegistry).
func (*Model) VerifyDead ¶
func (m *Model) VerifyDead(id InstanceID)
VerifyDead queues the probe a pane's Dead event asks for on id's session (verifyDeadInst); its result is a DeadVerified as before.
func (*Model) View ¶
func (m *Model) View(id InstanceID) (InstanceView, bool)
View returns the view of the instance id, which a served workspace must hold (false otherwise).
func (*Model) Views ¶
func (m *Model) Views(id WorkspaceID) []InstanceView
Views returns the workspace id's instances as views (ViewsWS); nil for an unknown id.
func (*Model) WatchGitHub ¶
WatchGitHub adds repo to the repositories the poll covers, for ghWatchTTL from now, and polls at the next tick (ExpediteGitHub) unless the poll has an answer for it already. A client's issue picker asks for its repository on every open: in global mode, a TUI started in a repository no opened workspace or global session names, which the poll would otherwise never cover. A repository watched already (compared canonically) is renewed, and one the poll has answered for (a snapshot or an error) is not polled again at once, so a picker opened again costs no gh calls. A path that is not absolute is not watched. One an opened workspace's poll covers already, under any spelling or from a subdirectory, is polled once (openedRepos, ghPollJob), and the client finds its state by the path it asked with (ghRepoKey). Expired watches are dropped here.
func (*Model) Workspace ¶
func (m *Model) Workspace(id WorkspaceID) (WorkspaceView, bool)
Workspace is the view of the served workspace id; false when the model serves none with it.
func (*Model) WorkspaceForTest ¶
func (m *Model) WorkspaceForTest(id WorkspaceID) *Workspace
WorkspaceForTest resolves a loaded workspace's ID to the model's workspace, nil when none is loaded: app tests reach a fixture's instances through it.
func (*Model) WorkspaceIDForTest ¶
func (m *Model) WorkspaceIDForTest(ws *Workspace) WorkspaceID
WorkspaceIDForTest is ws's ID, assigned on first use.
func (*Model) Workspaces ¶
func (m *Model) Workspaces() []WorkspaceView
Workspaces are the views of every workspace the model serves, in serve order: what a client opens one by (Open) and shows a failed load from (LoadErr).
type ModelChanged ¶
type ModelChanged struct {
View ModelView
}
ModelChanged carries the model's own state (the default account's remote-control auth and the workspace registry) whenever it changed, and on the first Sync. The TUI does nothing with it; a replica answers those queries from it.
type ModelView ¶
type ModelView struct {
RCAuth session.RemoteControlAuth
Registry RegistryView
}
ModelView is the model's own state: the default account's remote-control auth and the workspace registry (published as ModelChanged).
type NewInstance ¶
type NewInstance struct {
Title string
Path string // the repository it works in
Program string // the base program; Launch is composed onto it
Prompt string // sent once it has started
Branch string // the branch picker's choice; "" for a new branch
Issue int // the GitHub issue it was made from, 0 for none
// Launch is the Session Launch Options choice. Its account and branch
// prefix are recorded on the instance; the rest is composed onto
// Program with the account's remote-control auth (applyLaunch). Only
// with Start.
Launch launch.Options
// Start starts it at once (the creation flows). Without it the
// instance is added unstarted (a script's ctx:new_instance).
Start bool
}
NewInstance describes an instance to create (Create).
type Notice ¶
Notice is a line for the error bar: Err as an error (shown longer the longer it is, and logged), or else Info as an info line. Req names the request whose job it reports on (a failed job, a stash it forgot), 0 for one the model raised on its own: a server sends a request's notices to the client that made it alone.
func (Notice) MarshalJSON ¶
MarshalJSON encodes n with its error as a WireError.
func (*Notice) UnmarshalJSON ¶
UnmarshalJSON decodes a Notice MarshalJSON encoded.
type OpFailed ¶
type OpFailed struct {
Instance *session.Instance
Title string
Op string
Previous session.Status
Err error
}
OpFailed is a kill, discard, pause or resume that failed: the instance goes back to Previous so the user can retry.
type Options ¶
type Options struct {
// Registry is the workspace registry; nil in bare tests.
Registry *config.WorkspaceRegistry
// Program is the global config's agent program, as the daemon starts
// the model (loom serve). The model detects the default account's
// remote-control auth with it (Boot), and runs the accounts' Claude
// commands (ClaudeProgram) and orphan placeholders with it, until the
// global workspace's settings save replaces it (SaveSettings); each
// client keeps the program its own drafts default to.
Program string
// CmdExec replaces cmd.MakeExecutor() on the workspace load paths: a
// test seam. nil in production.
CmdExec cmd2.Executor
// GHExec replaces the executor FetchIssue runs gh with: a test seam
// (a daemon test holds a request's job with it). nil in production.
GHExec cmd2.Executor
}
Options configure a Model.
type Out ¶
Out is what the model produced since the last Drain: events for the TUI and jobs to run, each in the order produced.
type PauseResult ¶
type PauseResult struct {
Title string
}
PauseResult is a finished pause (Pause).
type ProbeResult ¶
ProbeResult is one instance's health probe: its tmux liveness and, for a live one, whether its diff refresh failed. Exported so the TUI's tests can deliver a HealthResult.
type Reactivated ¶
type Reactivated struct {
ID InstanceID
}
Reactivated reports that a failed operation put the instance ID back to its previous status. A tick may have pruned its client while it was Deleting or Loading, so the TUI ensures one (ensurePane, a no-op unless the instance is active).
type RecoverResult ¶
type RecoverResult struct {
Placeholder *session.Instance
Owner *Workspace
OldTitle string
Recovered *session.Instance
Err error
}
RecoverResult is a recover job's result (Recover). Placeholder is the Recoverable row it adopts, OldTitle its title; Recovered is the adopted instance, or Err why adoption failed.
type Recovered ¶
type Recovered struct {
Req ReqID
ID InstanceID
Title string
Owner WorkspaceID
Paused bool
// OwnerLabel is as for Started.
OwnerLabel string
}
Recovered reports an orphan adopted into its placeholder's row. Req, Owner, ID and Title are as for Started. Paused is set when adoption could only mark the record Paused (its session and worktree were gone).
type RecoverySummary ¶
type RecoverySummary struct {
Cleaned int // stale worktrees auto-removed
Review int // Recoverable entries added to the list
Failed int // records that failed reconcile (storage unrecovered cache)
// Undecodable counts records this binary cannot decode (corrupt, or
// written by a newer loom); storage preserves them verbatim.
Undecodable int
}
RecoverySummary tallies what a reconcileOrphans pass did, for the non-blocking one-line summary shown to the user.
func (RecoverySummary) Empty ¶
func (s RecoverySummary) Empty() bool
func (RecoverySummary) String ¶
func (s RecoverySummary) String() string
type RegistryView ¶
RegistryView is a copy of the workspace registry: every registered workspace, the open tabs to restore (the open list resolved to its registered workspaces, in order, as GetOpenWorkspaces resolves it), and the workspace last focused, which a restore focuses.
type Reply ¶
Reply answers a request made with a ReqID: at once when the request is refused, when it finishes for a long operation. ID names the instance it concerns (for Create the new one, for Recover the adopted one). Err is the failure. Notice is what a success must still show (a stash it could not drop). Issue is FetchIssue's result. The notices the TUI shows for an operation are emitted as usual; the Reply is for the requester that waits on it.
func (Reply) MarshalJSON ¶
MarshalJSON encodes r with its errors as WireErrors.
func (*Reply) UnmarshalJSON ¶
UnmarshalJSON decodes a Reply MarshalJSON encoded.
type ReqID ¶
type ReqID uint64
ReqID names a request so its Reply can find the requester. The client chooses it; 0 asks for no Reply.
type ResetReport ¶
type ResetReport struct {
// Records: the workspace's stored instances were deleted.
Records bool
// Sweep is what the sweep of its tmux sessions did, once it ran; Swept
// that it ran and every kill landed.
Sweep session.SweepResult
Swept bool
// Worktrees: its worktrees and their branches were removed.
Worktrees bool
}
ResetReport says how far a reset got (ResetWorkspace), step by step.
func ResetWorkspace ¶
func ResetWorkspace(ctx *config.WorkspaceContext, registry *config.WorkspaceRegistry, exec cmd2.Executor) (ResetReport, error)
ResetWorkspace resets the workspace of ctx from its records on disk, as `loom reset` does with no daemon running (the model's Reset runs the same steps over the records it serves). In order, it
- deletes the workspace's stored instances, and the records storage preserves beside them (undecodable or unrecovered);
- kills the loom tmux sessions started in its repository or worktrees dir, and none of another workspace's (registry tells them apart; nil when it can't be read), with exec;
- removes its worktrees and their branches: unpushed commits on them are lost.
A sweep that fails stops it before step 3: some of the workspace's agents may still be running in those worktrees. The report says how far it got.
type ResumeResult ¶
type ResumeResult struct {
Instance *session.Instance
Owner *Workspace
Notice error
Relaunched bool
}
ResumeResult is a resume that succeeded (resumeIfLoadingInst). Notice, when set, is what it found that the user must see: a stash it forgot or could not drop (session.Notice). Relaunched says it launched the agent anew (session.Instance.Launches moved) rather than reattach to its live session, so the launch is watched for a trust prompt. A failed resume is an OpFailed.
type SessionLaunched ¶
type SessionLaunched struct {
ID InstanceID
}
SessionLaunched reports that the tmux session of the instance ID was (re)launched or reattached while a loaded workspace holds it, so any pane client from before watched the session it replaced: the TUI gives it a fresh one (replacePane).
type StartResult ¶
StartResult is a start job's result (startInst): the instance, Start's error, and the workspace that owned it at dispatch.
type Started ¶
type Started struct {
Req ReqID
ID InstanceID
Title string
Owner WorkspaceID
// OwnerLabel names the owner in notices ("global" when unknown).
OwnerLabel string
}
Started reports a start that succeeded. Owner names the workspace that holds the instance (0 when unknown); the TUI attaches its client, and selects it or says where it started. ID and Title are the instance's. Req is the request that started it (a Create), 0 for none: only the client that asked selects the row and attaches inline, while every client attaches its pane.
type StatusesChanged ¶
type StatusesChanged struct{}
StatusesChanged reports that instance statuses may have moved (a probe, a hook scan, a roster answer): the TUI refreshes its tab statuses and peer sections (updateTabBarStatuses).
type ViewsChanged ¶
type ViewsChanged struct {
// WS names the workspace: the TUI's slot for it.
WS WorkspaceID
Views []InstanceView
}
ViewsChanged carries a served workspace's instance views, in display order, whenever any of them changed since the last Sync. The TUI replaces its store for that workspace with Views, when it shows the workspace. Sync puts these first in the events it returns, so the appliers of the events that follow see the new views.
type WireError ¶
WireError is an error as it crosses a process boundary: its message, and a code that keeps the identities clients test with errors.Is (ErrNoSession, ErrUnavailable, ErrRefused, session.ErrStorageLoadFailed). Every other error arrives as text only, which is all the TUI does with one.
func ToWire ¶
ToWire encodes err for the wire: nil for nil, a WireError unchanged, an error wrapping one (decode params: %w) under that one's code with the whole message, anything else its message under the code of the first sentinel it matches (CodeError for none).
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace is one loaded workspace: its context, the storage its instances persist to, its config and app state, its instances in display order, and the summary of its last orphan reconcile. The model owns it; the TUI reads it (its slot is a view over it) and changes its instances only through Add, Remove and Replace. Its context changes only by a rename (renameWS, which gives it a renamed copy) and its storage, config and state only by a reread from disk (reloadWS).
func NewWorkspace ¶
func NewWorkspace(p WorkspaceParts) *Workspace
NewWorkspace builds a workspace with no instances.
func (*Workspace) AddForTest ¶
AddForTest adds inst to w as the model's own edits do (Workspace.add): for tests that build instances and install them in a fixture workspace.
func (*Workspace) Ctx ¶
func (w *Workspace) Ctx() *config.WorkspaceContext
Ctx is the workspace's context; nil only in bare test fixtures.
func (*Workspace) InstancesForTest ¶
InstancesForTest returns w's instances, in display order (the model's own slice; a test must not modify it).
func (*Workspace) Label ¶
Label names the workspace in notices: its name, or "global" (also for a nil workspace).
func (*Workspace) Name ¶
Name is the workspace's registered name, "" for the global context (and for a nil workspace).
func (*Workspace) Recovery ¶
func (w *Workspace) Recovery() RecoverySummary
Recovery is the summary of the workspace's last orphan reconcile.
func (*Workspace) RemoveForTest ¶
RemoveForTest removes inst from w by identity, as the model's own edits do (Workspace.remove): for tests that stand in for a removal.
type WorkspaceID ¶
type WorkspaceID uint64
WorkspaceID names a workspace the model serves: a hash of its canonical config dir (wsIDOf), so every daemon over one disk gives it the same ID. A workspace keeps its ID while the model serves it, which is until the model stops (a tab closed and reopened shows the same workspace); a collision between two served workspaces probes to the next free value. 0 means none.
type WorkspaceParts ¶
type WorkspaceParts struct {
Ctx *config.WorkspaceContext
Storage *session.Storage
Config *config.Config
State config.AppState
}
WorkspaceParts are a workspace's fixed handles. Any may be nil, as in a test's bare fixture.
type WorkspaceView ¶
type WorkspaceView struct {
ID WorkspaceID
// Name is the registered name, "" for the global context; Label names
// it in notices (its name, or "global").
Name, Label string
// RepoPath and ConfigDir are the workspace context's ("" in a bare
// context).
RepoPath, ConfigDir string
// Settings is a copy of the workspace's config.json.
Settings config.Settings
// UIPrefs and HelpScreensSeen are copies of its state.json.
UIPrefs config.UIPrefs
HelpScreensSeen uint32
// WritesRefused is set while the workspace's storage refuses writes
// (its load failed: Storage.WritesRefused). PreservedTitles are the
// titles of records its storage preserves but could not load.
WritesRefused bool
PreservedTitles []string
// Recovery is the summary of its last orphan reconcile.
Recovery RecoverySummary
// LoadErr is the text of the error its storage failed to load with,
// "" once it loaded: what a client can show a failed workspace with.
// Opening it retries the load (Core.Open), which reports the error
// again if it still fails.
LoadErr string
}
WorkspaceView is a served workspace as its clients see it: a value the model publishes (WorkspacesChanged) and answers queries with. Every field is a copy.
func CloneWorkspaceViews ¶
func CloneWorkspaceViews(views []WorkspaceView) []WorkspaceView
CloneWorkspaceViews deep-copies workspace views (cloneWorkspaceViews).
type WorkspacesChanged ¶
type WorkspacesChanged struct {
Views []WorkspaceView
}
WorkspacesChanged carries every served workspace's view, in serve order, whenever any of them (or the served set) changed since the last Sync. Sync puts it first, ahead of ViewsChanged, so the appliers of everything after it see the new workspace views. Which of them a client shows is its own state.
type WorkspacesView ¶
type WorkspacesView struct {
Views []WorkspaceView
}
WorkspacesView is every served workspace's view, in serve order.
func (WorkspacesView) IsLoaded ¶
func (w WorkspacesView) IsLoaded(id WorkspaceID) bool
IsLoaded reports whether the workspace id is served (Core.IsLoaded).
func (WorkspacesView) Workspace ¶
func (w WorkspacesView) Workspace(id WorkspaceID) (WorkspaceView, bool)
Workspace is the view of the served workspace id (Core.Workspace).
func (WorkspacesView) Workspaces ¶
func (w WorkspacesView) Workspaces() []WorkspaceView
Workspaces are the served workspaces' views, in serve order (Core.Workspaces): never nil.
Source Files
¶
- accounts.go
- claude_status.go
- claude_tmp.go
- completions.go
- doc.go
- events.go
- events_json.go
- gate.go
- github.go
- hook_scan.go
- ids.go
- iface.go
- launch_watch.go
- load.go
- loop.go
- loop_core.go
- model.go
- new_session.go
- ops.go
- persist.go
- requests.go
- reset.go
- seams.go
- settings.go
- state_publish.go
- state_views.go
- tick.go
- usage.go
- view.go
- views.go
- wire_error.go
- workspace.go
- workspace_requests.go
- workspace_view.go
- workspace_views.go
- workspaces.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package rpc carries core.Core over a connection (daemon stage 2): newline-delimited JSON frames, a Server serving a core.Loop, and a Client implementing core.Core.
|
Package rpc carries core.Core over a connection (daemon stage 2): newline-delimited JSON frames, a Server serving a core.Loop, and a Client implementing core.Core. |
|
internal/gen
Package gen generates core/rpc's wire code from core.Core (core/iface.go): every method's parameter and result types, the method table, the server's dispatch, and the client's methods.
|
Package gen generates core/rpc's wire code from core.Core (core/iface.go): every method's parameter and result types, the method table, the server's dispatch, and the client's methods. |
|
internal/gen/cmd
command
Command cmd writes core/rpc/methods_gen.go from core/iface.go.
|
Command cmd writes core/rpc/methods_gen.go from core/iface.go. |