Documentation
¶
Overview ¶
Package launch starts and resumes agent conversations the platform's way: a tab in a workspace's first pane, the agent CLI's launch line with its environment and initial prompt typed into it, the tab's metadata, and the keeper told that a launch is under way. It also resumes, after a restart or a tmux reset, the agents that were working, and delivers a person's document comments to the conversation a document is bound to.
Index ¶
- func AppsJSON(ids []string) []any
- func AppsOf(o *jsvalue.Object) []string
- func PromptTimestamp(line string) float64
- func ResolveCwd(requested, workspaceRoot string, extraRoots []string) (string, error)
- func UnavailableBody(u *agents.Unavailable) *jsvalue.Object
- type Config
- type Delivery
- type EnvEntry
- type Headline
- type Headlines
- type Inbox
- type InboxTmux
- type Keeper
- type Lines
- type Options
- type Result
- type ResumeConfig
- type ResumeTmux
- type Starter
- func (s *Starter) AutoResume(rc ResumeConfig) int
- func (s *Starter) Conversations(h *Headlines, created func(session string) int64) *jsvalue.Object
- func (s *Starter) ExecuteResume(rc ResumeConfig, targets []Target)
- func (s *Starter) RememberStartStates()
- func (s *Starter) ResumeTargets(rc ResumeConfig) []Target
- func (s *Starter) Start(o Options) (Result, error)
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PromptTimestamp ¶
PromptTimestamp is the time of a prompt the person typed on a Claude Code or Codex transcript line; NaN for any other line (tool results, meta, command echoes).
func ResolveCwd ¶
ResolveCwd checks an explicit launch folder: absolute, existing, a folder, and inside workspaceRoot or one of extraRoots once symlinks are resolved. The error is the message for the caller.
func UnavailableBody ¶
func UnavailableBody(u *agents.Unavailable) *jsvalue.Object
UnavailableBody is the 409 body of an agent CLI that cannot run.
Types ¶
type Config ¶
type Config struct {
Store *state.Store
Lines Lines
// Availability is nil when the agent of a panel type can run.
Availability func(panelType string) *agents.Unavailable
// Keeper is the running keeper; nil while there is none.
Keeper func() Keeper
// WorkspaceRoot is the machine's project root ("" when the deployment names none): new conversations start there,
// and an explicit launch folder must lie inside it.
WorkspaceRoot string
// Home is where a first workspace is made without a project root.
Home string
// DataDir holds the instruction files a launch may add; DataDirLabel names it in messages (`~/.<name>`).
DataDir, DataDirLabel string
// EnvPrefix starts every variable a launch may set (`<prefix>NAME='value' ` before the line).
EnvPrefix string
// EnvSource gives what goes before a provider's whole command so the CLI starts with the keys, secrets and proxy a
// hub left in the machine's env files (agents.EnvSourcePrefix); nil, or "", adds nothing.
EnvSource func(provider string) string
// PromptDir takes a prompt too long to type, read back and removed by the launch line.
PromptDir string
// FirstWorkspaceName names the workspace made for a machine that has none.
FirstWorkspaceName string
// Now is the clock in epoch milliseconds.
Now func() float64
// ShellReady is how long new tmux sessions get before a resume line is typed (500 ms).
ShellReady time.Duration
// Admit is the reason a new conversation of the provider may not start (a limit of the hub, see internal/budget);
// nil, or "", lets it start.
Admit func(provider string, launch *agents.Launch) string
}
Config is what the starter works with.
type EnvEntry ¶
EnvEntry is one entry of a requested environment, as the request held it (a value that is not a string is refused).
type Headline ¶
Headline is a transcript's last AI title and when the person last typed a prompt (epoch ms); nil when not found.
type Headlines ¶
type Headlines struct {
// contains filtered or unexported fields
}
Headlines reads transcript headlines, each file's bytes once: a call reads only what was appended since the last.
type Inbox ¶
type Inbox struct {
Starter *Starter
Tmux InboxTmux
// Submit types a text into a Claude pane and submits it.
Submit func(session, text string) error
Log func(level, msg string, kv ...any)
// Every is how often queued messages are tried (3 s); MaxWait how long one may wait for its tab (6 h).
Every, MaxWait time.Duration
Now func() time.Time
// contains filtered or unexported fields
}
Inbox types a person's document comments into the conversation the document is bound to: at once when the agent is idle, after its turn when busy, into a resumed copy of the session when the tab is gone.
func (*Inbox) Deliver ¶
Deliver types or queues the message, or reopens the conversation; {mode, tabId}.
type InboxTmux ¶
type InboxTmux interface {
HasSession(name string) bool
// SessionsOfPane are the sessions a pane id names (on socket, or on every server when "").
SessionsOfPane(paneID, socket string) []string
SessionCwd(name string) string
}
InboxTmux is what document delivery asks of tmux.
type Keeper ¶
type Keeper interface {
RegisterTab(tabID string, e status.Entry)
MarkAgentLaunch(tabID string, reset bool)
AgentSources() []status.AgentSource
}
Keeper is the running tab keeper.
type Lines ¶
type Lines interface {
// Launch starts a new conversation; promptFiles go into Claude's system prompt after the workspace's.
Launch(provider, workspaceID string, launch *agents.Launch, promptFiles []string) (string, error)
Resume(provider, sessionID, workspaceID string, launch *agents.Launch) (string, error)
// Fork starts the agent on a fork of a session its CLI makes: a session of its own with the other's history.
Fork(provider, sessionID, workspaceID string, launch *agents.Launch) (string, error)
}
Lines are the agent CLIs' launch lines.
type Options ¶
type Options struct {
Provider string
WorkspaceID string
// Prompt is the first message; nil for none.
Prompt *string
// Launch is the checked model and effort; nil or both nil is "Auto".
Launch *agents.Launch
// Cwd is an explicit launch folder: it must exist and lie inside the project root or one of CwdRoots.
Cwd string
CwdRoots []string
Env []EnvEntry
// ResumeSessionID reopens a saved session instead (no initial prompt then).
ResumeSessionID string
// ForkSession starts the agent on a fork of ResumeSessionID instead, a session of its own the agent names.
ForkSession bool
// PromptFiles are instruction files under DataDir (Claude only).
PromptFiles []string
// Meta goes into the tab's metadata next to the launch (the conversation's mode).
Meta *jsvalue.Object
// TabName names the tab; nil or blank names it after the agent.
TabName *string
}
Options say what to start.
type Result ¶
Result is what a start answered: the conversation, or the status and body of a refusal.
func (Result) ConversationID ¶
ConversationID is the started conversation's id, "" for a refusal.
type ResumeConfig ¶
type ResumeConfig struct {
Tmux ResumeTmux
// Installed is the preflight of an agent CLI: whether it runs, and (for the log) whether its binary was found off PATH.
Installed func(provider string) (installed, binaryFound bool)
// LastActivity is when a conversation last moved (epoch ms), nil when unknown.
LastActivity func(provider, sessionID string) *float64
Sleep sleep.Config
// ChildPIDs and Cmdline read the processes under a pane.
ChildPIDs func(pid int) []int
Cmdline func(pid int) (string, bool)
Log func(level, msg string, kv ...any)
}
ResumeConfig is what the startup resume reads besides the starter's stores.
type ResumeTmux ¶
type ResumeTmux interface {
HasSession(name string) bool
CreateSession(name string, cols, rows int, cwd string) error
PaneCurrentCommand(name string) string
PanePID(name string) int
SendKeysSeparated(name, text string) error
}
ResumeTmux is what the startup resume asks of tmux.
type Starter ¶
type Starter struct {
// contains filtered or unexported fields
}
Starter starts conversations.
func (*Starter) AutoResume ¶
func (s *Starter) AutoResume(rc ResumeConfig) int
AutoResume finds the targets and resumes them in the background; it answers how many there are.
func (*Starter) Conversations ¶
Conversations lists the agent and terminal conversations of every workspace: titles from the transcripts, ordered by the person's last prompt or, without one, the tmux session's birth. created reads a session's start (epoch s, 0 when unknown).
func (*Starter) ExecuteResume ¶
func (s *Starter) ExecuteResume(rc ResumeConfig, targets []Target)
ExecuteResume makes the targets' missing tmux sessions one after another (the first one starts the server), gives their shells a moment once, then types the resume lines in parallel.
func (*Starter) RememberStartStates ¶ added in v0.15.46
func (s *Starter) RememberStartStates()
RememberStartStates keeps each agent tab's state as the last run left it, for the next ResumeTargets. Call it before the status keeper starts: a turn that was running is settled to idle as soon as the keeper sees no agent in its pane, which after a restart it never does, and the resume would then take the working agent for a quiet one.
func (*Starter) ResumeTargets ¶
func (s *Starter) ResumeTargets(rc ResumeConfig) []Target
ResumeTargets are the agent tabs to resume at startup: only conversations that were working or were touched recently. A machine that resumed forty tabs at boot ran out of memory; the others stay chats, resumed by their next prompt.
func (*Starter) Start ¶
Start starts a Claude or Codex conversation in a new tab of the workspace's first pane. Everything typed into the shell is checked before a tab or workspace is made: the environment, then the launch line, then the prompt. An error is a failure the old runtime answered with a bare 500.