computersetup

package
v1.5.145 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 5 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 computersetup owns the interactive "open a desktop application for Computer Use" flow that the TUI and the GUI must share: resolve a requested application, choose one window, take the grant, and start the session.

The package holds no rendering and no terminal/UI dependency. Frontends render View/Plan and call these methods from their own goroutine or message loop, so the decision about which application and window to use can only be made here.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed reports a setup that was already dismissed by the frontend.
	ErrClosed = errors.New("computer setup is no longer current")
	// ErrResolved reports a second resolution of the same setup.
	ErrResolved = errors.New("computer setup was already resolved")
	// ErrNoTarget reports a start without a selected window.
	ErrNoTarget = errors.New("no desktop window is selected")
	// ErrReadOnly reports a control grant while the conversation is read-only.
	ErrReadOnly = errors.New("computer control is unavailable in read-only mode")
)

Functions

This section is empty.

Types

type Grant

type Grant struct {
	Control bool
	// SemanticOnly skips the operator preview whose confirmation proves a
	// system-selected capture source. Backends without a preview gate ignore it.
	SemanticOnly bool
	// SkipPreview skips only the confirmation step, keeping capture and control.
	// Used when the person explicitly chose the window on macOS.
	SkipPreview bool
}

Grant is the authority a frontend asks for.

type Options

type Options struct {
	SessionID string
	Suggested string
	ReadOnly  bool
	// Guard revalidates the frontend's live authorization immediately before an
	// asynchronous application launch. It must not select a window.
	Guard func() error
	// Backend overrides the platform backend. Tests use it; production leaves
	// it nil so every setup gets a fresh catalog.
	Backend func() (computeruse.PlatformBackend, error)
}

Options describe one setup. Suggested is the application name the model requested; it is empty for a manually opened picker.

type Setup

type Setup struct {
	// contains filtered or unexported fields
}

Setup is one application/window selection. Backends are owned here until a session takes them, and it is safe to call Close from any goroutine.

func New

func New(opts Options) *Setup

New prepares an unresolved setup. Selected starts at -1 so a frontend can rely on "no window chosen yet" before Resolve runs.

func (*Setup) AutoGrant

func (s *Setup) AutoGrant() Grant

AutoGrant is the authority a requested application receives after a unique match: control, with the operator preview skipped only when the backend requires that confirmation for a system-selected source.

func (*Setup) ChooseApplication

func (s *Setup) ChooseApplication(ctx context.Context, index int) error

ChooseApplication launches one installed candidate and adopts its windows.

func (*Setup) Close

func (s *Setup) Close()

Close releases the catalog if no session took it. Sessions are stopped by the frontend that owns them.

func (*Setup) HasPreviewGate

func (s *Setup) HasPreviewGate() bool

HasPreviewGate reports whether the backend asks for a system-selected capture source that a person must confirm.

func (*Setup) Plan

func (s *Setup) Plan() computeruse.SetupPlan

Plan is the shared decision every frontend renders: installed applications first, then no match, then a unique requested window, then the window picker.

func (*Setup) PreparePreview

PreparePreview asks the backend for an operator-only preview of the selected window. It never starts a session.

func (*Setup) ReadOnly

func (s *Setup) ReadOnly() bool

ReadOnly reports the permission mode captured when the setup was created.

func (*Setup) Resolve

func (s *Setup) Resolve(ctx context.Context) error

Resolve discovers or launches the requested application. It must run once; repeating it would let a conversation retarget itself after granting access.

func (*Setup) Select

func (s *Setup) Select(index int) bool

Select records an explicit window choice. It refuses ambiguous or stale indexes so a frontend cannot start a window the person did not see.

func (*Setup) SessionID

func (s *Setup) SessionID() string

SessionID reports the conversation this setup belongs to.

func (*Setup) Start

func (s *Setup) Start(ctx context.Context, grant Grant) (*computeruse.Session, error)

Start begins the selected window with the requested grant. It prepares and installs the operator preview unless the grant is semantic-only, and returns the active session; the backend then belongs to that session.

func (*Setup) StartConfirmed

func (s *Setup) StartConfirmed(ctx context.Context, grant Grant, candidateID string) (*computeruse.Session, error)

StartConfirmed is Start for a frontend that already showed the preview to the person and collected an explicit confirmation of the same window.

func (*Setup) Suggested

func (s *Setup) Suggested() string

Suggested reports the requested application name, if any.

func (*Setup) Target

func (s *Setup) Target() (computeruse.Target, bool)

Target returns the selected window.

func (*Setup) View

func (s *Setup) View() View

View returns a copy of the current resolution state.

type View

type View struct {
	Targets      []computeruse.Target
	Applications []computeruse.Application
	Matched      bool
	NotFound     bool
	Selected     int
	Suggested    string
	PreviewGate  bool
}

View is the resolution state a frontend renders.

Jump to

Keyboard shortcuts

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