Documentation
¶
Overview ¶
Package app is Loomux's composition root: it wires the workspace registry, TargetExecutor, orchestrator, completion detection, credential vault, and router dispatch pipeline (design spec §2-§7) into a runnable App with a single Dispatch operation. The versioned HTTP/WS client API and login-gated auth (design spec §9, §10 axis 1, LOOM-9) are explicitly out of scope here — this package only proves the whole stack constructs and is dispatchable; a later HTTP/WS/auth layer is expected to wrap an *App rather than re-wire these pieces itself. cmd/loomuxd is the thin CLI entrypoint built on this package.
Index ¶
- func DefaultAgentTypes() router.AgentTypeRegistry
- type App
- func (a *App) AgentTypeNames() []string
- func (a *App) CancelTask(ctx context.Context, taskID string) (string, error)
- func (a *App) CheckAgentArgs(agentType string, pin registry.AgentArgs) error
- func (a *App) Close() error
- func (a *App) CloseAgentSignIn(ctx context.Context, targetID, agentType string) error
- func (a *App) DeleteWorkspace(ctx context.Context, id string) ([]string, error)
- func (a *App) DeleteWorkspaceAndWorktree(ctx context.Context, id string) ([]string, error)
- func (a *App) Dispatch(ctx context.Context, conversationID, message, workspaceHint string) (string, error)
- func (a *App) Dispatches() *dispatch.Service
- func (a *App) DrainDispatches() error
- func (a *App) DropSSHKey(id string)
- func (a *App) HealthChecker() *health.Checker
- func (a *App) LocalTargets() bool
- func (a *App) Machines() *providers.Manager
- func (a *App) Metrics() *metrics.Metrics
- func (a *App) Plugins() *plugins.Manager
- func (a *App) PrepareAgentSignIn(ctx context.Context, targetID, agentType string, restart bool) (*api.AgentSignInResult, error)
- func (a *App) ProbeTarget(ctx context.Context, targetID string) (*registry.TargetHealth, []*registry.TargetAgent, error)
- func (a *App) ProvisionWorkspace(ctx context.Context, req api.WorkspaceToProvision) (api.ProvisionedWorkspace, error)
- func (a *App) ResolveSSHConfig(ctx context.Context, t *registry.Target, keyFile string) (*targets.SSHConfigPlan, error)
- func (a *App) RouterSettings() *llmrouter.Settings
- func (a *App) ScanHostKey(ctx context.Context, t *registry.Target) ([]targets.HostKey, error)
- func (a *App) SetWorkspaceStatus(ctx context.Context, id string, status registry.WorkspaceStatus) error
- func (a *App) StartHoldSweeper(sessionTTL, sessionMaxAge time.Duration)
- func (a *App) StartRetention(sessionTTL, sessionMaxAge time.Duration)
- func (a *App) Store() registry.Store
- func (a *App) TaskHolds() *orchestrator.Orchestrator
- func (a *App) TmuxSocket() string
- type Config
- type NotifyConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAgentTypes ¶
func DefaultAgentTypes() router.AgentTypeRegistry
DefaultAgentTypes is the production registered-agent-type set: "claude-code" and "codex" (LOOM-22 — proves the agent-type interface generalizes beyond a single CLI), both built by package agents. Both are TierMarker, and Loomux owns the whole completion path (LOOM-75): router.launchAgent tells the launched process its marker path (LOOMUX_MARKER_PATH, LOOM-32), and each adapter's CompletionHookArgs install the hook that touches it — claude's Stop hook via --settings, codex's notify via -c — per launch, with nothing configured on the target beforehand. The "" entry configures completion detection for shell-kind (provisioning) tasks only (router/agenttype.go's own doc comment) — it is never a real dispatchable agent type and is deliberately excluded from what's offered to the router model by dispatchableAgentTypeNames below.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the fully wired Loomux domain layer, exposed through the one operation this package's "minimal internal interface" needs — Dispatch — plus lifecycle cleanup and read access to the underlying Store for a client-facing layer (api.Server) that needs its own session storage in the same database.
func Build ¶
Build wires the full domain layer (design spec §2-§7) from cfg: storage -> executor factory -> completion detection -> orchestrator -> credential resolver -> LLM-backed routing model -> router. On any failure after the store opens successfully, the store is closed before returning the error.
func (*App) AgentTypeNames ¶
AgentTypeNames are the agent types this server can launch, sorted (LOOM-122: what a target's allowed_agent_types may name).
func (*App) CancelTask ¶
CancelTask cancels a task (LOOM-99). A running task is the one its conversation's running dispatch drives — only one task is ever mid-turn — so it is cancelled through that dispatch, which ends the turn. Any other open task (left awaiting input, stopped at a prompt, or running with no dispatch after a restart) is cancelled directly — see router.Router.CancelTask — never through a dispatch driving some other task of the conversation. Satisfies api.TaskCanceller.
func (*App) CheckAgentArgs ¶ added in v0.3.161
CheckAgentArgs reports whether agentType is one this server launches and its CLI takes the pin a (LOOM-307): api.WithAgentArgsCheck.
func (*App) Close ¶
Close stops the background idle reaper (LOOM-16) and releases the store's resources (its DB connection).
func (*App) CloseAgentSignIn ¶ added in v0.3.160
CloseAgentSignIn closes agentType's sign-in session on targetID (LOOM-316). Satisfies api.AgentSignIns.
func (*App) DeleteWorkspace ¶
DeleteWorkspace deletes a workspace, its tasks and their sessions (LOOM-70) — see orchestrator.Orchestrator.DeleteWorkspace. Satisfies api.WorkspaceManager.
func (*App) DeleteWorkspaceAndWorktree ¶ added in v0.3.121
DeleteWorkspaceAndWorktree is DeleteWorkspace that also removes the workspace's git worktree from its target (LOOM-228).
func (*App) Dispatch ¶
func (a *App) Dispatch(ctx context.Context, conversationID, message, workspaceHint string) (string, error)
Dispatch routes one chat message through the full pipeline. See router.Router.Dispatch. workspaceHint (LOOM-46) is an optional, advisory workspace ID — empty means no hint — surfaced as a plain string rather than a router.DispatchOption specifically so callers like api.Server's Dispatcher interface don't need to import the router package just to supply it (mirroring api.Dispatcher's own narrow-seam rationale).
func (*App) Dispatches ¶
Dispatches is the dispatch-job service (LOOM-80) the client API submits chat messages to: each runs through the router as a job on a server-owned context, outliving the request that submitted it.
func (*App) DrainDispatches ¶
DrainDispatches stops accepting dispatch jobs and gives in-flight ones the configured drain time to finish; any still running are then marked interrupted, their tasks left for startup reconciliation (LOOM-82). Call it on shutdown before the HTTP server's own Shutdown, so blocking requests waiting on a job get their answer first.
func (*App) DropSSHKey ¶ added in v0.3.41
DropSSHKey stops serving a managed SSH key (LOOM-138): the key was deleted.
func (*App) HealthChecker ¶
HealthChecker returns the deep-health checker for api.Server to expose on /api/v1/health and /api/v1/health/deep (LOOM-105).
func (*App) LocalTargets ¶ added in v0.3.98
LocalTargets says whether this instance runs local targets at all (LOOM-141, LOOMUX_LOCAL_TARGETS).
func (*App) Machines ¶ added in v0.3.69
Machines serves the machine side of /api/v1/targets (LOOM-178): targets plugins made.
func (*App) Metrics ¶
Metrics returns the Prometheus metrics bundle so cmd/loomuxd can expose it on a scraper port (LOOM-103).
func (*App) Plugins ¶ added in v0.3.68
Plugins serves /api/v1/plugins (LOOM-178): the plugin system's catalog and installed instances.
func (*App) PrepareAgentSignIn ¶ added in v0.3.160
func (a *App) PrepareAgentSignIn(ctx context.Context, targetID, agentType string, restart bool) (*api.AgentSignInResult, error)
PrepareAgentSignIn opens agentType's sign-in on targetID for a person to attach to (LOOM-316) — see router.Router.PrepareSignIn. Satisfies api.AgentSignIns.
func (*App) ProbeTarget ¶
func (a *App) ProbeTarget(ctx context.Context, targetID string) (*registry.TargetHealth, []*registry.TargetAgent, error)
ProbeTarget probes a target's health and agent CLIs now and records the results (LOOM-86) — see router.Router.ProbeTarget. Satisfies api.TargetProber.
func (*App) ProvisionWorkspace ¶ added in v0.3.113
func (a *App) ProvisionWorkspace(ctx context.Context, req api.WorkspaceToProvision) (api.ProvisionedWorkspace, error)
ProvisionWorkspace provisions a workspace on a chosen target for POST /api/v1/workspaces (LOOM-215): the router writes the row and the run goes on in the background, on the app's own context, so Close waits for it (and, cancelling it, leaves the workspace failed with why). Satisfies api.WorkspaceProvisioner.
func (*App) ResolveSSHConfig ¶ added in v0.3.98
func (a *App) ResolveSSHConfig(ctx context.Context, t *registry.Target, keyFile string) (*targets.SSHConfigPlan, error)
ResolveSSHConfig plans t's migration to a managed target against this instance's SSH proxy (targets.ExecutorOptions.ResolveSSHConfig).
func (*App) RouterSettings ¶ added in v0.3.64
RouterSettings serves /api/v1/settings/router (LOOM-185): the router model's tiers as stored through Settings over the environment's, applied to the running model without a restart.
func (*App) ScanHostKey ¶ added in v0.3.98
ScanHostKey reads the host key t presents, reached the way this instance reaches it (targets.ExecutorOptions.ScanHostKey).
func (*App) SetWorkspaceStatus ¶
func (a *App) SetWorkspaceStatus(ctx context.Context, id string, status registry.WorkspaceStatus) error
SetWorkspaceStatus reopens (idle) or archives a workspace (LOOM-70) — see orchestrator.Orchestrator.ReopenWorkspace and ArchiveWorkspace. Satisfies api.WorkspaceManager.
func (*App) StartHoldSweeper ¶ added in v0.3.154
StartHoldSweeper starts the hold sweeper (LOOM-265, docs/design/tui-client-design.md "Expiry, crashes and restarts"): it first gives every hold a full lease from now, before it returns (so call it before the API serves), so the restart doesn't end the holds of clients still attached, then every orchestrator.HoldSweepInterval ends the holds whose lease ran out, whose session is gone or expired, or whose task ended, detaching a drive hold's tmux clients before handing its task back. sessionTTL and sessionMaxAge are the client API's session lifetime, as for StartRetention. Close stops it; only the first call starts it.
func (*App) StartRetention ¶ added in v0.3.74
StartRetention starts the retention sweep (LOOM-193): every retentionSweepInterval, and once now, it deletes sessions expired longer than Config.SessionRetention, dispatches finished longer than Config.DispatchRetention and confirmations resolved longer than Config.ConfirmationRetention. Messages are kept. sessionTTL and sessionMaxAge are the session lifetime the client API enforces (its sliding window and absolute lifetime, 0 for none), which say when a session expired. Close stops it; only the first call starts it.
func (*App) Store ¶
Store returns the underlying registry.Store — e.g. for api.Server's session storage, which must live in the same database as everything else rather than a second, separately managed connection.
func (*App) TaskHolds ¶ added in v0.3.148
func (a *App) TaskHolds() *orchestrator.Orchestrator
TaskHolds takes, renews and releases holds on tasks (LOOM-264): the orchestrator, whose Takeover, Heartbeat and Release satisfy api.TaskHolds.
func (*App) TmuxSocket ¶ added in v0.3.101
TmuxSocket is this instance's tmux socket (LOOM-93, LOOMUX_TMUX_SOCKET): what its executors run every session on and its attach commands name.
type Config ¶
type Config struct {
// DBPath is the SQLite database file path. Defaults to "loomux.db"
// in the working directory if unset — not a secret, so (unlike the
// fail-fast-on-malformed values below) a default is appropriate.
DBPath string
// MarkerDir is completion.NewDetector's marker file directory.
// Empty uses completion's own package default.
MarkerDir string
// TmuxSocket is the tmux socket name every session runs on
// (LOOMUX_TMUX_SOCKET); empty means targets.DefaultTmuxSocket. Give
// two instances driving the same targets different ones.
TmuxSocket string
// LocalTargetsOff (LOOMUX_LOCAL_TARGETS=off; the container image sets
// it) turns local targets off (LOOM-141): a local target's agents run
// as loomuxd's own user, so they're fully trusted. The zero value
// leaves them on. See targets.ExecutorOptions.LocalTargetsOff.
LocalTargetsOff bool
// MasterKey is the credential vault's AES-256 key, or nil if
// LOOMUX_MASTER_KEY is unset. Optional at this layer: registry/sqlite
// already fails fast on any credential operation that actually needs
// it, rather than this process refusing to start without one.
MasterKey []byte
// SSHProxy is the SOCKS5 proxy (host:port) managed targets are
// reached through unless they opt out (LOOMUX_SSH_PROXY, as
// socks5://host:port; LOOM-138); "" for none.
SSHProxy string
// Router is the LLM-backed RoutingModel's own configuration.
Router llmrouter.Config
// ReapIdleThreshold is how long a task can go without a state change
// (design spec's continuation model, LOOM-16 — see
// orchestrator.Reaper's doc comment for exactly what "idle" means)
// before its session is torn down. Zero means "unset" — build applies
// defaultReapIdleThreshold, the same way LoadConfig does; existing
// callers that construct Config directly (tests) get sensible
// behavior without needing to set every field.
ReapIdleThreshold time.Duration
// ReapIdleOff turns idle reaping off (LOOMUX_REAP_IDLE_THRESHOLD
// "off" or "0", LOOM-227): no session is closed for waiting, however
// long. The sweep's other work (retention, stuck provisioning) runs.
ReapIdleOff bool
// ReapInterval is how often the idle reaper sweeps. Same zero-means-
// default handling as ReapIdleThreshold.
ReapInterval time.Duration
// TargetProbeInterval is how often every target's health is probed
// (LOOM-86). Same zero-means-default handling as ReapIdleThreshold.
TargetProbeInterval time.Duration
// MachineIdleStop stops a persistent machine a plugin created once
// it has been idle this long (LOOMUX_MACHINE_IDLE_STOP, LOOM-177);
// the next dispatch to it starts it again. Zero, the default, never
// stops one.
MachineIdleStop time.Duration
// Logger receives the router's structured records (LOOM-63). Nil —
// as in tests that construct Config directly — means nothing is
// logged; LoadConfig always sets one.
Logger *slog.Logger
// AgentProfiles overrides agent-types' launch profiles (LOOM-78):
// permission/sandbox args, workspace pre-trust, first prompt as an
// argument. Keyed by agent-type name. Nil keeps every default (see
// agents/README.md); naming an unregistered agent-type fails Build.
AgentProfiles map[string]router.ProfileOverride
// DispatchMaxDuration bounds one dispatch job end to end (LOOM-80).
// Zero means the dispatch package's own default.
DispatchMaxDuration time.Duration
// DispatchDrain is how long shutdown lets in-flight dispatch jobs
// finish before marking them interrupted (LOOM-80). Zero means
// defaultDispatchDrain.
DispatchDrain time.Duration
// Notify configures turn notifications (LOOM-102); off when
// Notify.NtfyURL is empty.
Notify NotifyConfig
// TurnRetention is how long each task turn's transcript is kept
// (LOOM-122); zero keeps them. LoadConfig defaults it to
// defaultTurnRetention.
TurnRetention time.Duration
// EventRetention is how long the dispatch audit trail is kept
// (LOOM-110); zero keeps it. LoadConfig defaults it to
// defaultEventRetention.
EventRetention time.Duration
// PluginBundleDir, PluginDir and PluginSocketDir are where plugins
// are found (LOOM-178, docs/design/target-providers.md §1.8): the
// image's bundled plugins, the operator's, and sidecars' sockets.
// An empty PluginDir means plugins/ beside the database; the other
// two empty mean nothing is looked for there.
PluginBundleDir string
PluginDir string
PluginSocketDir string
// PluginsSeed is LOOMUX_PLUGINS_SEED parsed: plugin instances the
// deployment declares (LOOM-219, plugins/seed.go); nil for none.
// PluginsSeedDryRun (LOOMUX_PLUGINS_SEED_DRY_RUN) only logs what it
// would do.
PluginsSeed *plugins.Seed
PluginsSeedDryRun bool
// PluginDigests and PluginSigners vouch for plugins from the plugin
// directory (LOOM-218, plugins/attest): executable digests the
// operator pinned (LOOMUX_PLUGIN_DIGESTS, "sha256:<hex>"), and the
// signing workflows whose Sigstore build provenance is trusted
// (LOOMUX_PLUGIN_SIGNERS), verified against PluginTrustedRoot
// (LOOMUX_PLUGIN_TRUSTED_ROOT, a Sigstore trusted_root.json; empty
// for Sigstore's public-good root). PluginAllowUnsigned
// (LOOMUX_PLUGIN_ALLOW_UNSIGNED) lets unverified ones be installed:
// for local development.
PluginDigests []string
PluginSigners []string
PluginTrustedRoot string
PluginAllowUnsigned bool
// SessionRetention is how long a session row is kept after it
// expired, DispatchRetention how long a dispatch is kept after it
// finished, and ConfirmationRetention how long a confirmation is kept
// after it was answered or expired (LOOM-193), which is also how
// long an ended task hold is kept (LOOM-263); zero keeps them.
// LoadConfig defaults them to defaultSessionRetention,
// defaultDispatchRetention and defaultConfirmationRetention. Messages
// are kept.
SessionRetention time.Duration
DispatchRetention time.Duration
ConfirmationRetention time.Duration
// contains filtered or unexported fields
}
Config is the process configuration, loaded from environment variables (this repo's established convention — see registry/sqlite.KeyFromEnv, router/llmrouter.ConfigFromEnv).
func LoadConfig ¶
LoadConfig reads Config from the environment, failing fast on malformed (as opposed to merely absent) values — an unset LOOMUX_MASTER_KEY is fine (MasterKey stays nil); an invalid one is not.
type NotifyConfig ¶
type NotifyConfig struct {
// NtfyURL is the ntfy server ("https://ntfy.sh"), NtfyTopic the topic
// posted to and NtfyToken an optional access token. An empty NtfyURL
// turns notifications off.
NtfyURL, NtfyTopic, NtfyToken string
// Events are the kinds notified ("done", "failed", "needs_you").
Events map[notify.Kind]bool
// MinDuration skips turns shorter than this: the user was likely
// still watching.
MinDuration time.Duration
// PublicURL is where the web client is served, for each
// notification's link to its conversation; empty means no link.
PublicURL string
}
NotifyConfig configures turn notifications (LOOM-102).