computeruse

package
v1.5.85 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 32 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 computeruse owns the platform-independent authorization and lifecycle of a single locally resolved desktop window. Platform adapters must fail closed when they cannot prove the target and input conditions.

Index

Constants

View Source
const (
	MaxFrameBytes  = 8 << 20
	MaxFramePixels = 16 << 20
)
View Source
const (
	MaxSnapshotNodes = 500
	MaxNodeTextBytes = 512
	MaxSnapshotBytes = 32 << 10
)
View Source
const OperatorPanePrefix = "golder-computer-use-"

OperatorPanePrefix is reserved for the person's desktop-control view. Pane tools must not inject input into it or capture its sensitive contents.

View Source
const (

	// OperatorResumeTimeout bounds a GUI or TUI resume without closing the
	// operator connection while a target is still settling.
	OperatorResumeTimeout = 15 * time.Second
)

Variables

View Source
var (
	ErrUnavailable  = errors.New("computer use backend unavailable")
	ErrNotActive    = errors.New("computer use session is not active")
	ErrNotAllowed   = errors.New("computer use action is not authorized")
	ErrPaused       = errors.New("computer use is paused; the user must resume")
	ErrTargetLost   = errors.New("computer use target changed or is unavailable")
	ErrPreviewBusy  = errors.New("computer use preview skipped while another operation is running")
	ErrNoInput      = errors.New("computer use did not dispatch input")
	ErrClosePending = errors.New("a close request was already attempted; inspect the selected window and do not repeat it automatically")
)
View Source
var ErrStaleObservation = errors.New("computer use observation is stale; observe the target again")

Functions

func DescribeFailure added in v1.5.64

func DescribeFailure(err error, p PermissionState) string

DescribeFailure keeps the underlying failure distinct from permission state; a granted OS permission does not prove that a window was safely matched.

func DescribePermissions added in v1.5.64

func DescribePermissions(p PermissionState) string

DescribePermissions reports only this process's OS grants. They are separate from the operator's authorization for any particular window.

func IsOperatorPane

func IsOperatorPane(windowID string) bool

func MatchApplications

func MatchApplications(name string, targets []Target) []int

MatchApplications returns indexes whose application name exactly matches the requested name after case and whitespace normalization. A unique match can be used directly; ambiguous matches require an operator's selection. Substring or title matching is deliberately excluded because a document or a different application may contain the requested name.

func PreviewPoint

func PreviewPoint(frame FrameGeometry, targetID, frameID string, previewWidth, previewHeight, x, y float64) (float64, float64, error)

PreviewPoint converts coordinates from a letterboxed preview into frame pixels; clicks outside the visible image and stale frame identities fail.

func RequestMacPermission added in v1.5.58

func RequestMacPermission(string) bool

func RunOperatorPane

func RunOperatorPane(ctx context.Context, socket string, in, out *os.File) error

RunOperatorPane is the internal child entry point for the dedicated tuios view. The parent authenticates all three socket peers before serving them. It must not be used as a model-facing desktop control interface.

func ServeOperatorPane

func ServeOperatorPane(ctx context.Context, conn net.Conn, pane *Pane) error

ServeOperatorPane serves one already authenticated connection. The caller MUST verify its exact pane identity with VerifyOperatorPanePeer before using this function and keep it private from model-facing tools. If several connections share a Pane, they must all be pinned to the same verified process; disconnect or cancellation pauses the session before returning.

func VerifyOperatorPanePeer

func VerifyOperatorPanePeer(ctx context.Context, conn net.Conn, daemon *tuiosctl.Client, windowID string) error

VerifyOperatorPanePeer binds a private pane connection to the exact helper pane Golder created. A claimed pane ID or a token in argv is not sufficient: the kernel supplies the peer PID and the daemon resolves that PID's pane. An older or restricted daemon that cannot prove this fails closed.

func WithApplicationLaunchGuard added in v1.5.62

func WithApplicationLaunchGuard(ctx context.Context, guard func() error) context.Context

WithApplicationLaunchGuard rechecks a frontend's live authorization just before a discovered app is launched, after any asynchronous discovery.

Types

type Application added in v1.5.62

type Application struct {
	ID       string
	Name     string
	Identity string
	Detail   string
}

Application is a locally discovered, opaque launch candidate. Its ID is valid only for the backend that discovered it; Detail is for disambiguation.

type ApplicationLauncher added in v1.5.62

type ApplicationLauncher interface {
	Applications(context.Context, string) ([]Application, error)
	LaunchApplication(context.Context, Application) error
}

ApplicationLauncher is an optional platform capability. Names are matched against local inventory, never interpreted as paths or shell commands.

type ApplicationResolution added in v1.5.62

type ApplicationResolution struct {
	Targets      []Target
	Applications []Application
	Matched      bool
}

ApplicationResolution contains either matching windows, ambiguous installed applications, or other windows for an explicit operator choice.

func LaunchAndFindApplication added in v1.5.62

func LaunchAndFindApplication(ctx context.Context, backend PlatformBackend, app Application) (ApplicationResolution, error)

LaunchAndFindApplication waits for a window belonging to the exact launched application. It never substitutes a window from another application.

func ResolveApplication added in v1.5.62

func ResolveApplication(ctx context.Context, backend PlatformBackend, name string) (ApplicationResolution, error)

ResolveApplication first reuses matching discovered windows. If none exist, it launches only an unambiguous locally discovered application. Multiple app or window candidates are returned for a person to disambiguate.

type ApplicationRevealer added in v1.5.70

type ApplicationRevealer interface {
	RevealApplication(context.Context, Application) error
}

ApplicationRevealer can bring an already catalogued application forward if a background launch did not produce a visible window. It must revalidate the same application identity, and must not select or control a window itself.

type ApplicationWindowLookup added in v1.5.84

type ApplicationWindowLookup interface {
	ApplicationWindows(context.Context, Application) ([]Target, error)
}

ApplicationWindowLookup discovers windows of the exact catalogued app, including windows outside the foreground desktop when the OS can prove them. It never activates an application or expands the selected app identity.

type Backend

type Backend interface {
	Validate(context.Context, Target, bool) error
	Close() error
}

Backend is implemented by a platform-specific adapter. Validate must check the identity and conditions needed for the requested action immediately before execution. A successful capture does not imply safe input control. Backends must honor context cancellation and recheck it before injecting input; cancellation cannot undo an input already delivered to the OS.

type Capabilities

type Capabilities struct {
	Observe bool
	Control bool
}

type CaptureAvailability

type CaptureAvailability interface {
	CaptureAvailable() bool
}

CaptureAvailability lets a backend with an operator-confirmed source avoid advertising screenshots while its local selection has not been approved.

type CaptureBackend

type CaptureBackend interface {
	Capture(context.Context, Target) ([]byte, error)
}

CaptureBackend returns only the selected target window in PNG format. The adapter must refuse a capture if it cannot reliably exclude other windows.

type Element

type Element struct {
	Ref      string `json:"ref"`
	Role     string `json:"role"`
	Name     string `json:"name,omitempty"`
	Value    string `json:"value,omitempty"`
	Enabled  bool   `json:"enabled"`
	Editable bool   `json:"editable,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
}

Element represents only bounded, non-sensitive accessibility data. Secure includes password controls and nodes whose safety cannot be established; backends must never populate their Name or Value.

type Frame

type Frame struct {
	ID     string
	Width  int
	Height int
	PNG    []byte
}

Frame is ephemeral. It must not be put into ordinary logs or persisted as a session artifact without an explicit retention policy and user consent.

type FrameBoundBackend

type FrameBoundBackend interface {
	CaptureBackend
	CaptureBound(context.Context, Target) ([]byte, string, error)
	ClickFrame(context.Context, Target, string, float64, float64) error
}

FrameBoundBackend binds a capture to opaque platform geometry. ClickFrame must revalidate the target, geometry and sensitive controls immediately before dispatch. Global input additionally requires focus and occlusion checks; a target-scoped semantic action must verify subtree membership. A token alone is never authorization.

type FrameGeometry

type FrameGeometry struct {
	TargetID string
	FrameID  string
	Width    int
	Height   int
}

FrameGeometry binds a preview to the exact captured target and dimensions. A backend must separately verify target identity, focus and occlusion before injecting any resulting point; this calculation alone is not authorization.

type FrameKeyAvailability

type FrameKeyAvailability interface {
	SupportsFrameKey(string) bool
}

FrameKeyAvailability narrows the keys a backend can safely implement.

type FrameKeyBackend

type FrameKeyBackend interface {
	FrameBoundBackend
	PressFrame(context.Context, Target, string, string) error
}

FrameKeyBackend and FrameScrollBackend may be offered independently. Both must apply the same target, frame and dispatch checks as FrameBoundBackend.

type FrameScrollBackend

type FrameScrollBackend interface {
	FrameBoundBackend
	ScrollFrame(context.Context, Target, string, float64, float64, int, int) error
}

type KittyRenderer

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

KittyRenderer draws ephemeral computer-use frames in a terminal pane that has already positively detected Kitty graphics support. It does not own the terminal, select targets, grant control, or forward input to a desktop.

func NewKittyRenderer

func NewKittyRenderer(out io.Writer, imageID uint32, graphicsSupported bool) (*KittyRenderer, error)

func (*KittyRenderer) Clear

func (r *KittyRenderer) Clear() error

Clear removes the current frame without closing the renderer, so a paused session never leaves its last captured image displayed in the pane.

func (*KittyRenderer) Close

func (r *KittyRenderer) Close() error

Close removes only this pane's image. It is safe to call repeatedly.

func (*KittyRenderer) Frame

func (r *KittyRenderer) Frame(frame Frame, columns, rows int) error

Frame transmits a single PNG by direct, chunked data transfer. It does not expose a filesystem path to the terminal or persist the captured image.

type OperatorPreview

type OperatorPreview struct {
	ID  string
	PNG []byte
}

type OperatorPreviewBackend

type OperatorPreviewBackend interface {
	PrepareOperatorPreview(context.Context, Target) (OperatorPreview, error)
	ConfirmOperatorPreview(context.Context, Target, string) error
}

OperatorPreviewBackend supports a second, operator-only source selection. The candidate is never exposed through the model-facing Session before the person explicitly confirms that it matches the already selected target.

type OperatorPreviewDiscarder

type OperatorPreviewDiscarder interface {
	DiscardOperatorPreview(context.Context, Target, string) error
}

OperatorPreviewDiscarder permits an explicit semantic-only fallback.

type Pane

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

Pane is the state and rendering logic for a dedicated, operator-controlled terminal pane. The caller owns its PTY and must authenticate input as coming from the operator; this type must not be exposed as a model-callable socket.

func NewPane

func NewPane(session *Session, out io.Writer, imageID uint32, graphicsSupported bool) (*Pane, error)

func (*Pane) Close

func (p *Pane) Close() error

Close removes the frame and pauses control if the pane goes away. Closing a view must never leave an unseen desktop control session running.

func (*Pane) OperatorCommand

func (p *Pane) OperatorCommand(ctx context.Context, input string) (string, error)

OperatorCommand handles only local, person-originated input. It never accepts a window identity or a model request, and resume is operator-only.

func (*Pane) Render

func (p *Pane) Render(ctx context.Context, columns, rows int) error

Render refreshes the target frame on a capable terminal; a non-graphics terminal receives status only. The caller positions the cursor and owns terminal resize handling.

type PaneClient

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

PaneClient is used by the dedicated operator pane, never by the model. Its bounded protocol transfers frames only in memory and never writes them to a screenshot file or the conversation transcript.

func NewPaneClient

func NewPaneClient(conn net.Conn) *PaneClient

func (*PaneClient) Close

func (c *PaneClient) Close() error

func (*PaneClient) Request

func (c *PaneClient) Request(ctx context.Context, request PaneRequest) (PaneResponse, error)

type PaneHandle

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

PaneHandle owns the helper pane and its private connections. Closing it revokes the target immediately, including when the model is still running.

func LaunchOperatorPane

func LaunchOperatorPane(ctx context.Context, session *Session, cwd string) (*PaneHandle, error)

LaunchOperatorPane opens a helper next to this exact agent pane. The target must already have been resolved and started by the frontend. Separate sockets let pause/stop interrupt a slow capture or action rather than queue behind it. A failure to prove all peers as the same process in the new pane fails closed; no model-facing endpoint is created.

func (*PaneHandle) Close

func (h *PaneHandle) Close()

func (*PaneHandle) Done

func (h *PaneHandle) Done() <-chan struct{}

func (*PaneHandle) WindowID

func (h *PaneHandle) WindowID() string

type PaneRequest

type PaneRequest struct {
	Action   string `json:"action"`
	Ref      string `json:"ref,omitempty"`
	Text     string `json:"text,omitempty"`
	Sequence uint64 `json:"sequence,omitempty"`
}

PaneRequest is private to a Golder-owned, kernel-verified operator pane. It intentionally has no target selector, shell, arbitrary OS handles or files.

type PaneResponse

type PaneResponse struct {
	Status Status `json:"status"`
	Frame  *Frame `json:"frame,omitempty"`
	Text   string `json:"text,omitempty"`
	Error  string `json:"error,omitempty"`
	Busy   bool   `json:"busy,omitempty"`
}

type PermissionState

type PermissionState struct {
	ScreenCapture string
	Accessibility string
}

PermissionState is a non-prompting view of platform permission status. It cannot grant Golder authority to observe or control any particular target.

func ProbePermissions

func ProbePermissions() PermissionState

ProbePermissions deliberately does not imply that a system permission or desktop session exists on platforms without a supported probe yet.

type PlatformBackend

type PlatformBackend interface {
	Backend
	Targets(context.Context) ([]Target, error)
}

PlatformBackend exposes local window inventory and target validation. The inventory is used by frontend resolution and is not a model-facing tool.

func NewPlatformBackend

func NewPlatformBackend() (PlatformBackend, error)

NewPlatformBackend uses the desktop's existing AT-SPI service. A desktop without AT-SPI fails closed rather than selecting an unrelated window.

type SemanticBackend

type SemanticBackend interface {
	SupportsAction(string) bool
	Act(context.Context, Target, string, string, string, string) error
}

SemanticBackend may act only on the backend snapshot and ref passed here; it must reject stale nodes and revalidate the target immediately before an OS action. It must not treat an arbitrary model ref as a system handle.

type Session

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

Session serializes lifecycle transitions with target validation and backend operations. Only the operator-facing host may call Start or Resume.

func New

func New(backend Backend) *Session

func (*Session) Act

func (s *Session) Act(ctx context.Context, snapshotID, ref, action, text string) error

Act executes a supported semantic action only against a current observed ref. The lease is consumed even on failure so callers must observe again.

func (*Session) Capture

func (s *Session) Capture(ctx context.Context) (Frame, error)

func (*Session) CapturePreview added in v1.5.84

func (s *Session) CapturePreview(ctx context.Context) (Frame, error)

CapturePreview is for the local operator view, not model-facing screenshots. It neither queues behind control operations nor issues an input frame lease.

func (*Session) ClickFrame

func (s *Session) ClickFrame(ctx context.Context, frameID string, x, y float64) error

ClickFrame consumes a recent, single-use frame lease. Coordinates are pixels in that frame, never global screen coordinates or a system handle.

func (*Session) Close

func (s *Session) Close() error

func (*Session) CloseWindow added in v1.5.67

func (s *Session) CloseWindow(ctx context.Context) error

CloseWindow attempts one request on the pinned window. Subsequent reads may inspect that same window, but an unknown or successful request is never replayed. A different window or an unprovable target remains outside this session.

func (*Session) Do

func (s *Session) Do(ctx context.Context, control bool, operation func(context.Context, Backend, Target) error) error

Do serializes one authorized backend operation and pauses if the platform cannot validate the pinned target. Callers must not invoke backend input by bypassing this method.

func (*Session) InstallOperatorPreview

func (s *Session) InstallOperatorPreview(preview OperatorPreview) error

InstallOperatorPreview is called by the local host before it exposes the session to an agent. A pending preview blocks every model-facing operation.

func (*Session) Observe

func (s *Session) Observe(ctx context.Context) (Snapshot, error)

Observe validates the authorized target and binds the returned refs to a fresh, unpredictable session-owned snapshot identity.

func (*Session) Pause

func (s *Session) Pause()

func (*Session) PressFrame

func (s *Session) PressFrame(ctx context.Context, frameID, key string) error

PressFrame permits only a small set of non-modifier keys. The platform must also prove the focused control belongs to the target and is not sensitive.

func (*Session) Resume

func (s *Session) Resume(ctx context.Context) error

Resume must only be called from an explicit operator action. It revalidates the original target and never changes the scope of the original grant.

func (*Session) ScrollFrame

func (s *Session) ScrollFrame(ctx context.Context, frameID string, x, y float64, dx, dy int) error

ScrollFrame applies a bounded number of lines at an authorized frame point.

func (*Session) Start

func (s *Session) Start(ctx context.Context, target Target, caps Capabilities) error

Start installs a locally resolved target and capabilities. Starting a second target requires stopping the old session and resolving the new target.

func (*Session) Status

func (s *Session) Status() Status

func (*Session) Stop

func (s *Session) Stop()

Stop revokes the current authorization. It does not close the backend, so a later operator selection can create a new session.

func (*Session) SupportsCapture

func (s *Session) SupportsCapture() bool

func (*Session) SupportsCloseWindow added in v1.5.67

func (s *Session) SupportsCloseWindow() bool

func (*Session) SupportsCoordinates

func (s *Session) SupportsCoordinates() bool

SupportsCoordinates is true only when the backend can bind and revalidate a captured frame through its native input safety checks.

func (*Session) SupportsFrameAction

func (s *Session) SupportsFrameAction(action string) bool

func (*Session) SupportsFrameKey

func (s *Session) SupportsFrameKey(key string) bool

func (*Session) SupportsSemantic

func (s *Session) SupportsSemantic(action string) bool

func (*Session) SupportsSnapshot

func (s *Session) SupportsSnapshot() bool

func (*Session) WaitOperatorPreview

func (s *Session) WaitOperatorPreview(ctx context.Context) error

WaitOperatorPreview lets the host delay exposing the agent tool until the authenticated operator pane confirms or explicitly declines the preview.

type Snapshot

type Snapshot struct {
	ID        string    `json:"id"`
	Elements  []Element `json:"elements"`
	Truncated bool      `json:"truncated,omitempty"`
}

func BoundedSnapshot

func BoundedSnapshot(id string, elements []Element) Snapshot

BoundedSnapshot sanitizes platform-provided content before it can be sent to a model. Ref generation and identity resolution remain backend/session owned.

type SnapshotBackend

type SnapshotBackend interface {
	Snapshot(context.Context, Target) (string, []Element, bool, error)
}

SnapshotBackend is an optional semantic observation capability. Backends must keep refs scoped to the current target and snapshot.

type Status

type Status struct {
	Active         bool
	Paused         bool
	PendingPreview bool
	Target         Target
	Capabilities   Capabilities
}

type Target

type Target struct {
	ID            string
	Application   string
	ApplicationID string // platform identity, never a model-supplied selector
	Window        string
	Detail        string // operator-facing disambiguation; never a model selector
}

Target is an opaque identity returned by a platform backend. The local host resolves or confirms it; model-supplied process identifiers never select it.

type WindowCloser added in v1.5.67

type WindowCloser interface {
	CloseWindow(context.Context, Target) error
}

WindowCloser requests closure of the already authorized window, not its app. A successful request does not prove that the window actually closed.

type WindowDiagnostic added in v1.5.64

type WindowDiagnostic struct {
	Reason   WindowFailure
	AXError  int
	Windows  int
	Readable int
	Matches  int
}

WindowDiagnostic identifies a failed macOS window identity check without exposing window titles, screen contents, or accessibility element values.

func (*WindowDiagnostic) Error added in v1.5.64

func (d *WindowDiagnostic) Error() string

func (*WindowDiagnostic) Unwrap added in v1.5.64

func (d *WindowDiagnostic) Unwrap() error

Unwrap keeps the existing fail-closed target-loss contract for callers that inspect errors directly rather than through Session.

type WindowFailure added in v1.5.64

type WindowFailure string
const (
	WindowPermissionDenied WindowFailure = "accessibility-denied"
	WindowUnavailable      WindowFailure = "window-unavailable"
	WindowBoundsMissing    WindowFailure = "screen-bounds-unavailable"
	WindowAXAppUnavailable WindowFailure = "ax-application-unavailable"
	WindowAXDisabled       WindowFailure = "ax-api-disabled"
	WindowAXReadFailed     WindowFailure = "ax-windows-read-failed"
	WindowAXNoWindows      WindowFailure = "ax-no-windows"
	WindowAXGeometry       WindowFailure = "ax-geometry-unavailable"
	WindowAXNoMatch        WindowFailure = "ax-geometry-mismatch"
	WindowAXAmbiguous      WindowFailure = "ax-ambiguous-match"
	WindowAXLimit          WindowFailure = "ax-window-limit"
	WindowAXFocus          WindowFailure = "ax-focus-changed"
)

Jump to

Keyboard shortcuts

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