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 ¶
- func ArgumentFields(data []byte) (map[string]json.RawMessage, error)
- func ErrorCode(err error) string
- func Export(ctx context.Context, directory string, result Result) error
- func ExportChecked(ctx context.Context, directory string, result Result, ...) error
- func NewError(code string, err error) error
- func ValidatePNG(data []byte, metadata *computeruse.ScreenshotInfo) error
- func WriteContext(w io.Writer, result Result) error
- type Error
- type ImageInfo
- type Node
- type Options
- type ProcessStart
- type Result
- type TreeInfo
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 ¶
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 ¶
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 ¶
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 ¶
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 ProcessStart ¶
type ProcessStart = core.ProcessStart
type 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
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. |