Documentation
¶
Overview ¶
Package orca is a visor backend for the terminals of Orca on this machine. A session is an agent in an Orca terminal. Orca owns the terminal, so the session lives through a visor restart. The backend reads the agent state from the Orca agent cards. It has no typed events: it answers a permission prompt through the screen.
Index ¶
- Constants
- func FindCLI() (path string, ok bool)
- func HookLabels(getenv func(string) string) map[string]string
- func IsCode(err error, code string) bool
- type Agent
- type Backend
- func (b *Backend) Adopt(_ context.Context, s agentvisor.Session, pane string) (agentvisor.Handle, error)
- func (b *Backend) Binding(session string) (pane, terminal, worktree string, ok bool)
- func (b *Backend) CLI() *CLI
- func (b *Backend) Caps(string) agentvisor.Caps
- func (b *Backend) Close(context.Context) error
- func (b *Backend) Folders(ctx context.Context) ([]string, error)
- func (b *Backend) Found() <-chan agentvisor.Found
- func (b *Backend) Kind() agentvisor.Kind
- func (b *Backend) Recover(context.Context) ([]agentvisor.Handle, error)
- func (b *Backend) Start(ctx context.Context, l agentvisor.Launch) (agentvisor.Handle, error)
- type CLI
- func (c *CLI) Close(ctx context.Context, handle string) error
- func (c *CLI) CreateTerminal(ctx context.Context, worktree, title, command string) (Terminal, error)
- func (c *CLI) EnsureWorkspace(ctx context.Context, w WorkspaceSpec, shellWait time.Duration) (Workspace, error)
- func (c *CLI) Line(ctx context.Context, handle, text string) error
- func (c *CLI) Reachable(ctx context.Context) bool
- func (c *CLI) Repos(ctx context.Context) ([]Repo, error)
- func (c *CLI) Screen(ctx context.Context, handle string) ([]string, error)
- func (c *CLI) Show(ctx context.Context, handle string) (Terminal, error)
- func (c *CLI) Submit(ctx context.Context, handle, text string) (bool, error)
- func (c *CLI) Tail(ctx context.Context, handle string, lines int) ([]string, error)
- func (c *CLI) Terminals(ctx context.Context) ([]Terminal, error)
- func (c *CLI) Type(ctx context.Context, handle, text string) error
- func (c *CLI) WaitIdle(ctx context.Context, handle string) (bool, error)
- func (c *CLI) Worktrees(ctx context.Context) ([]Worktree, error)
- type Error
- type ExecRunner
- type Options
- type Repo
- type Runner
- type Terminal
- type Workspace
- type WorkspaceSpec
- type Worktree
Constants ¶
const ( // LabelPane is the Orca pane (tabId:leafId). A hook call with it finds // the session. LabelPane = "orca.pane" // LabelTerminal is the Orca terminal handle. LabelTerminal = "orca.terminal" // LabelWorktree is the Orca worktree id. In a start spec, the terminal // opens in this worktree. LabelWorktree = "orca.worktree" // LabelShell is a terminal handle in a start spec. The agent command goes // into this shell, and no new terminal opens. LabelShell = "orca.shell" )
The labels of an Orca session. The backend puts them on each session, and a start spec can set LabelWorktree and LabelShell.
const ( AgentWorking = "working" AgentWaiting = "waiting" AgentBlocked = "blocked" AgentDone = "done" )
The agent states of Orca.
const EnvPane = "ORCA_PANE_KEY"
Env names of the hook process in an Orca terminal.
const Kind agentvisor.Kind = "orca"
Kind is the session kind of this backend.
const MacPath = "/Applications/Orca.app/Contents/Resources/bin/orca"
MacPath is the Orca CLI in the Orca app on macOS.
Variables ¶
This section is empty.
Functions ¶
func FindCLI ¶
FindCLI gives the Orca CLI of the app on macOS, else orca on PATH. ok is false when there is none.
func HookLabels ¶
HookLabels gives the labels of a hook call from the env of the hook process. They are nil outside an Orca terminal.
Types ¶
type Agent ¶
type Agent struct {
PaneKey string `json:"paneKey"`
State string `json:"state"` // working, waiting, blocked, done
WorkingMode string `json:"workingMode"` // "monitoring" when only a background shell runs
AgentType string `json:"agentType"`
Prompt string `json:"prompt"`
LastAssistantMessage string `json:"lastAssistantMessage"`
ToolName string `json:"toolName"`
ToolInput string `json:"toolInput"`
Interrupted bool `json:"interrupted"`
StateStartedAt int64 `json:"stateStartedAt"`
UpdatedAt int64 `json:"updatedAt"`
MainAgent *struct {
State string `json:"state"`
StateStartedAt int64 `json:"stateStartedAt"`
} `json:"mainAgent"`
}
Agent is one agent pane of a workspace. The times are Unix milliseconds.
func (Agent) Effective ¶
Effective gives the agent with a stale monitoring state replaced by the state of the main agent. A real background shell starts in the turn, so its monitoring state starts before the main agent finishes. Orca can go to monitoring after the turn with no shell, for example on a recap.
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend hosts agent sessions in Orca terminals.
func (*Backend) Adopt ¶
func (b *Backend) Adopt(_ context.Context, s agentvisor.Session, pane string) (agentvisor.Handle, error)
Adopt binds the found pane to the visor session s.
func (*Backend) Caps ¶
func (b *Backend) Caps(string) agentvisor.Caps
Caps has no typed events and no structured permissions: the backend answers a prompt through the screen.
func (*Backend) Found ¶
func (b *Backend) Found() <-chan agentvisor.Found
Found gives the agents that the visor did not start, when Options.Discover is set.
func (*Backend) Kind ¶
func (b *Backend) Kind() agentvisor.Kind
func (*Backend) Recover ¶
Recover gives a handle for each stored binding. The poll ends the handles whose terminal is gone.
func (*Backend) Start ¶
func (b *Backend) Start(ctx context.Context, l agentvisor.Launch) (agentvisor.Handle, error)
Start opens a terminal in Orca and runs the agent command in it. Then it waits until the agent is idle and sends the first prompt.
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI calls the Orca CLI of this machine. Each call has an argument array and --json. No call has --environment: the CLI talks only to the local Orca.
func (*CLI) CreateTerminal ¶
func (c *CLI) CreateTerminal(ctx context.Context, worktree, title, command string) (Terminal, error)
CreateTerminal opens a terminal in the worktree selector and runs command.
func (*CLI) EnsureWorkspace ¶
func (c *CLI) EnsureWorkspace(ctx context.Context, w WorkspaceSpec, shellWait time.Duration) (Workspace, error)
EnsureWorkspace finds the workspace with the name in the repo, or makes it. A new workspace runs the Orca setup of the repo.
func (*CLI) Submit ¶
Submit sends text as a prompt to the agent in the terminal. It is true when the agent started a turn on it.
type Options ¶
type Options struct {
// CLI is the Orca CLI. Nil uses FindCLI.
CLI *CLI
// Dir keeps the session bindings and the launch scripts.
Dir string
// Poll is the time between two reads of the Orca state. Zero is 2 s.
Poll time.Duration
// Command gives the command of an agent session. Nil runs the harness
// program with the model args and the extra args. A resume needs it.
Command agentvisor.TerminalCommand
// Discover reports the agents that the visor did not start, for example
// the agents that the user started in Orca.
Discover bool
// ShellWait is the pause between two looks for the first shell of a new
// workspace. Zero is 300 ms.
ShellWait time.Duration
Logger *slog.Logger
}
Options configures the backend.
type Repo ¶
type Repo struct {
ID string `json:"id"`
Path string `json:"path"`
DisplayName string `json:"displayName"`
Kind string `json:"kind"` // git or folder
}
Repo is one repo of `orca repo list`.
type Runner ¶
type Runner interface {
Run(ctx context.Context, exe string, args []string) (stdout, stderr []byte, err error)
}
Runner runs one child process.
type Terminal ¶
type Terminal struct {
Handle string `json:"handle"`
WorktreeID string `json:"worktreeId"`
WorktreePath string `json:"worktreePath"`
TabID string `json:"tabId"`
LeafID string `json:"leafId"`
Key string `json:"paneKey"`
RecordedPaneKey string `json:"recordedPaneKey"`
Title string `json:"title"`
AgentIdentity string `json:"agentIdentity"`
Orphaned bool `json:"orphaned"`
Connected bool `json:"connected"`
}
Terminal is one terminal of `orca terminal list`, `create`, or `show`.
type Workspace ¶
Workspace is a workspace that EnsureWorkspace found or made. Shell is the first shell of a new workspace, or empty.
type WorkspaceSpec ¶
type WorkspaceSpec struct {
// Repo is the path of the repo in Orca.
Repo string
Name string
// BaseBranch and Comment apply to a new workspace.
BaseBranch string
Comment string
}
WorkspaceSpec names a workspace to find or make in a repo.
type Worktree ¶
type Worktree struct {
ID string `json:"worktreeId"`
RepoID string `json:"repoId"`
Repo string `json:"repo"`
Path string `json:"path"`
Branch string `json:"branch"`
DisplayName string `json:"displayName"`
Comment string `json:"comment"`
IsArchived bool `json:"isArchived"`
IsMain bool `json:"isMainWorktree"`
Agents []Agent `json:"agents"`
}
Worktree is one workspace of `orca worktree ps`.
func (Worktree) BranchName ¶
BranchName is Branch without refs/heads/.