workspace

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 12 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 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

View Source
const ReasonTrust = "agent-trust-workspace"

ReasonTrust is the blocked reason of a session on the agent's workspace trust dialog.

Variables

View Source
var ErrUnknownStatus = errors.New("unknown workspace status")
View Source
var ErrUnknownWorkspace = errors.New("no enabled workspace manager lists the workspace")

ErrUnknownWorkspace is a workspace id no enabled manager lists.

View Source
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

func Capability[T any](m Manager) (T, bool)

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

func DefaultMaxAge(fast time.Duration) map[wsdomain.Part]time.Duration

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

func Invalidate(m Manager, parts wsdomain.Part)

Invalidate marks parts stale on m when it keeps a snapshot; a no-op otherwise.

func LinkedPR

func LinkedPR(u unit.Unit) int

LinkedPR is the pull request number of a github unit, 0 for any other.

Types

type AgentIdentifier

type AgentIdentifier interface {
	AgentIdentity(kind string) string
}

AgentIdentifier is a manager that names an agent's terminals by another identity.

type AppProbe

type AppProbe interface {
	AppRunning(ctx context.Context) error
}

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 NewCache

func NewCache(src Observer, maxAge map[wsdomain.Part]time.Duration, now func() time.Time) *Cache

func (*Cache) Invalidate

func (c *Cache) Invalidate(p wsdomain.Part)

Invalidate marks parts stale: the next Read reloads them. It never blocks on a load.

func (*Cache) Last

func (c *Cache) Last() *wsdomain.Snapshot

Last is the latest snapshot without asking the manager; nil before the first load.

func (*Cache) OnChange

func (c *Cache) OnChange(fn func(s *wsdomain.Snapshot, moved []string))

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

func (c *Cache) Read(ctx context.Context, want wsdomain.Part) (*wsdomain.Snapshot, error)

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

func (c *Cache) Recent(p wsdomain.Part) *wsdomain.Snapshot

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.

func (*Cache) Refresh

func (c *Cache) Refresh(p wsdomain.Part)

Refresh starts one asynchronous reload of p, after an Invalidate of it, and returns at once; OnChange fires if a projection moved.

func (*Cache) SetBase

func (c *Cache) SetBase(ctx context.Context)

SetBase is the context the loads Refresh starts run under, such as one carrying the meter registry; each opens a loop:workspace scope in it.

type Cached

type Cached struct {
	Manager
	Cache *Cache
}

Cached is a Manager whose reads come from Cache and whose writes invalidate the parts they change.

func NewCached

func NewCached(m Manager, o Observer, fast time.Duration) *Cached

func (*Cached) AddRepo

func (c *Cached) AddRepo(ctx context.Context, path string) (wsdomain.Repo, error)

func (*Cached) AgentActivity

func (c *Cached) AgentActivity(ctx context.Context) (map[string]wsdomain.Activity, error)

func (*Cached) CloseTerminal

func (c *Cached) CloseTerminal(ctx context.Context, handle string) error

func (*Cached) Closed

func (c *Cached) Closed(ctx context.Context, session string) (bool, error)

func (*Cached) ConnectsMCPOnFirstPrompt

func (c *Cached) ConnectsMCPOnFirstPrompt() bool

func (*Cached) Create

func (*Cached) Direct

func (c *Cached) Direct() Manager

func (*Cached) Focus

func (c *Cached) Focus(ctx context.Context, id string) error

func (*Cached) Honors

func (c *Cached) Honors(needs LaunchNeeds) error

func (*Cached) LinkUnit

func (c *Cached) LinkUnit(ctx context.Context, id string, u unit.Unit) error

func (*Cached) List

func (c *Cached) List(ctx context.Context) ([]wsdomain.Workspace, 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) MarkUnread

func (c *Cached) MarkUnread(ctx context.Context, id string) error

func (*Cached) Reachable

func (c *Cached) Reachable(ctx context.Context) error

func (*Cached) ReadScreen

func (c *Cached) ReadScreen(ctx context.Context, handle string) (string, error)

func (*Cached) Remove

func (c *Cached) Remove(ctx context.Context, id string, force bool) error

func (*Cached) Rename

func (c *Cached) Rename(ctx context.Context, id, displayName string) error

func (*Cached) Repos

func (c *Cached) Repos(ctx context.Context) ([]wsdomain.Repo, error)

func (*Cached) RewritePrompt

func (c *Cached) RewritePrompt(prompt string) string

func (*Cached) SendPrompt

func (c *Cached) SendPrompt(ctx context.Context, handle, prompt string, queued bool) (bool, error)

func (*Cached) SetCard

func (c *Cached) SetCard(ctx context.Context, id, status, comment string, unread bool) error

func (*Cached) SetStatus

func (c *Cached) SetStatus(ctx context.Context, id, status string) error

func (*Cached) Snapshot

func (c *Cached) Snapshot() *Cache

func (*Cached) StartAgentSession

func (c *Cached) StartAgentSession(ctx context.Context, req StartRequest) (string, error)

func (*Cached) TrustsAtLaunch

func (c *Cached) TrustsAtLaunch(agent, home string) bool

func (*Cached) Unregister

func (c *Cached) Unregister(ctx context.Context, id string) error

func (*Cached) Wake

func (c *Cached) Wake(ctx context.Context, req WakeRequest) (string, error)

type Checkout added in v0.3.0

type Checkout struct {
	Branch, Head, Base string
	Fork               bool
}

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

type LaunchTruster interface {
	TrustsAtLaunch(agent, home string) bool
}

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 Linker

type Linker interface {
	LinkUnit(ctx context.Context, id string, u unit.Unit) error
}

Linker is a manager that shows the pull request a workspace is for.

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.

func Direct

func Direct(m Manager) Manager

Direct is the manager behind m's snapshot, m itself when it keeps none.

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 Renamer

type Renamer interface {
	Rename(ctx context.Context, id, displayName string) error
}

Renamer is a manager whose workspaces carry a display name.

type ScreenReader

type ScreenReader interface {
	ReadScreen(ctx context.Context, handle string) (string, error)
}

ScreenReader is a manager that can read what a process renders now.

type Session

type Session struct {
	Handle     string
	LastOutput time.Time
}

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 NewSet

func NewSet(ms ...Manager) *Set

func (*Set) AgentActivity

func (s *Set) AgentActivity(ctx context.Context) (map[string]wsdomain.Activity, error)

AgentActivity is every manager's activity by workspace id.

func (*Set) All

func (s *Set) All() []Manager

All are the managers in the configured order.

func (*Set) Custody

func (s *Set) Custody() Custody

Custody is the set's custody record, nil without one.

func (*Set) Find

func (s *Set) Find(ctx context.Context, id string) (wsdomain.Workspace, bool, error)

Find is the workspace id as its manager lists it.

func (*Set) First

func (s *Set) First() Manager

First is the manager of highest priority, nil for an empty set.

func (*Set) Focus

func (s *Set) Focus(ctx context.Context, ws wsdomain.Workspace) error

Focus brings ws on screen in its manager's app.

func (*Set) For

func (s *Set) For(ctx context.Context, ws wsdomain.Workspace) (Manager, error)

For is the manager that owns ws: the one ws names, else the one that lists it.

func (*Set) Invalidate

func (s *Set) Invalidate(parts wsdomain.Part)

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) Len

func (s *Set) Len() int

func (*Set) LinkUnit

func (s *Set) LinkUnit(ctx context.Context, ws wsdomain.Workspace, u unit.Unit) error

LinkUnit records that the worktree ws stands for u, and has its manager show the link when it can.

func (*Set) List

func (s *Set) List(ctx context.Context) ([]wsdomain.Workspace, error)

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) ListAll added in v0.3.0

func (s *Set) ListAll(ctx context.Context) (_ []wsdomain.Workspace, failed []string, _ error)

ListAll is List, and the managers that could not be read.

func (*Set) Listings added in v0.2.0

func (s *Set) Listings(ctx context.Context, path string) []wsdomain.Workspace

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) Named

func (s *Set) Named(name string) (Manager, bool)

func (*Set) Names

func (s *Set) Names() []string

Names are the managers' names in order.

func (*Set) Of

func (s *Set) Of(ctx context.Context, id string) (Manager, error)

Of is the manager that lists the workspace id.

func (*Set) Reachable

func (s *Set) Reachable(ctx context.Context) error

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

func (s *Set) Read(ctx context.Context, want wsdomain.Part) (*wsdomain.Snapshot, error)

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

func (s *Set) Remove(ctx context.Context, id string, force bool) error

Remove deletes the workspace id under the manager that lists it, and forgets its custody.

func (*Set) Repos

func (s *Set) Repos(ctx context.Context) ([]wsdomain.Repo, error)

Repos is every manager's repositories, each carrying its manager.

func (*Set) Snapshots

func (s *Set) Snapshots() bool

Snapshots reports whether every manager keeps a snapshot.

func (*Set) Unreachable

func (s *Set) Unreachable(ctx context.Context) map[string]error

Unreachable are the managers that cannot be asked now, with why.

func (*Set) Unregister

func (s *Set) Unregister(ctx context.Context, id string) error

Unregister drops the workspace id from the manager that lists it, and forgets its custody.

func (*Set) UseCustody

func (s *Set) UseCustody(c Custody)

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

type TerminalCloser interface {
	CloseTerminal(ctx context.Context, handle string) error
}

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.

Jump to

Keyboard shortcuts

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