launch

package
v0.16.42 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 19 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppsJSON added in v0.16.42

func AppsJSON(ids []string) []any

AppsJSON is a launch's apps as the tab meta keeps them.

func AppsOf added in v0.16.42

func AppsOf(o *jsvalue.Object) []string

AppsOf reads the apps a tab's launch keeps.

func PromptTimestamp

func PromptTimestamp(line string) float64

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

func ResolveCwd(requested, workspaceRoot string, extraRoots []string) (string, error)

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
}

Config is what the starter works with.

type Delivery

type Delivery struct {
	TabID, SessionName, AgentSessionID, Cwd string
	Message                                 string
}

Delivery is a comment and where its document came from.

type EnvEntry

type EnvEntry struct {
	Key   string
	Value any
}

EnvEntry is one entry of a requested environment, as the request held it (a value that is not a string is refused).

type Headline

type Headline struct {
	Title        *string
	LastPromptAt *float64
}

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.

func (*Headlines) Read

func (h *Headlines) Read(path string) Headline

Read is the headline of a transcript. It reads back from the end in growing steps until a prompt and a title turn up (Codex writes no titles, so only a prompt is looked for there); the last line, perhaps still being written, waits for the next call.

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

func (b *Inbox) Deliver(in Delivery) (*jsvalue.Object, error)

Deliver types or queues the message, or reopens the conversation; {mode, tabId}.

func (*Inbox) Flush

func (b *Inbox) Flush()

Flush tries the head of every tab's queue once: one message per tick, as the paste makes the agent busy.

func (*Inbox) ResolvePane

func (b *Inbox) ResolvePane(paneID, socket string) *jsvalue.Object

ResolvePane is the tab of this runtime a publishing shell's pane id belongs to. One id may name a pane on each tmux server; the one running an agent is the publisher, and socket settles it outright.

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

type Result struct {
	OK           bool
	Status       int
	Body         *jsvalue.Object
	Conversation *jsvalue.Object
}

Result is what a start answered: the conversation, or the status and body of a refusal.

func (Result) ConversationID

func (r Result) ConversationID() string

ConversationID is the started conversation's id, "" for a refusal.

func (Result) JSON

func (r Result) JSON() *jsvalue.Object

JSON is the result as the platform's routes exchange it: {ok, conversation} or {ok, status, body}.

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 New

func New(cfg Config) *Starter

New is a starter over cfg.

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

func (s *Starter) Conversations(h *Headlines, created func(session string) int64) *jsvalue.Object

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

func (s *Starter) Start(o Options) (Result, error)

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.

type Target

type Target struct {
	WorkspaceID, TabID, TmuxSession, SessionID, Provider string
	Launch                                               *agents.Launch
}

Target is an agent tab to resume.

Jump to

Keyboard shortcuts

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