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) Close() error
- func (a *App) DeleteWorkspace(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) HealthChecker() *health.Checker
- func (a *App) Metrics() *metrics.Metrics
- func (a *App) ProbeTarget(ctx context.Context, targetID string) (*registry.TargetHealth, []*registry.TargetAgent, error)
- func (a *App) RefreshTargetAgents(ctx context.Context, targetID string) ([]*registry.TargetAgent, error)
- func (a *App) SetWorkspaceStatus(ctx context.Context, id string, status registry.WorkspaceStatus) error
- func (a *App) Store() registry.Store
- 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) Close ¶
Close stops the background idle reaper (LOOM-16) and releases the store's resources (its DB connection).
func (*App) DeleteWorkspace ¶
DeleteWorkspace deletes a workspace, its tasks and their sessions (LOOM-70) — see orchestrator.Orchestrator.DeleteWorkspace. Satisfies api.WorkspaceManager.
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) 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) Metrics ¶
Metrics returns the Prometheus metrics bundle so cmd/loomuxd can expose it on a scraper port (LOOM-103).
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) RefreshTargetAgents ¶
func (a *App) RefreshTargetAgents(ctx context.Context, targetID string) ([]*registry.TargetAgent, error)
RefreshTargetAgents re-probes a target for every agent CLI with a declared Binary and records the results (LOOM-71) — see router.Router.RefreshTargetAgents. Satisfies api.AgentProber.
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.
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
// 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
// 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
// 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
// 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
}
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).