automation

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 5 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 automation is the protocol between the nsgo tool and an app `nsgo dev -automation` built: the tool sends a Request and the app's agent (package nsgotest) answers it. Tool and app come from one module version, so the protocol is internal and unversioned; MCP (`nsgo mcp`) and nsgotest are the public interfaces (docs/architecture/tool.md, Automation).

Index

Constants

View Source
const (
	Windows    = "windows"
	Snapshot   = "snapshot"
	Find       = "find"
	Press      = "press"
	Type       = "type"
	Key        = "key"
	Scroll     = "scroll"
	Drag       = "drag"
	Hover      = "hover"
	Menu       = "menu"
	Alert      = "alert"
	Wait       = "wait"
	Screenshot = "screenshot"
)

The app's methods, which its agent answers.

View Source
const (
	Status = "status"
	Logs   = "logs"
	Reload = "reload"
)

The tool's methods, which nsgo dev answers itself.

View Source
const AppToolListTimeout = 250 * time.Millisecond

AppToolListTimeout bounds discovery while the graph is busy.

View Source
const ListAppTools = "_nsgo/list-app-tools"

ListAppTools asks for the running graph's app-defined tools.

Variables

View Source
var (
	ErrUnknownAppTool = errors.New("automation: unknown app tool")
	ErrAppToolInput   = errors.New("automation: expected a JSON object")
)
View Source
var Params = map[string]func() any{
	Windows: func() any { return &WindowsParams{} }, Snapshot: func() any { return &SnapshotParams{} },
	Find: func() any { return &FindParams{} }, Press: func() any { return &PressParams{} },
	Type: func() any { return &TypeParams{} }, Key: func() any { return &KeyParams{} },
	Scroll: func() any { return &ScrollParams{} }, Drag: func() any { return &DragParams{} },
	Hover: func() any { return &HoverParams{} }, Menu: func() any { return &MenuParams{} },
	Alert: func() any { return &AlertParams{} }, Wait: func() any { return &WaitParams{} },
	Screenshot: func() any { return &ScreenshotParams{} },
	Status:     func() any { return &StatusParams{} }, Logs: func() any { return &LogsParams{} },
	Reload: func() any { return &ReloadParams{} },
}

Params are each method's params type, as a new value.

Functions

func ValidateAppTool

func ValidateAppTool(tool AppTool) error

ValidateAppTool checks the published name and the MCP input shape.

Types

type AlertInfo

type AlertInfo struct {
	ID      uint32   `json:"id"`
	Window  uint32   `json:"window"`
	Title   string   `json:"title,omitempty"`
	Message string   `json:"message,omitempty"`
	Buttons []string `json:"buttons"`
}

AlertInfo is an alert showing, which a window or an app's own surface (window 0 for the first graph) shows.

type AlertParams

type AlertParams struct {
	Window *uint32 `` /* 128-byte string literal not displayed */
	ID     uint32  `` /* 147-byte string literal not displayed */
	Answer *int    `json:"answer,omitempty" jsonschema:"press the button at this index, or -1 to dismiss; without it the alerts are listed"`
}

AlertParams list the alerts showing, or answer one.

type AlertResult

type AlertResult struct {
	Alerts []AlertInfo `json:"alerts"`
}

AlertResult lists the alerts showing, oldest first, after any answer.

type Answer

type Answer struct {
	ID     uint64          `json:"id"`
	Result json.RawMessage `json:"result,omitempty"`
	Error  *Error          `json:"error,omitempty"`
}

Answer answers the Request of its ID with Result, one of the result types below, or Error.

func Reply

func Reply(id uint64, result any, err *Error) Answer

Reply is the Answer to request id: result as JSON, or err.

type AppTool

type AppTool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"inputSchema"`
}

AppTool is the published description of a tool the app registered.

type Code

type Code string

Code says what kind of failure an Error is.

const (
	// InvalidRequest is a request that cannot be read: bad JSON, a bad selector, a button the alert lacks.
	InvalidRequest Code = "invalid_request"
	// UnknownMethod names no method.
	UnknownMethod Code = "unknown_method"
	// NoApp is a request no app connected to answer, or whose app went away.
	NoApp Code = "no_app"
	// NoWindow names no window the app shows.
	NoWindow Code = "no_window"
	// NoMatch is a selector or a menu path that matches nothing shown.
	NoMatch Code = "no_match"
	// Unsupported is what the platform cannot do, such as screenshots headless.
	Unsupported Code = "unsupported"
	// Timeout is a wait that ran out of time.
	Timeout Code = "timeout"
	// Failed is a step that could not be taken, such as a press on a disabled view.
	Failed Code = "failed"
)

type DragParams

type DragParams struct {
	Window   uint32  `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string  `` /* 203-byte string literal not displayed */
	At       *Point  `json:"at,omitempty" jsonschema:"start at this point of the match, in its own points, instead of its middle"`
	Path     []Point `json:"path" jsonschema:"the points to move through, as offsets from where the drag starts"`
	Snapshot bool    `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

DragParams drag from what a selector names.

type Element

type Element struct {
	// Ref is a selector naming the view alone, view:<node>, until the app starts again.
	Ref    string   `json:"ref"`
	Role   string   `json:"role"`
	Name   string   `json:"name,omitempty"`
	Text   string   `json:"text,omitempty"`
	Value  string   `json:"value,omitempty"`
	TestID string   `json:"test_id,omitempty"`
	States []string `json:"states,omitempty"`
	// Bounds are its frame in the window's points: x, y, width, height.
	Bounds *[4]float64 `json:"bounds,omitempty"`
}

Element is a view a selector matched.

type Error

type Error struct {
	Code    Code   `json:"code"`
	Message string `json:"message"`
}

Error is why a request failed.

func Errorf

func Errorf(code Code, format string, args ...any) *Error

Errorf returns an Error of code with a formatted message.

func (*Error) Error

func (e *Error) Error() string

type FindParams

type FindParams struct {
	Window   uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string `` /* 203-byte string literal not displayed */
	Mounted  bool   `json:"mounted,omitempty" jsonschema:"match every view mounted, shown or not"`
}

FindParams list the elements a selector matches.

type FindResult

type FindResult struct {
	Elements []Element `json:"elements"`
}

FindResult lists what a selector matched, in the order a user finds it.

type HoverParams

type HoverParams struct {
	Window   uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string `` /* 203-byte string literal not displayed */
	Snapshot bool   `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

HoverParams move the mouse over what a selector names.

type KeyParams

type KeyParams struct {
	Window   uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string `` /* 126-byte string literal not displayed */
	Key      string `` /* 128-byte string literal not displayed */
	Snapshot bool   `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

KeyParams press a key.

type LogsParams

type LogsParams struct {
	Lines int `json:"lines,omitempty" jsonschema:"how many of the latest lines; 200 by default, 2000 at most"`
}

LogsParams read the app's latest output.

type LogsResult

type LogsResult struct {
	Lines []string `json:"lines"`
}

LogsResult is the app's latest output, oldest line first.

type MenuParams struct {
	Window   uint32   `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Path     []string `json:"path" jsonschema:"the item's labels from the menu bar down, such as File, New"`
	Popup    bool     `json:"popup,omitempty" jsonschema:"choose in the context menu showing instead of the application menu"`
	Dock     bool     `` /* 221-byte string literal not displayed */
	Snapshot bool     `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

MenuParams choose a menu item.

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Point is a point in a view's own points, from its top left.

type PressParams

type PressParams struct {
	Window   uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string `` /* 203-byte string literal not displayed */
	At       *Point `json:"at,omitempty" jsonschema:"press this point of the match, in its own points, instead of its middle"`
	Mode     string `json:"mode,omitempty" jsonschema:"tap (the default), long or right"`
	Snapshot bool   `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

PressParams press what a selector names.

type ReloadParams

type ReloadParams struct{}

ReloadParams build and start the app again.

type Request

type Request struct {
	ID     uint64          `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

Request asks the app, or the tool for Status, Logs and Reload, to do Method with Params, one of the params types below.

type ScreenshotParams

type ScreenshotParams struct {
	Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
}

ScreenshotParams capture a window.

type ScreenshotResult

type ScreenshotResult struct {
	PNG    []byte `json:"png"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

ScreenshotResult is a window as a PNG, in pixels.

type ScrollParams

type ScrollParams struct {
	Window   uint32   `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string   `` /* 203-byte string literal not displayed */
	By       float64  `json:"by,omitempty" jsonschema:"points to scroll along the view's axis; positive shows what is further down or right"`
	To       *float64 `json:"to,omitempty" jsonschema:"the offset to scroll to along the view's axis, instead of by"`
	Snapshot bool     `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

ScrollParams scroll the scroll view a selector names, or the one around it.

type SnapshotParams

type SnapshotParams struct {
	Window uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	All    bool   `json:"all,omitempty" jsonschema:"list every view shown, containers too, not only the named ones"`
	Bounds bool   `json:"bounds,omitempty" jsonschema:"add each element's frame in the window's points"`
}

SnapshotParams outline what a window shows.

type SnapshotResult

type SnapshotResult struct {
	Window uint32 `json:"window"`
	Text   string `json:"text"`
}

SnapshotResult outlines what a window shows, an element a line: `- button "Add" [view:12] id=add focused`.

type StatusParams

type StatusParams struct{}

StatusParams ask how the app's build and run stand.

type StatusResult

type StatusResult struct {
	Target     string `json:"target"`
	Building   bool   `json:"building"`
	BuildError string `json:"build_error,omitempty"`
	// App is whether a running app is connected; Run counts the apps that connected, and view refs of an earlier run are stale.
	App bool `json:"app"`
	Run int  `json:"run"`
}

StatusResult is how the app's build and run stand.

type StepResult

type StepResult struct {
	Settled  bool   `json:"settled"`
	Snapshot string `json:"snapshot,omitempty"`
}

StepResult is what a step left: Settled is false when the app kept changing past the step's wait of 5 seconds.

type TypeParams

type TypeParams struct {
	Window   uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector string `` /* 203-byte string literal not displayed */
	Text     string `json:"text,omitempty" jsonschema:"what to type at the end of the field's text"`
	Clear    bool   `json:"clear,omitempty" jsonschema:"empty the field first"`
	Submit   bool   `json:"submit,omitempty" jsonschema:"press Return after typing"`
	Snapshot bool   `json:"snapshot,omitempty" jsonschema:"answer with the window's snapshot after the step"`
}

TypeParams type into the field a selector names.

type WaitParams

type WaitParams struct {
	Window    uint32 `json:"window,omitempty" jsonschema:"a window ID as windows lists it; the newest window by default"`
	Selector  string `` /* 203-byte string literal not displayed */
	Gone      bool   `json:"gone,omitempty" jsonschema:"wait until nothing matches instead"`
	TimeoutMS int    `json:"timeout_ms,omitempty" jsonschema:"how long to wait in milliseconds; 5000 by default, 60000 at most"`
}

WaitParams wait until a selector matches, or matches nothing.

type Window

type Window struct {
	ID uint32 `json:"id"`
	// Graph numbers the engine's reactive graph within the process, from 1, telling apart surfaces of several engines in one host.
	Graph  int     `json:"graph,omitempty"`
	Title  string  `json:"title"`
	Kind   string  `json:"kind"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
	// Default is the window requests without a window act on.
	Default bool `json:"default,omitempty"`
}

Window is a window or embedded view the process shows.

type WindowsParams

type WindowsParams struct{}

WindowsParams lists the app's windows.

type WindowsResult

type WindowsResult struct {
	Windows []Window `json:"windows"`
}

WindowsResult lists the app's windows, oldest first.

Jump to

Keyboard shortcuts

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