Documentation
¶
Overview ¶
Package appshot captures a running macOS application's accessibility context and an optional PNG of the same window.
Use Capture to collect an appshot. WriteContext writes the formatted accessibility context, Export saves the capture as a directory, and ModelInputs prepares text and image inputs for a model client.
The context and image may contain sensitive information visible in the window.
Example ¶
package main
import (
"fmt"
"github.com/tmc/axmcp/appshot"
)
func main() {
opts, err := (appshot.Options{Image: appshot.ImageOmit}).Normalize()
if err != nil {
return
}
fmt.Println(opts.Image, opts.TimeoutMS)
}
Output: omit 30000
Index ¶
- Variables
- func ErrorCode(err error) string
- func Export(dir string, result Result) error
- func ExportChecked(ctx context.Context, dir string, result Result, ...) error
- func NewError(code string, err error) error
- func WriteContext(w io.Writer, result Result) error
- type AppInfo
- type DisplayInfo
- type Error
- type ImageInfo
- type ImageMetadata
- type ImagePolicy
- type ModelInput
- type Options
- type ProcessStart
- type Rect
- type Result
- type TreeInfo
- type WindowInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = NewError("unsupported", errors.New("appshot capture requires macOS"))
ErrUnsupported reports that native capture is unavailable on this platform.
Functions ¶
func ErrorCode ¶
ErrorCode returns the stable failure code or an empty string for unclassified errors. It recognizes context cancellation and deadline errors.
func Export ¶
Export writes the capture to a new private directory. It fails if dir already exists and leaves the existing path intact. The parent directory must exist and its path must be free of symbolic links.
func ExportChecked ¶
func ExportChecked(ctx context.Context, dir string, result Result, access func(context.Context) error) error
ExportChecked writes the capture to a new private directory. If access is non-nil, it runs immediately before publication. A failed check prevents publication. The caller supplies any live authorization checks.
func WriteContext ¶
WriteContext writes the capture's formatted accessibility context to w.
Example ¶
package main
import (
"os"
"github.com/tmc/axmcp/appshot"
)
func main() {
result := appshot.Result{
Context: `<appshot app="TextEdit" bundle-identifier="com.apple.TextEdit">TextEdit</appshot>`,
}
if err := appshot.WriteContext(os.Stdout, result); err != nil {
return
}
}
Output: <appshot app="TextEdit" bundle-identifier="com.apple.TextEdit">TextEdit</appshot>
Types ¶
type AppInfo ¶
type AppInfo struct {
Name string `json:"name,omitempty"`
BundleID string `json:"bundle_id,omitempty"`
PID int `json:"pid,omitempty"`
}
AppInfo identifies the running process observed by capture.
type DisplayInfo ¶
type DisplayInfo struct {
ID uint32 `json:"id"`
Bounds Rect `json:"bounds"`
PixelWidth int `json:"pixel_width"`
PixelHeight int `json:"pixel_height"`
}
DisplayInfo describes a display's logical bounds and physical dimensions.
type ImageInfo ¶
type ImageInfo struct {
Name string `json:"name"`
MIMEType string `json:"mime_type"`
Metadata ImageMetadata `json:"metadata"`
}
ImageInfo describes the optional PNG attachment.
type ImageMetadata ¶
type ImageMetadata struct {
ImageID string `json:"image_id"`
Width int `json:"width"`
Height int `json:"height"`
SourceKind string `json:"source_kind"`
TargetWindow uint32 `json:"target_window"`
GlobalRect Rect `json:"global_rect"`
ScaleX float64 `json:"scale_x"`
ScaleY float64 `json:"scale_y"`
Displays []DisplayInfo `json:"displays"`
}
ImageMetadata binds PNG pixels to their source window. Scale factors measure pixels per logical point on each axis.
type ImagePolicy ¶
type ImagePolicy string
ImagePolicy controls whether capture includes a window image.
const ( // ImageAuto includes an image when available and otherwise returns context alone. ImageAuto ImagePolicy = "auto" // ImageRequired makes an unavailable image a capture error. ImageRequired ImagePolicy = "required" // ImageOmit captures accessibility context alone. ImageOmit ImagePolicy = "omit" )
type ModelInput ¶
type ModelInput struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL string `json:"image_url,omitempty"`
Detail string `json:"detail,omitempty"`
}
ModelInput contains either text or an image data URL for a model client.
func ModelInputs ¶
func ModelInputs(result Result) ([]ModelInput, error)
ModelInputs validates a capture and returns its context as an input_text item followed, when available, by an input_image item containing the PNG.
Example ¶
package main
import (
"fmt"
"github.com/tmc/axmcp/appshot"
)
func main() {
result := appshot.Result{
Version: 1,
AppshotID: "example",
App: appshot.AppInfo{Name: "TextEdit", BundleID: "com.apple.TextEdit"},
Context: `<appshot app="TextEdit" bundle-identifier="com.apple.TextEdit">TextEdit</appshot>`,
}
inputs, err := appshot.ModelInputs(result)
if err != nil {
return
}
fmt.Println(inputs[0].Type)
}
Output: input_text
type Options ¶
type Options struct {
Image ImagePolicy `json:"image,omitempty"`
TimeoutMS int `json:"timeout_ms,omitempty"`
MaxNodes int `json:"max_nodes,omitempty"`
MaxTextBytes int `json:"max_text_bytes,omitempty"`
}
Options sets the limits and image policy for a capture. Zero values select the defaults documented by Options.Normalize.
type ProcessStart ¶
type ProcessStart struct {
Seconds int64 `json:"seconds"`
Microseconds int64 `json:"microseconds"`
}
ProcessStart records when the operating system started the captured process.
type Rect ¶
type Rect struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
Rect describes a rectangle in global macOS logical points.
type Result ¶
type Result struct {
Version int `json:"version"`
AppshotID string `json:"appshot_id"`
CapturedAt time.Time `json:"captured_at"`
CaptureStartedAt time.Time `json:"capture_started_at"`
CaptureFinishedAt time.Time `json:"capture_finished_at"`
App AppInfo `json:"app"`
ProcessStart ProcessStart `json:"process_start"`
Window WindowInfo `json:"window"`
Context string `json:"context"`
Tree TreeInfo `json:"tree"`
Image *ImageInfo `json:"image,omitempty"`
Warnings []string `json:"warnings"`
PNG []byte `json:"-"`
// contains filtered or unexported fields
}
Result holds an owned capture. Its JSON encoding uses version-1 metadata with PNG bytes kept in the separate PNG field.
func Capture ¶
Capture returns ErrUnsupported on platforms other than macOS.
func (Result) ScreenRecordingRequired ¶
ScreenRecordingRequired reports whether the capture needs screen recording access when it is published. A capture that observed a grant can require this check even when its result contains context alone.
type TreeInfo ¶
type TreeInfo struct {
NodeCount int `json:"node_count"`
Truncated bool `json:"truncated"`
OmittedSecureValues int `json:"omitted_secure_values"`
Limit string `json:"limit,omitempty"`
}
TreeInfo describes traversal and output limits for the accessibility context.
type WindowInfo ¶
type WindowInfo struct {
WindowID uint32 `json:"window_id,omitempty"`
Title string `json:"title,omitempty"`
X int `json:"x,omitempty"`
Y int `json:"y,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
ScreenshotWidth int `json:"screenshot_width,omitempty"`
ScreenshotHeight int `json:"screenshot_height,omitempty"`
}
WindowInfo describes the target window in logical points and the PNG size in pixels.