layoutapi

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layoutapi answers the core slice's routes over layouts, workspaces, the CLIs' tab commands and the right pane's bridges, the way the previous runtime's API answered them: its route table and precedence, its sign-in check, its body parsing (1 MB, "Invalid JSON", 413), its JSON with ETag and 304, and each handler's statuses and texts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agents

type Agents interface {
	// Availability is nil when the agent of panelType (if any) can run.
	Availability(panelType string) *Unavailable
	// ValidateLaunch checks a requested model and effort against what the CLI offers; the text is the 400 error.
	ValidateLaunch(provider string, model, effort any) (*agents.Launch, string)
	LaunchLine(provider, workspaceID string, launch *agents.Launch) (string, error)
	ResumeLine(provider, sessionID, workspaceID string, launch *agents.Launch) (string, error)
	Start(StartRequest) StartResult
	// RememberStates keeps each agent tab's state as it is before a reset ends the sessions: once they are gone the
	// status keeper settles a working tab to idle, and AutoResume would take it for a quiet one.
	RememberStates()
	// AutoResume starts again the agents that ran before a reset.
	AutoResume()
}

Agents is what the routes need of the agent CLIs: availability, launch lines and starting a conversation.

type DelegateRefused

type DelegateRefused struct{ Msg string }

DelegateRefused is a delegation the machine refused (too many chats, too deep, an unknown model): the person's limits, not a reason to start a loose tab instead.

func (*DelegateRefused) Error

func (e *DelegateRefused) Error() string

type DelegateRequest

type DelegateRequest struct {
	// Session is the tmux session of the terminal the command ran in; the chat that asks is the one that runs there.
	Session  string
	Provider string
	Model    string
	Profile  string // a backend profile of the provider (GitHub #109)
	Effort   string
	Prompt   string
	Title    string
	Notify   bool
	Test     bool
}

DelegateRequest is an agent tab with a first message, asked for by an agent of a chat: the chat the work is handed to is nested under the chat that asks (internal/delegation), as the MCP tool delegate_task makes it.

type DelegateResult

type DelegateResult struct {
	ChatID, ParentID, Provider, Model string
}

DelegateResult is the nested chat that was started.

type Deps

type Deps struct {
	// Browser calls the same conversation-bound tools as MCP after the CLI guard succeeds. It gets the tmux session the
	// command names, because a chat's id is not the id of its tab.
	Browser func(*http.Request, string, string, *jsvalue.Object) *jsvalue.Object
	Store   *state.Store
	Tmux    Tmux
	Status  Status
	Agents  Agents
	// Delegate starts the first message of an agent tab as a chat nested under the chat of the asking terminal; nil, or
	// an *ErrNoParent, leaves the tab to be made the old way.
	Delegate func(context.Context, DelegateRequest) (DelegateResult, error)
	// ChatTab is the layout tab a chat runs in ("" while it has none): a chat's id is not the id of its tab, and the CLI
	// names a delegated chat by its own id.
	ChatTab func(chatID string) string
	Sync    Sync
	Intents *paneintents.Store
	Panel   *panel.Bridge
	Vault   *vault.Bridge
	Targets panel.Targets
	// Deliver reads a file the agent hands over (the rules of the files the pane opens); nil: the machine delivers nothing.
	Deliver func(path, title string) (delivery.Info, *delivery.Refusal)
	// Session: the request carries a page session; CLIToken: it carries the runtime's cli-token (the first token
	// header present decides).
	Session  func(*http.Request) bool
	CLIToken func(*http.Request) bool
	// PlatformAPI is the prefix of the platform's own routes (state-changed, pane-shell, pane intents, bridges).
	PlatformAPI string
	Home        string
	// ShellReady is how long a new tab's shell gets before a resume line is typed (500 ms).
	ShellReady time.Duration
	// PanelWait is how long a pane command waits for a page (1.5 s).
	PanelWait time.Duration
}

Deps is everything the routes use. Status and Agents may be nil until they exist: tabs are then not registered, every agent counts as available and a conversation start is refused.

type ErrNoParent

type ErrNoParent struct{ Reason string }

ErrNoParent says the command did not run in the terminal of a chat, so there is no chat to nest the new one under; the tab is then made the old way, and Reason is told to the caller.

func (*ErrNoParent) Error

func (e *ErrNoParent) Error() string

type Launch

type Launch struct {
	Starter   *launch.Starter
	Inbox     *launch.Inbox
	Headlines *launch.Headlines
	// MachineAgent: the request is the machine agent's own (loopback, its session).
	MachineAgent func(*http.Request) bool
	// SessionCreated is a tmux session's start, epoch seconds (0 when unknown).
	SessionCreated func(session string) int64
	// CodexArgs are the arguments the Codex launcher gets for codex itself.
	CodexArgs func(workspaceID, resumeID string, launch *agents.Launch) (codex.Start, error)
	// CodexInput: new Codex chats may start beside an app-server (the structured input channel), so the launcher's
	// conversation is passed on to the arguments of a fresh launch without apps.
	CodexInput bool
	// CodexForkArgs are the arguments that start codex on a fork of a session; nil when the runtime cannot fork.
	CodexForkArgs func(workspaceID, sessionID string, launch *agents.Launch) (codex.Start, error)
	// EvalRuns holds eval runs (<runId>/request.json, state.json, stop); EvalRunner is the runner script, run by Node
	// detached ("" or missing: this release has none).
	EvalRuns, EvalRunner, Node string
	// SideChat* find a tab's Claude session and run the fork.
	SideChatRuntime string
	Sources         func() []status.AgentSource
	ProjectDir      func(cwd string) string
	Log             func(level, msg string, kv ...any)
	// FromApp says whether the app that starts a chat for the person (from.app) is turned on in that chat: installed by
	// the person and working in a chat. Its tools then reach the agent, so the task it handed over can report back to it
	// nil: no app is turned on this way.
	FromApp func(id string) bool
}

Launch is what the launch slice's routes use besides Deps: the starter and document inbox, the Codex launch lines, eval runs and side chats.

type Route

type Route struct {
	Match   func(*http.Request) bool
	Handler http.Handler
}

Route is one gate route: Match the paths, Handler the answer.

func LaunchRoutes

func LaunchRoutes(d *Deps, l *Launch) (main, shadow Route)

LaunchRoutes are the launch slice's routes: starting conversations, documents, evals, side chats and Codex lines.

func Routes

func Routes(d *Deps) (main, shadow Route)

Routes are the answering route and the route of the GETs that may run in the shadow.

type StartRequest

type StartRequest struct {
	Provider, WorkspaceID string
	Prompt                any // string or nil
	Launch                *agents.Launch
	TabName               any // string or nil
}

StartRequest starts an agent conversation the platform's way (launch line, hooks, prompt).

type StartResult

type StartResult struct {
	ConversationID string
	Status         int
	Body           []byte
}

StartResult is the started conversation, or the status and JSON body of the refusal.

type Status

type Status interface {
	RegisterTab(tabID string, e TabEntry)
	RemoveTab(tabID string)
	MarkAgentLaunch(tabID string, resetAgentSession bool)
	// HooksMissing: the tab's agent was started without the platform's hooks.
	HooksMissing(tabID string) bool
	// AgentTab is the agent tab (Claude Code or Codex) whose tmux session this is, "" for none.
	AgentTab(tmuxSession string) string
	// Rescan rebuilds the tab statuses after a tmux reset.
	Rescan()
}

Status is the status keeper.

type Sync

type Sync interface {
	Broadcast(event *jsvalue.Object)
	ClientCount() int
}

Sync is the sync socket: an event to every page, and how many sockets are open (the agent's relay included).

type TabEntry

type TabEntry struct {
	CliState, WorkspaceID, TabName, TmuxSession string
	PanelType                                   any
	AgentProviderID                             string // "" for a tab without an agent
	AgentSessionID                              any
}

TabEntry is what the status keeper learns of a new tab.

type Tmux

type Tmux interface {
	HasSession(name string) bool
	Capture(name string) (string, bool)
	SendKeys(name, line string) error
	SendBracketedPaste(name, text string) error
	SendKeySequence(name string, keys ...string) error
	PaneCurrentCommand(name string) string
	CheckTerminalProcess(name string) (safe bool, process string)
	ListSessions() []string
	KillServer()
	ApplyConfig(socket string)
	CreateSession(name string, cols, rows int, cwd string) error
	KillSession(name string)
	PaneShellName(tabID string, legacy bool) (string, bool)
	SessionCwd(name string) string
	// CwdAndLastCommand is the session's folder and the newest command its shell runs (nil for none).
	CwdAndLastCommand(name string) (string, *string)
	ResolveExistingDir(preferred string) string
}

Tmux is what the routes ask of tmux beyond the stores. FromTmux adapts the runtime's own.

func FromTmux

func FromTmux(t *tmux.Tmux) Tmux

FromTmux is the runtime's tmux layer as the routes use it.

type Unavailable

type Unavailable = agents.Unavailable

Unavailable is why an agent CLI cannot start: the 409 answer.

Jump to

Keyboard shortcuts

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