Documentation
¶
Overview ¶
Package workspace is the port between the loop and the workspace managers, the tools that host worktrees and agent sessions: Orca and Claude Desktop.
Index ¶
- Constants
- Variables
- func Capability[T any](m Manager) (T, bool)
- func DefaultMaxAge(fast time.Duration) map[wsdomain.Part]time.Duration
- func Honors(m Manager, needs LaunchNeeds) error
- func Invalidate(m Manager, parts wsdomain.Part)
- func LinkedPR(u unit.Unit) int
- type AgentIdentifier
- type AppProbe
- type BlockedError
- type Board
- type Cache
- func (c *Cache) Invalidate(p wsdomain.Part)
- func (c *Cache) Last() *wsdomain.Snapshot
- func (c *Cache) OnChange(fn func(s *wsdomain.Snapshot, moved []string))
- func (c *Cache) Read(ctx context.Context, want wsdomain.Part) (*wsdomain.Snapshot, error)
- func (c *Cache) Recent(p wsdomain.Part) *wsdomain.Snapshot
- func (c *Cache) Refresh(p wsdomain.Part)
- func (c *Cache) SetBase(ctx context.Context)
- type Cached
- func (c *Cached) AddRepo(ctx context.Context, path string) (wsdomain.Repo, error)
- func (c *Cached) AgentActivity(ctx context.Context) (map[string]wsdomain.Activity, error)
- func (c *Cached) CloseTerminal(ctx context.Context, handle string) error
- func (c *Cached) Closed(ctx context.Context, session string) (bool, error)
- func (c *Cached) ConnectsMCPOnFirstPrompt() bool
- func (c *Cached) Create(ctx context.Context, req CreateRequest) (wsdomain.Workspace, string, error)
- func (c *Cached) Direct() Manager
- func (c *Cached) Focus(ctx context.Context, id string) error
- func (c *Cached) Honors(needs LaunchNeeds) error
- func (c *Cached) LinkUnit(ctx context.Context, id string, u unit.Unit) error
- func (c *Cached) List(ctx context.Context) ([]wsdomain.Workspace, error)
- func (c *Cached) LiveAgentSession(ctx context.Context, workspaceID, agent string) (Session, bool, error)
- func (c *Cached) MarkUnread(ctx context.Context, id string) error
- func (c *Cached) Reachable(ctx context.Context) error
- func (c *Cached) ReadScreen(ctx context.Context, handle string) (string, error)
- func (c *Cached) Remove(ctx context.Context, id string, force bool) error
- func (c *Cached) Rename(ctx context.Context, id, displayName string) error
- func (c *Cached) Repos(ctx context.Context) ([]wsdomain.Repo, error)
- func (c *Cached) RewritePrompt(prompt string) string
- func (c *Cached) SendPrompt(ctx context.Context, handle, prompt string, queued bool) (bool, error)
- func (c *Cached) SetCard(ctx context.Context, id, status, comment string, unread bool) error
- func (c *Cached) SetStatus(ctx context.Context, id, status string) error
- func (c *Cached) Snapshot() *Cache
- func (c *Cached) StartAgentSession(ctx context.Context, req StartRequest) (string, error)
- func (c *Cached) TrustsAtLaunch(agent, home string) bool
- func (c *Cached) Unregister(ctx context.Context, id string) error
- func (c *Cached) Wake(ctx context.Context, req WakeRequest) (string, error)
- type Checkout
- type CreateRequest
- type Custody
- type LaunchNeeds
- type LaunchTruster
- type LazyMCP
- type Linker
- type Manager
- type Observer
- type PolicyHonorer
- type PromptRewriter
- type Renamer
- type ScreenReader
- type Session
- type SessionStore
- type Set
- func (s *Set) AgentActivity(ctx context.Context) (map[string]wsdomain.Activity, error)
- func (s *Set) All() []Manager
- func (s *Set) Custody() Custody
- func (s *Set) Find(ctx context.Context, id string) (wsdomain.Workspace, bool, error)
- func (s *Set) First() Manager
- func (s *Set) Focus(ctx context.Context, ws wsdomain.Workspace) error
- func (s *Set) For(ctx context.Context, ws wsdomain.Workspace) (Manager, error)
- func (s *Set) Invalidate(parts wsdomain.Part)
- func (s *Set) Keep(ctx context.Context, m Manager, ws wsdomain.Workspace, repo string, ...) error
- func (s *Set) Len() int
- func (s *Set) LinkUnit(ctx context.Context, ws wsdomain.Workspace, u unit.Unit) error
- func (s *Set) List(ctx context.Context) ([]wsdomain.Workspace, error)
- func (s *Set) ListAll(ctx context.Context) (_ []wsdomain.Workspace, failed []string, _ error)
- func (s *Set) Listings(ctx context.Context, path string) []wsdomain.Workspace
- func (s *Set) Named(name string) (Manager, bool)
- func (s *Set) Names() []string
- func (s *Set) Of(ctx context.Context, id string) (Manager, error)
- func (s *Set) Reachable(ctx context.Context) error
- func (s *Set) Read(ctx context.Context, want wsdomain.Part) (*wsdomain.Snapshot, error)
- func (s *Set) Remove(ctx context.Context, id string, force bool) error
- func (s *Set) Repos(ctx context.Context) ([]wsdomain.Repo, error)
- func (s *Set) Snapshots() bool
- func (s *Set) Unreachable(ctx context.Context) map[string]error
- func (s *Set) Unregister(ctx context.Context, id string) error
- func (s *Set) UseCustody(c Custody)
- type Snapshots
- type StartRequest
- type TerminalCloser
- type WakeRequest
- type Waker
Constants ¶
const ReasonTrust = "agent-trust-workspace"
ReasonTrust is the blocked reason of a session on the agent's workspace trust dialog.
Variables ¶
var ErrUnknownStatus = errors.New("unknown workspace status")
var ErrUnknownWorkspace = errors.New("no enabled workspace manager lists the workspace")
ErrUnknownWorkspace is a workspace id no enabled manager lists.
var ErrUnreachable = errors.New("workspace manager not reachable")
ErrUnreachable is a manager that cannot be asked now: not running, socket refused, or its runtime restarted mid-call. A read that fails with it says nothing about the data.
Functions ¶
func Capability ¶
Capability is m's optional feature T, false when m lacks it. On a *Cached the feature is the cache's, which invalidates what the feature changes.
func DefaultMaxAge ¶
DefaultMaxAge is how long each part serves reads: repos 10 minutes, every mutable part the fast interval.
func Honors ¶
func Honors(m Manager, needs LaunchNeeds) error
Honors is nil when m can launch a session with needs.
func Invalidate ¶
Invalidate marks parts stale on m when it keeps a snapshot; a no-op otherwise.
Types ¶
type AgentIdentifier ¶
AgentIdentifier is a manager that names an agent's terminals by another identity.
type AppProbe ¶
AppProbe is a manager whose listings stay readable while its app is down, such as worktrees read from disk: Cached asks it, not the snapshot, whether the manager can be asked now.
type BlockedError ¶
type BlockedError struct{ Handle, Reason string }
BlockedError is an agent session that started but waits on a prompt in its terminal, such as the agent's own trust dialog.
func (*BlockedError) Error ¶
func (e *BlockedError) Error() string
type Board ¶
type Board interface {
SetStatus(ctx context.Context, id, status string) error
MarkUnread(ctx context.Context, id string) error
// SetCard moves the card to status, sets its comment and marks it unread in
// one write; an empty status or comment, or a false unread, leaves that part.
SetCard(ctx context.Context, id, status, comment string, unread bool) error
}
Board is a manager with a board of workspace cards in columns.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache serves snapshots of an Observer's listings, loading each part at most once per MaxAge and once per Invalidate, with concurrent reads of a part sharing one load.
func (*Cache) Invalidate ¶
Invalidate marks parts stale: the next Read reloads them. It never blocks on a load.
func (*Cache) Last ¶
Last is the latest snapshot without asking the manager; nil before the first load.
func (*Cache) OnChange ¶
OnChange sets fn to be called after each load that changed a projection, with the ids of the workspaces whose part moved, before the reads waiting on that load return. fn must not wait on a load of this cache (Last is safe), and two loads of disjoint parts may call it out of order, so fn should read the newest snapshot from Last.
func (*Cache) Read ¶
Read returns a snapshot holding at least want, each part read within its MaxAge and by a load that began after the latest Invalidate of it. On error the cache keeps its last snapshot. A runtime change costs one reload; if the reload sees another change, Read returns the snapshot as loaded, its scopes incomplete when their runtimes disagree, and the next Read loads again.
func (*Cache) Recent ¶
Recent is the latest snapshot when p was read by the current runtime within twice its MaxAge (with no MaxAge, at any age), nil otherwise; it never asks the manager.
type Cached ¶
Cached is a Manager whose reads come from Cache and whose writes invalidate the parts they change.
func (*Cached) AgentActivity ¶
func (*Cached) CloseTerminal ¶
func (*Cached) ConnectsMCPOnFirstPrompt ¶
func (*Cached) Honors ¶
func (c *Cached) Honors(needs LaunchNeeds) error
func (*Cached) LiveAgentSession ¶
func (c *Cached) LiveAgentSession(ctx context.Context, workspaceID, agent string) (Session, bool, error)
LiveAgentSession is the usable terminal of the agent that printed last; an empty kind matches any agent.
func (*Cached) ReadScreen ¶
func (*Cached) RewritePrompt ¶
func (*Cached) SendPrompt ¶
func (*Cached) StartAgentSession ¶
func (*Cached) TrustsAtLaunch ¶
type Checkout ¶ added in v0.3.0
Checkout is what a unit's work checks out: its head branch and commit, the branch it merges into, and whether the head lives in another repository.
type CreateRequest ¶
type CreateRequest struct {
RepoID string
Name string
BaseRef string
// DefaultBase creates the worktree from the repository's default base, as
// the manager knows it, in place of BaseRef.
DefaultBase bool
// Parent is the path of the caller's worktree, which a manager with
// worktree lineage records as the new one's parent when it lists it.
Parent string
// Unit is the unit the workspace is created for; a pull request is linked as the manager links one.
Unit unit.Unit
Agent string
Prompt string
// Checkout is what the unit's work checks out, as its source says; with
// a branch, the workspace's branch is named after it.
Checkout Checkout
}
type Custody ¶
type Custody interface {
Worktrees(ctx context.Context) ([]wsdomain.Custody, error)
Keep(ctx context.Context, c wsdomain.Custody) error
LinkUnit(ctx context.Context, path string, u unit.Unit) error
}
Custody is the loop's record of which manager owns each worktree and the units it stands for.
type LaunchNeeds ¶
type LaunchNeeds struct {
// UserSettingsOnly keeps the worktree's own agent settings from loading.
UserSettingsOnly bool
// Strict makes the policy the session's only permissions.
Strict bool
// NoMCP keeps every MCP server but the loop's from loading.
NoMCP bool
// CustomHome is an agent home other than the agent's default.
CustomHome bool
}
LaunchNeeds is what a session's launch policy asks of the manager that runs it.
type LaunchTruster ¶
LaunchTruster is a manager that may trust a worktree in an agent home as it launches a session there.
type LazyMCP ¶
type LazyMCP interface {
ConnectsMCPOnFirstPrompt() bool
}
LazyMCP is a manager whose agent connects its MCP servers only when its first prompt arrives, so a new session cannot show the loop's MCP tool before the loop types into it.
type Manager ¶
type Manager interface {
// Name is the manager's key in the workspace manager registry, such as "orca".
Name() string
// Hosts says whether the manager can run sessions of agent.
Hosts(agent string) bool
Reachable(ctx context.Context) error
Repos(ctx context.Context) ([]wsdomain.Repo, error)
AddRepo(ctx context.Context, path string) (wsdomain.Repo, error)
List(ctx context.Context) ([]wsdomain.Workspace, error)
Create(ctx context.Context, req CreateRequest) (wsdomain.Workspace, string, error)
AgentActivity(ctx context.Context) (map[string]wsdomain.Activity, error)
LiveAgentSession(ctx context.Context, workspaceID, agent string) (Session, bool, error)
// StartAgentSession starts the agent in the workspace and waits until it
// is ready, returning the handle of its process; a *BlockedError carries
// the handle of a start that stopped on a prompt.
StartAgentSession(ctx context.Context, req StartRequest) (string, error)
// SendPrompt types the prompt and presses Enter. submitted reports whether
// the agent was observed accepting it.
// With queued, the agent is mid-turn and takes the prompt when the turn
// ends, so text reaching the process counts as submitted.
SendPrompt(ctx context.Context, handle, prompt string, queued bool) (submitted bool, err error)
// Focus brings the workspace on screen in the app: its live agent session
// when there is one, else whatever the app shows of the worktree. It fails
// when the workspace has nothing to show.
Focus(ctx context.Context, id string) error
// Remove deletes the workspace and its checkout. The caller checks first
// that nothing would be lost; force only waives the manager's own check
// that every process of the workspace exited.
Remove(ctx context.Context, id string, force bool) error
// Unregister drops the workspace from the manager without force. It is
// meant for a workspace whose checkout is already gone.
Unregister(ctx context.Context, id string) error
}
Manager is an app that hosts worktrees and the agent sessions in them. What only some managers offer is an optional interface below; callers do without it.
type Observer ¶
type Observer interface {
Repos(ctx context.Context) ([]wsdomain.Repo, error)
Workspaces(ctx context.Context) ([]wsdomain.Workspace, wsdomain.Scope, error)
Panes(ctx context.Context) ([]wsdomain.Pane, error)
// AllTerminals lists every terminal of every workspace; Scope.Complete also requires
// the manager to report itself ready.
AllTerminals(ctx context.Context) ([]wsdomain.Terminal, wsdomain.Scope, error)
}
Observer is a manager that lists everything a Snapshot holds in one call per part.
type PolicyHonorer ¶
type PolicyHonorer interface {
// Honors is nil when the manager can launch a session with needs, else why not.
Honors(needs LaunchNeeds) error
}
PolicyHonorer is a manager that honors only some launch policies; one that does not implement it honors every policy.
type PromptRewriter ¶
type PromptRewriter interface {
// RewritePrompt is the line the agent receives for prompt.
RewritePrompt(prompt string) string
}
PromptRewriter is a manager that delivers a prompt as a message the agent does not expand, so a slash command must be rewritten into words.
type ScreenReader ¶
ScreenReader is a manager that can read what a process renders now.
type SessionStore ¶
type SessionStore interface {
// Closed takes the session's newest handle, else its id.
Closed(ctx context.Context, session string) (bool, error)
}
SessionStore is a manager that keeps its own record of each session and says when the user closed one there, such as archiving or deleting it.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is every enabled workspace manager, in the configured order. It routes each workspace to the manager that owns it and merges what they list; it is not a manager itself.
func (*Set) AgentActivity ¶
AgentActivity is every manager's activity by workspace id.
func (*Set) Invalidate ¶
Invalidate marks parts stale on every manager that keeps a snapshot.
func (*Set) Keep ¶
func (s *Set) Keep(ctx context.Context, m Manager, ws wsdomain.Workspace, repo string, created bool, units ...unit.Unit) error
Keep records m as the owner of the worktree ws, which m created when created.
func (*Set) LinkUnit ¶
LinkUnit records that the worktree ws stands for u, and has its manager show the link when it can.
func (*Set) List ¶
List is every manager's workspaces, each carrying its manager; a manager that cannot be read lists none, and only every one failing is an error.
func (*Set) Listings ¶ added in v0.2.0
Listings are every manager's rows of the worktree at path, in priority order, before the set settles its owner; a manager that cannot be read has none.
func (*Set) Reachable ¶
Reachable is nil when at least one manager can be asked now; a manager that cannot only leaves its own workspaces and sessions unread.
func (*Set) Read ¶
Read merges each manager's snapshot holding want. A manager whose snapshot cannot be read contributes no rows and incomplete scopes; only every one failing is an error. Gen is the sum of the managers' generations, so it moves whenever one does.
func (*Set) Remove ¶
Remove deletes the workspace id under the manager that lists it, and forgets its custody.
func (*Set) Unreachable ¶
Unreachable are the managers that cannot be asked now, with why.
func (*Set) Unregister ¶
Unregister drops the workspace id from the manager that lists it, and forgets its custody.
func (*Set) UseCustody ¶
UseCustody has the set settle, from c, which manager owns a worktree that more than one lists, and the units each stands for.
type Snapshots ¶
type Snapshots interface {
Manager
Snapshot() *Cache
// Direct is the manager behind the snapshot, for a read that must not come from it.
Direct() Manager
}
Snapshots is a manager whose reads come from a snapshot it keeps.
type StartRequest ¶
type StartRequest struct {
WorkspaceID string
// Session is the id the loop minted for the session; the agent runs under it.
Session string
Agent string
// Command is the shell line a terminal manager runs to start the agent.
Command string
Title string
// Model is the agent's model for the session, "" for its default.
Model string
// Settings are the session's permission settings as the agent reads them,
// "" for none; a manager that cannot pass Command's flags writes them where
// the agent loads them.
Settings string
}
StartRequest starts an agent session in a workspace.
type TerminalCloser ¶
TerminalCloser is a manager that can close a terminal the caller started.
type WakeRequest ¶
type WakeRequest struct {
WorkspaceID, Session, Agent string
// Handle is the newest handle the manager gave the session, "" for none.
Handle string
// Settings are the session's permission settings, as in StartRequest.
Settings string
// AgentSession is the agent's own id of the conversation to resume.
AgentSession string
// Command is the shell line a terminal manager runs to resume it.
Command string
Title string
// Model is the agent's model for the session, "" for its default.
Model string
}
WakeRequest wakes a dormant session.
type Waker ¶
type Waker interface {
Wake(ctx context.Context, req WakeRequest) (handle string, err error)
}
Waker is a manager that can give a dormant session a live process again. Wake's handle comes with an error when the process started but is not ready, so a process that comes up late lands on the woken session.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claudedesktop implements workspace.Manager over the Claude Desktop app: git worktrees under a root the loop owns and the ones the app made for its sessions, and the Claude Code sessions Desktop runs in them.
|
Package claudedesktop implements workspace.Manager over the Claude Desktop app: git worktrees under a root the loop owns and the ones the app made for its sessions, and the Claude Code sessions Desktop runs in them. |
|
Package fake is an in-memory workspace.Manager for tests.
|
Package fake is an in-memory workspace.Manager for tests. |
|
Package orca implements workspace.Manager over Orca's runtime socket and the orca CLI.
|
Package orca implements workspace.Manager over Orca's runtime socket and the orca CLI. |
|
orcatest
Package orcatest serves a fake Orca runtime on a local socket, for tests that run the real orca.Manager and count its calls.
|
Package orcatest serves a fake Orca runtime on a local socket, for tests that run the real orca.Manager and count its calls. |
|
orcatest/cmd/orca-stub
command
Command orca-stub serves an Orca runtime with no repository, worktree or terminal, for scripts/isolated-daemon.sh: its daemon finds a reachable workspace manager, so the sweep runs its workflows, and every write a session would need is refused.
|
Command orca-stub serves an Orca runtime with no repository, worktree or terminal, for scripts/isolated-daemon.sh: its daemon finds a reachable workspace manager, so the sweep runs its workflows, and every write a session would need is refused. |