appstate

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 29 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 appstate builds live app snapshots for the computer-use server.

Code generated by textgen; DO NOT EDIT. Unicode data: textgen/LICENSE.unicode. Swift policy: textgen/NOTICE.swift.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrCaptureResourceLimit = errors.New("screenshot resource limit")

ErrCaptureResourceLimit reports a screenshot exceeding capture resource limits.

View Source
var ErrCaptureUnstable = errors.New("window capture geometry did not stabilize")

ErrCaptureUnstable reports geometry that failed consecutive stabilization checks.

View Source
var ErrContextImageUnavailable = errors.New("context image unavailable")
View Source
var ErrContextTargetChanged = errors.New("context target changed")
View Source
var ErrContextTreeUnavailable = errors.New("context tree unavailable")
View Source
var ErrContextWindowNotFound = errors.New("context window not found")

Functions

func CheckScreenshotGeometry added in v0.3.0

func CheckScreenshotGeometry(ctx context.Context, window *axuiautomation.Element, info *computeruse.ScreenshotInfo) error

CheckScreenshotGeometry checks the exact window ID, unrounded logical frame, and active display topology recorded in info. It does not capture pixels, verify process birth, or make dispatch atomic. The caller retains window's lifetime and handles authorization and intervention. The context bounds AX messaging waits. Nil arguments or invalid metadata return an error.

Example
package main

import (
	"context"
	"fmt"
	"github.com/tmc/axmcp/internal/computeruse/appstate"
)

func main() {
	err := appstate.CheckScreenshotGeometry(context.Background(), nil, nil)
	fmt.Println(err)
}
Output:
screenshot window and metadata required

func ListApps

func ListApps(ctx context.Context) ([]computeruse.AppInfo, error)

func PresentationNodeTextBytes added in v0.4.0

func PresentationNodeTextBytes(n *appshotlex.NativeNode, limit int) (int, error)

PresentationNodeTextBytes bounds retained lexical text without rendering.

Example
size, err := PresentationNodeTextBytes(presentationFixture("row"), 100)
fmt.Println(size, err)
Output:
3 <nil>

func ResolveApp

func ResolveApp(ctx context.Context, selector string) (computeruse.AppInfo, error)

func ValidatePresentationNode added in v0.4.0

func ValidatePresentationNode(n *appshotlex.NativeNode, maxTextBytes int) error

ValidatePresentationNode bounds input before invoking the shared lexer. It validates copied state, not the authenticity of supplied Unicode facts.

Example
fmt.Println(ValidatePresentationNode(presentationFixture("row"), 100))
Output:
<nil>

Types

type Builder

type Builder struct{}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, selector, windowTitle string, instructions computeruse.InstructionProvider) (*Snapshot, error)

func (*Builder) BuildWindow added in v0.3.0

func (b *Builder) BuildWindow(ctx context.Context, pid int32, windowID uint32, instructions computeruse.InstructionProvider) (*Snapshot, error)

BuildWindow captures one running process's exact window. A zero windowID selects its focused window; a positive ID must match exactly. It never launches an app or falls back to another window. The caller owns the returned snapshot. Process-instance validation across capture is the action runner's responsibility.

Example
builder := NewBuilder()
_, err := builder.BuildWindow(context.Background(), 0, 0, nil)
fmt.Println(err)
Output:
pid must be positive

func (*Builder) BuildWindowElement added in v0.3.0

func (b *Builder) BuildWindowElement(ctx context.Context, pid int32, window *axuiautomation.Element, instructions computeruse.InstructionProvider) (*Snapshot, error)

BuildWindowElement captures the live window matching a retained accessibility element in the exact process's window list. It never falls back to a window title, numeric ID, or focused window. The caller retains ownership of window; the returned snapshot independently owns its enumerated handles. The caller holds window alive and validates the process instance across capture.

Example
builder := NewBuilder()
_, err := builder.BuildWindowElement(context.Background(), 1, nil, nil)
fmt.Println(err)
Output:
window is required

type ContextCapture added in v0.4.0

type ContextCapture struct {
	Window computeruse.WindowInfo
	// Title is capture-only optional title evidence; nil means it was not supplied.
	Title *ContextTitle
	Nodes []ContextNode
	// Presentation is supplied only after native transformation and rendering.
	Presentation     *ContextPresentation
	PNG              []byte
	Screenshot       *computeruse.ScreenshotInfo
	ImageUnavailable bool
}

ContextCapture owns no accessibility handles or action-session authority.

func CaptureContextWindow added in v0.4.0

func CaptureContextWindow(ctx context.Context, info computeruse.AppInfo, windowID uint32, expected *axuiautomation.Element, maxNodes int, imageMode string) (ContextCapture, error)

CaptureContextWindow captures an exact retained window, or resolves a window once by ID (zero means focused). It never launches or activates an application. info is the caller-resolved application identity, not an authorization grant. expected remains owned by the caller. All internally obtained handles are released.

type ContextNode added in v0.4.0

type ContextNode struct {
	computeruse.ElementNode
	Subrole                string
	SecureValue            bool
	FloatValue             bool
	ValueType              computeruse.ValueType
	Focused                bool
	SelectedText           string
	WebFocus               *ContextNode
	WebDocument            bool
	RoleDescription        string
	RoleDescriptionPresent bool
	URL                    string
	Help                   string
	Placeholder            string
	ValueDescription       string
	// contains filtered or unexported fields
}

ContextNode contains capture-local data and a secure-plaintext omission marker.

type ContextPresentation added in v0.4.0

type ContextPresentation struct {
	Body, Focus                       []ContextPresentationRow
	SelectedText                      ContextPresentationText
	RawNodeCount, OmittedSecureValues int
}

ContextPresentation is the handle-free result of completed native rendering. Body and Focus are independent depth-first occurrence lists. Empty Body is valid after transformation of a nonempty raw capture.

func CopyContextPresentation added in v0.4.0

func CopyContextPresentation(ctx context.Context, p ContextPresentation, maxNodes, maxTextBytes int) (ContextPresentation, error)

CopyContextPresentation validates and copies a completed presentation before the caller closes its capture lease. Limits bound both forests cumulatively; callers must also charge acquisition and temporary work to their own ledger.

Example
p, err := CopyContextPresentation(context.Background(), ContextPresentation{RawNodeCount: 1}, 10, 1024)
fmt.Println(p.RawNodeCount, len(p.Body), err)
Output:
1 0 <nil>

type ContextPresentationIndex added in v0.4.0

type ContextPresentationIndex struct {
	Value   int
	Present bool
}

ContextPresentationIndex is copied provenance, not an action target.

type ContextPresentationRow added in v0.4.0

type ContextPresentationRow struct {
	Node                         *appshotlex.NativeNode
	Depth                        int
	RawPosition, RenderElementID ContextPresentationIndex
	DetailText                   ContextPresentationText
}

ContextPresentationRow is one occurrence in an admitted render forest. Depth belongs to that forest; RawPosition belongs to acquisition.

type ContextPresentationText added in v0.4.0

type ContextPresentationText struct {
	Text    string
	Present bool
}

ContextPresentationText preserves absent and present-empty text.

type ContextTitle added in v0.4.0

type ContextTitle struct {
	Text    string
	Present bool
}

ContextTitle preserves the distinction between absent and present-empty title metadata. Text is empty when Present is false.

Example
absent := ContextTitle{}
empty := ContextTitle{Present: true}
fmt.Printf("absent: present=%t text=%q\n", absent.Present, absent.Text)
fmt.Printf("empty: present=%t text=%q\n", empty.Present, empty.Text)
Output:
absent: present=false text=""
empty: present=true text=""

type Snapshot

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

func (*Snapshot) App

func (*Snapshot) Close

func (s *Snapshot) Close() error

func (*Snapshot) Resolve

func (*Snapshot) State

func (s *Snapshot) State() computeruse.AppState

Directories

Path Synopsis
Command textgen generates the fixed native text profile from pinned inputs.
Command textgen generates the fixed native text profile from pinned inputs.

Jump to

Keyboard shortcuts

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