appshot

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: 6 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 appshot captures and formats immutable accessibility context with an optional exact-window PNG. Attachment indices do not authorize later actions.

Capture intervals describe observations that are not atomic. Secure AX values are omitted; images may still contain sensitive visible content.

Example
package main

import (
	"fmt"
	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	options, err := (appshot.Options{Image: "omit"}).Normalize()
	if err != nil {
		panic(err)
	}
	fmt.Println(options.Image, options.MaxNodes)
}
Output:
omit 2000

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgumentFields

func ArgumentFields(data []byte) (map[string]json.RawMessage, error)
Example
package main

import (
	"fmt"

	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	fields, err := appshot.ArgumentFields([]byte(`{"image":"omit"}`))
	fmt.Println(string(fields["image"]), err)
}
Output:
"omit" <nil>

func ErrorCode

func ErrorCode(err error) string
Example
package main

import (
	"fmt"
	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	fmt.Println(appshot.ErrorCode(appshot.NewError("tree_unavailable", fmt.Errorf("empty tree"))))
}
Output:
tree_unavailable

func Export

func Export(ctx context.Context, directory string, result Result) error
Example
package main

import (
	"context"
	"fmt"
	"os"
	"path/filepath"
	"time"

	"github.com/tmc/axmcp/internal/appshot"
	"github.com/tmc/axmcp/internal/computeruse"
)

func main() {
	dir, err := exampleWorkspace("appshot-example-")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer os.RemoveAll(dir)
	r := appshot.Result{Version: 1, AppshotID: "example", App: computeruse.AppInfo{Name: "Example", BundleID: "com.example"}, Context: "<appshot app=\"Example\" bundle-identifier=\"com.example\">\n[0] AXWindow\n</appshot>"}
	if err := appshot.Export(context.Background(), filepath.Join(dir, "capture"), r); err != nil {
		fmt.Println(err)
		return
	}
	data, err := os.ReadFile(filepath.Join(dir, "capture", "context.txt"))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(data) == r.Context)
}

// exampleWorkspace creates a private directory; the example removes it after use.
func exampleWorkspace(pattern string) (string, error) {
	home, err := os.UserHomeDir()
	if err != nil {
		return "", err
	}
	base := filepath.Join(home, "tmp", "axmcp", time.Now().Format("20060102")+"-tests")
	if err := os.MkdirAll(base, 0700); err != nil {
		return "", err
	}
	return os.MkdirTemp(base, pattern)
}
Output:
true

func ExportChecked

func ExportChecked(ctx context.Context, directory string, result Result, check func(context.Context) error) error
Example
package main

import (
	"context"
	"fmt"
	"os"
	"path/filepath"
	"time"

	"github.com/tmc/axmcp/internal/appshot"
	"github.com/tmc/axmcp/internal/computeruse"
)

func main() {
	dir, err := exampleWorkspace("appshot-check-example-")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer os.RemoveAll(dir)
	r := appshot.Result{Version: 1, AppshotID: "example", App: computeruse.AppInfo{Name: "Example", BundleID: "com.example"}, Context: "<appshot app=\"Example\" bundle-identifier=\"com.example\">\n[0] AXWindow\n</appshot>"}
	err = appshot.ExportChecked(context.Background(), filepath.Join(dir, "capture"), r, func(context.Context) error {
		return appshot.NewError("permission_denied", fmt.Errorf("access revoked"))
	})
	fmt.Println(appshot.ErrorCode(err))
}

// exampleWorkspace creates a private directory; the example removes it after use.
func exampleWorkspace(pattern string) (string, error) {
	home, err := os.UserHomeDir()
	if err != nil {
		return "", err
	}
	base := filepath.Join(home, "tmp", "axmcp", time.Now().Format("20060102")+"-tests")
	if err := os.MkdirAll(base, 0700); err != nil {
		return "", err
	}
	return os.MkdirTemp(base, pattern)
}
Output:
permission_denied

func NewError

func NewError(code string, err error) error
Example
package main

import (
	"fmt"
	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	fmt.Println(appshot.NewError("window_not_found", fmt.Errorf("window closed")))
}
Output:
window_not_found: window closed

func ValidatePNG

func ValidatePNG(data []byte, metadata *computeruse.ScreenshotInfo) error
Example
package main

import (
	"fmt"

	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	err := appshot.ValidatePNG([]byte("not a PNG"), nil)
	fmt.Println(appshot.ErrorCode(err))
}
Output:
image_unavailable

func WriteContext

func WriteContext(w io.Writer, result Result) error
Example
package main

import (
	"fmt"
	"strings"

	"github.com/tmc/axmcp/internal/appshot"
)

func main() {
	var text strings.Builder
	if err := appshot.WriteContext(&text, appshot.Result{Context: "captured context"}); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(text.String())
}
Output:
captured context

Types

type Error

type Error = core.Error

type ImageInfo

type ImageInfo = core.ImageInfo

type Node

type Node = core.Node

type Options

type Options = core.Options

type ProcessStart

type ProcessStart = core.ProcessStart

type Result

type Result = core.Result

func Build

func Build(app computeruse.AppInfo, window computeruse.WindowInfo, birth ProcessStart, nodes []Node, data []byte, metadata *computeruse.ScreenshotInfo, options Options, started, finished time.Time) (Result, error)
Example
package main

import (
	"fmt"
	"time"

	"github.com/tmc/axmcp/internal/appshot"
	"github.com/tmc/axmcp/internal/computeruse"
)

func main() {
	nodes := []appshot.Node{{ElementNode: computeruse.ElementNode{Role: "AXWindow", ParentIndex: -1}}}
	now := time.Unix(0, 0)
	r, err := appshot.Build(computeruse.AppInfo{Name: "Example"}, computeruse.WindowInfo{WindowID: 1}, appshot.ProcessStart{}, nodes, nil, nil, appshot.Options{Image: "omit"}, now, now)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(r.Version, r.Tree.NodeCount)
}
Output:
1 1

type TreeInfo

type TreeInfo = core.TreeInfo

Directories

Path Synopsis
Package core implements capture, validation, and export for appshot.
Package core implements capture, validation, and export for appshot.
Package testfixture supplies Appshot image fixtures.
Package testfixture supplies Appshot image fixtures.

Jump to

Keyboard shortcuts

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