diff --git a/Makefile b/Makefile index 70b60ee..21a4b36 100644 --- a/Makefile +++ b/Makefile @@ -150,15 +150,17 @@ java: # within a week. api: @go run ./internal/apisurface/generate . + @go run ./internal/apisurface/outputschema . > /dev/null @echo "api surface written" # api-check fails if the generated files are out of date, so a tool added # without regenerating them is caught in CI rather than read as truth later. api-check: @go run ./internal/apisurface/generate . - @git diff --quiet -- docs/API.md docs/api/surface.json || { \ - echo "docs/API.md or docs/api/surface.json is stale — run 'make api' and commit the result"; \ - git --no-pager diff --stat -- docs/API.md docs/api/surface.json; \ + @go run ./internal/apisurface/outputschema . > /dev/null + @git diff --quiet -- docs/API.md docs/api/surface.json internal/agent/outputschema_gen.go || { \ + echo "docs/API.md, docs/api/surface.json or internal/agent/outputschema_gen.go is stale — run 'make api' and commit the result"; \ + git --no-pager diff --stat -- docs/API.md docs/api/surface.json internal/agent/outputschema_gen.go; \ exit 1; } @echo "api surface current" diff --git a/docs/guides/mcp.md b/docs/guides/mcp.md index a1c254f..d7bd4c0 100644 --- a/docs/guides/mcp.md +++ b/docs/guides/mcp.md @@ -152,8 +152,18 @@ cut short and its schema reduced to the argument names: Every schema says `additionalProperties: false`, so an argument a tool does not take is refused rather than ignored. `readOnlyHint` is on every tool: -true for the 19 that only read — `app_map`, `app_text`, `app_state` and the -like — and false for everything that can change the device. +true for the 22 that only read — `app_map`, `app_text`, `app_state` and the +like — and false for everything that can change the device; tools that act +also say `destructiveHint` and `idempotentHint` where they can (section 7). + +68 of the 78 tools also carry an `outputSchema`: the shape of the +`structuredContent` every successful call returns, so a client can check +what it is handed. It is generated from the code by Go's type checker +(`internal/apisurface/outputschema`, run by `make api`), and only for a +tool that always answers with one type; the other ten, such as +`app_screenshot`, `app_batch` and `app_logs`, answer with an image or with +one of several shapes, and carry none. A test holds every schema to empty +and filled values of its type, and `make ci` fails when one is out of date. ## 4. Answers: text, data and images diff --git a/internal/agent/outputschema.go b/internal/agent/outputschema.go new file mode 100644 index 0000000..2766f72 --- /dev/null +++ b/internal/agent/outputschema.go @@ -0,0 +1,17 @@ +package agent + +import "encoding/json" + +// OutputSchema is the tool's MCP outputSchema, or nil for a tool without +// one (outputschema_gen.go says which have one; make api regenerates it). +func OutputSchema(name string) map[string]interface{} { + raw, ok := outputSchemas[name] + if !ok { + return nil + } + var s map[string]interface{} + if json.Unmarshal([]byte(raw), &s) != nil { + return nil + } + return s +} diff --git a/internal/agent/outputschema_gen.go b/internal/agent/outputschema_gen.go new file mode 100644 index 0000000..3a1370b --- /dev/null +++ b/internal/agent/outputschema_gen.go @@ -0,0 +1,153 @@ +// Code generated by internal/apisurface/outputschema; DO NOT EDIT. + +package agent + +import ( + "github.com/mobiumdev/mobium/internal/device" +) + +// outputSchemas are the tools' MCP outputSchema, each the shape of the +// structuredContent every successful call of the tool returns. +var outputSchemas = map[string]string{ + "app_accessibility": "{\"properties\":{\"device\":{\"type\":\"string\"},\"previous\":{\"type\":\"string\"},\"restored\":{\"type\":\"boolean\"},\"setting\":{\"type\":\"string\"},\"settings\":{\"additionalProperties\":{\"type\":\"string\"},\"type\":[\"object\",\"null\"]},\"unsupported\":{\"additionalProperties\":{\"type\":\"string\"},\"type\":[\"object\",\"null\"]},\"value\":{\"type\":\"string\"}},\"required\":[\"device\"],\"type\":\"object\"}", + "app_alert": "{\"properties\":{\"answered\":{\"type\":\"string\"},\"buttons\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"device\":{\"type\":\"string\"},\"note\":{\"type\":\"string\"},\"present\":{\"type\":\"boolean\"},\"pressed\":{\"type\":\"string\"},\"text\":{\"type\":\"string\"},\"typed\":{\"type\":\"string\"}},\"required\":[\"device\",\"present\"],\"type\":\"object\"}", + "app_appearance": "{\"properties\":{\"appearance\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"previous\":{\"type\":\"string\"}},\"required\":[\"appearance\",\"device\"],\"type\":\"object\"}", + "app_audio": "{\"properties\":{\"app\":{\"type\":\"string\"},\"bytes\":{\"type\":\"integer\"},\"data\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"duration\":{\"type\":\"integer\"},\"elapsed\":{\"type\":\"integer\"},\"interruptions\":{\"items\":{\"properties\":{\"from\":{\"type\":\"integer\"},\"kind\":{\"type\":\"string\"},\"open\":{\"type\":\"boolean\"},\"reason\":{\"type\":\"string\"},\"to\":{\"type\":\"integer\"},\"usage\":{\"type\":\"string\"}},\"required\":[\"from\",\"kind\",\"to\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"note\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"},\"recording\":{\"type\":\"boolean\"},\"timeline\":{\"items\":{\"properties\":{\"from\":{\"type\":\"integer\"},\"hz\":{\"type\":\"number\"},\"level\":{\"type\":\"number\"},\"sound\":{\"type\":\"boolean\"},\"to\":{\"type\":\"integer\"}},\"required\":[\"from\",\"sound\",\"to\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"volumes\":{\"items\":{\"properties\":{\"index\":{\"type\":\"integer\"},\"max\":{\"type\":\"integer\"},\"min\":{\"type\":\"integer\"},\"muted\":{\"type\":\"boolean\"},\"stream\":{\"type\":\"string\"}},\"required\":[\"index\",\"max\",\"min\",\"stream\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"volumesAtStart\":{\"items\":{\"properties\":{\"index\":{\"type\":\"integer\"},\"max\":{\"type\":\"integer\"},\"min\":{\"type\":\"integer\"},\"muted\":{\"type\":\"boolean\"},\"stream\":{\"type\":\"string\"}},\"required\":[\"index\",\"max\",\"min\",\"stream\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"device\",\"recording\"],\"type\":\"object\"}", + "app_audit": "{\"properties\":{\"device\":{\"type\":\"string\"},\"findings\":{\"items\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":[\"object\",\"null\"]},\"detail\":{\"type\":\"string\"},\"element\":{\"type\":\"string\"},\"locator\":{\"type\":\"string\"},\"summary\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"}},\"required\":[\"summary\",\"type\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"unchecked\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"device\",\"findings\"],\"type\":\"object\"}", + "app_background": "{\"properties\":{\"app\":{\"type\":\"string\"},\"away_ms\":{\"type\":\"integer\"},\"device\":{\"type\":\"string\"},\"seconds\":{\"type\":\"number\"}},\"required\":[\"app\",\"away_ms\",\"device\",\"seconds\"],\"type\":\"object\"}", + "app_battery": "{\"properties\":{\"device\":{\"type\":\"string\"},\"level\":{\"type\":[\"integer\",\"null\"]},\"plugged\":{\"type\":\"string\"},\"present\":{\"type\":\"boolean\"},\"state\":{\"type\":\"string\"}},\"required\":[\"device\",\"present\",\"state\"],\"type\":\"object\"}", + "app_biometric": "{\"properties\":{\"device\":{\"type\":\"string\"},\"enrolled\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"locked_out\":{\"type\":\"boolean\"},\"note\":{\"type\":\"string\"},\"outcome\":{\"type\":\"string\"}},\"required\":[\"device\",\"enrolled\",\"kind\"],\"type\":\"object\"}", + "app_boot": "{\"properties\":{\"already\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"platform\":{\"type\":\"string\"},\"took\":{\"type\":\"string\"}},\"required\":[\"already\",\"device\",\"name\",\"platform\"],\"type\":\"object\"}", + "app_call": "{\"properties\":{\"action\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"number\":{\"type\":\"string\"}},\"required\":[\"action\",\"device\",\"number\"],\"type\":\"object\"}", + "app_check": "{\"properties\":{\"claim\":{\"type\":\"string\"},\"evidence\":{\"items\":{\"properties\":{\"summary\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"}},\"required\":[\"summary\",\"type\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"model\":{\"type\":\"string\"},\"record\":{\"type\":\"string\"},\"status\":{\"type\":\"string\"},\"steps\":{\"type\":\"integer\"},\"summary\":{\"type\":\"string\"}},\"required\":[\"claim\",\"evidence\",\"model\",\"record\",\"status\",\"steps\",\"summary\"],\"type\":\"object\"}", + "app_clear_data": "{\"properties\":{\"app\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"emptied\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"kept\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"not_read_back\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"still_granted\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"app\",\"device\",\"emptied\",\"still_granted\"],\"type\":\"object\"}", + "app_clipboard": "{\"properties\":{\"device\":{\"type\":\"string\"},\"known\":{\"type\":\"boolean\"},\"text\":{\"type\":\"string\"}},\"required\":[\"device\",\"known\"],\"type\":\"object\"}", + "app_context": "{\"properties\":{\"current\":{\"type\":\"boolean\"},\"id\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"}},\"required\":[\"id\"],\"type\":\"object\"}", + "app_contexts": "{\"properties\":{\"behind\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"contexts\":{\"items\":{\"properties\":{\"current\":{\"type\":\"boolean\"},\"id\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"}},\"required\":[\"id\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"current\":{\"type\":\"string\"}},\"required\":[\"contexts\",\"current\"],\"type\":\"object\"}", + "app_cookies": "{\"properties\":{\"action\":{\"type\":\"string\"},\"cleared\":{\"type\":\"integer\"},\"context\":{\"type\":\"string\"},\"cookies\":{\"items\":{\"properties\":{\"domain\":{\"type\":\"string\"},\"expires\":{\"type\":\"number\"},\"httpOnly\":{\"type\":\"boolean\"},\"name\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"},\"sameSite\":{\"type\":\"string\"},\"secure\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"}},\"required\":[\"name\",\"value\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"device\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"}},\"required\":[\"action\",\"context\",\"cookies\",\"device\",\"url\"],\"type\":\"object\"}", + "app_crashes": "{\"properties\":{\"app\":{\"type\":\"string\"},\"crashes\":{\"items\":{\"properties\":{\"app\":{\"type\":\"string\"},\"dropped\":{\"type\":\"integer\"},\"id\":{\"type\":\"string\"},\"kind\":{\"type\":\"string\"},\"summary\":{\"type\":\"string\"},\"text\":{\"type\":\"string\"},\"time\":{}},\"required\":[\"id\",\"kind\",\"time\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"device\":{\"type\":\"string\"},\"total\":{\"type\":\"integer\"}},\"required\":[\"crashes\",\"device\"],\"type\":\"object\"}", + "app_current": "{\"properties\":{\"app\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"}},\"required\":[\"app\",\"device\"],\"type\":\"object\"}", + "app_devices": "{\"properties\":{\"devices\":{\"items\":{\"properties\":{\"emulator\":{\"type\":\"boolean\"},\"id\":{\"type\":\"string\"},\"model\":{\"type\":\"string\"},\"navigation\":{\"type\":\"string\"},\"platform\":{\"type\":\"string\"},\"runtime\":{\"type\":\"string\"},\"state\":{\"type\":\"string\"}},\"required\":[\"emulator\",\"id\",\"platform\",\"state\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"notes\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"devices\"],\"type\":\"object\"}", + "app_dialogs": "{\"properties\":{\"device\":{\"type\":\"string\"},\"rules\":{\"items\":{\"properties\":{\"hits\":{\"type\":\"integer\"},\"press\":{\"type\":\"string\"},\"when\":{\"type\":\"string\"}},\"required\":[\"hits\",\"press\",\"when\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"device\",\"rules\"],\"type\":\"object\"}", + "app_doctor": "{\"properties\":{\"checks\":{\"items\":{\"properties\":{\"detail\":{\"type\":\"string\"},\"fix\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"status\":{\"type\":\"string\"}},\"required\":[\"detail\",\"name\",\"status\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"problems\":{\"type\":\"integer\"}},\"required\":[\"checks\",\"problems\"],\"type\":\"object\"}", + "app_drag": "{\"properties\":{\"duration_ms\":{\"type\":\"integer\"},\"from\":{\"type\":\"string\"},\"hold_ms\":{\"type\":\"integer\"},\"to\":{\"type\":\"string\"},\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"duration_ms\",\"hold_ms\",\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"}", + "app_eval": "{\"properties\":{\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"expression\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"context\",\"device\",\"expression\",\"value\"],\"type\":\"object\"}", + "app_grant": "{\"properties\":{\"app\":{\"type\":\"string\"},\"approximate_kept\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"granted\":{\"type\":\"boolean\"},\"permissions\":{\"items\":{\"properties\":{\"applied\":{\"type\":\"boolean\"},\"error\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"skipped\":{\"type\":\"string\"}},\"required\":[\"applied\",\"name\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"reset\":{\"type\":\"boolean\"}},\"required\":[\"device\"],\"type\":\"object\"}", + "app_hit_test": "{\"properties\":{\"device\":{\"type\":\"string\"},\"reaches\":{\"type\":\"boolean\"},\"target\":{\"type\":\"string\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"device\",\"reaches\",\"target\",\"x\",\"y\"],\"type\":\"object\"}", + "app_hook": "{\"properties\":{\"hook\":{\"type\":\"string\"},\"result\":{}},\"required\":[\"hook\",\"result\"],\"type\":\"object\"}", + "app_install": "{\"properties\":{\"device\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"}},\"required\":[\"device\",\"path\"],\"type\":\"object\"}", + "app_keyboard": "{\"properties\":{\"device\":{\"type\":\"string\"},\"focus_moved_to\":{\"type\":\"string\"},\"focused\":{\"properties\":{\"empty\":{\"type\":\"boolean\"},\"id\":{\"type\":\"string\"},\"kind\":{\"type\":\"string\"},\"password\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"}},\"required\":[\"value\"],\"type\":[\"object\",\"null\"]},\"hidden\":{\"type\":\"boolean\"},\"key\":{\"type\":\"string\"},\"shown\":{\"type\":\"boolean\"},\"typed\":{\"type\":\"string\"}},\"required\":[\"device\",\"shown\"],\"type\":\"object\"}", + "app_launch": "{\"properties\":{\"app\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"}},\"required\":[\"app\",\"device\"],\"type\":\"object\"}", + "app_list_apps": "{\"properties\":{\"apps\":{\"items\":{\"properties\":{\"id\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"system\":{\"type\":\"boolean\"},\"version\":{\"type\":\"string\"}},\"required\":[\"id\",\"system\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"device\":{\"type\":\"string\"},\"includes_system\":{\"type\":\"boolean\"}},\"required\":[\"apps\",\"device\",\"includes_system\"],\"type\":\"object\"}", + "app_locale": "{\"properties\":{\"app\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"deviceLocale\":{\"type\":\"string\"},\"locales\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"previous\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"app\",\"device\",\"deviceLocale\",\"locales\"],\"type\":\"object\"}", + "app_location": "{\"properties\":{\"device\":{\"type\":\"string\"},\"known\":{\"type\":\"boolean\"},\"latitude\":{\"type\":\"number\"},\"longitude\":{\"type\":\"number\"},\"mock\":{\"type\":\"boolean\"},\"mocking\":{\"type\":\"boolean\"},\"routing\":{\"type\":\"boolean\"},\"seconds\":{\"type\":\"number\"},\"speed\":{\"type\":\"number\"},\"waypoints\":{\"type\":\"integer\"}},\"required\":[\"device\",\"known\",\"mock\",\"mocking\"],\"type\":\"object\"}", + "app_lock": "{\"properties\":{\"device\":{\"type\":\"string\"},\"locked\":{\"type\":\"boolean\"},\"previous\":{\"type\":[\"boolean\",\"null\"]}},\"required\":[\"device\",\"locked\"],\"type\":\"object\"}", + "app_long_press": "{\"properties\":{\"action\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"cover\":{\"properties\":{\"control\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"}},\"required\":[\"control\",\"label\"],\"type\":[\"object\",\"null\"]},\"position\":{\"type\":[\"number\",\"null\"]},\"target\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"action\",\"x\",\"y\"],\"type\":\"object\"}", + "app_map": "{\"properties\":{\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"diff\":{\"properties\":{\"added\":{\"items\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"changed\":{\"items\":{\"properties\":{\"after\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":\"object\"},\"before\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":\"object\"},\"what\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"after\",\"before\",\"what\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"first\":{\"type\":\"boolean\"},\"removed\":{\"items\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"since\":{}},\"required\":[\"added\",\"changed\",\"removed\"],\"type\":[\"object\",\"null\"]},\"elements\":{\"items\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"notes\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"context\",\"device\",\"elements\"],\"type\":\"object\"}", + "app_network": "{\"properties\":{\"airplane\":{\"type\":\"boolean\"},\"changed\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"download_kbps\":{\"type\":\"integer\"},\"interface\":{\"type\":\"string\"},\"latency_ms\":{\"type\":\"integer\"},\"online\":{\"type\":\"boolean\"},\"proxy\":{\"type\":\"string\"},\"proxy_reversed\":{\"type\":\"boolean\"},\"upload_kbps\":{\"type\":\"integer\"}},\"required\":[\"airplane\",\"changed\",\"device\",\"download_kbps\",\"latency_ms\",\"online\",\"upload_kbps\"],\"type\":\"object\"}", + "app_notifications": "{\"properties\":{\"device\":{\"type\":\"string\"},\"notifications\":{\"items\":{\"properties\":{\"key\":{\"type\":\"string\"},\"package\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"},\"text\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"}},\"required\":[\"key\",\"package\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"device\",\"notifications\"],\"type\":\"object\"}", + "app_open_url": "{\"properties\":{\"app\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"}},\"required\":[\"device\",\"url\"],\"type\":\"object\"}", + "app_orientation": "{\"properties\":{\"device\":{\"type\":\"string\"},\"locked\":{\"type\":\"boolean\"},\"orientation\":{\"type\":\"string\"},\"previous\":{\"type\":\"string\"}},\"required\":[\"device\",\"locked\",\"orientation\"],\"type\":\"object\"}", + "app_press": "{\"properties\":{\"button\":{\"type\":\"string\"},\"confirmed\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"focus\":{\"type\":\"string\"},\"foreground\":{\"type\":\"string\"},\"gesture\":{\"type\":\"boolean\"},\"left\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"}},\"required\":[\"button\",\"confirmed\",\"device\"],\"type\":\"object\"}", + "app_press_drag": "{\"properties\":{\"duration_ms\":{\"type\":\"integer\"},\"from\":{\"type\":\"string\"},\"hold\":{\"type\":\"string\"},\"lead_ms\":{\"type\":\"integer\"},\"to\":{\"type\":\"string\"},\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"x3\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"},\"y3\":{\"type\":\"integer\"}},\"required\":[\"duration_ms\",\"lead_ms\",\"x1\",\"x2\",\"x3\",\"y1\",\"y2\",\"y3\"],\"type\":\"object\"}", + "app_press_tap": "{\"properties\":{\"hold\":{\"type\":\"string\"},\"lead_ms\":{\"type\":\"integer\"},\"tap\":{\"type\":\"string\"},\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"lead_ms\",\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"}", + "app_record": "{\"properties\":{\"bytes\":{\"type\":\"integer\"},\"data\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"duration\":{\"type\":\"integer\"},\"elapsed\":{\"type\":\"integer\"},\"frames\":{\"type\":\"integer\"},\"path\":{\"type\":\"string\"},\"recording\":{\"type\":\"boolean\"}},\"required\":[\"device\",\"recording\"],\"type\":\"object\"}", + "app_reset_permissions": "{\"properties\":{\"app\":{\"type\":\"string\"},\"approximate_kept\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"granted\":{\"type\":\"boolean\"},\"permissions\":{\"items\":{\"properties\":{\"applied\":{\"type\":\"boolean\"},\"error\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"skipped\":{\"type\":\"string\"}},\"required\":[\"applied\",\"name\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"reset\":{\"type\":\"boolean\"}},\"required\":[\"device\"],\"type\":\"object\"}", + "app_revoke": "{\"properties\":{\"app\":{\"type\":\"string\"},\"approximate_kept\":{\"type\":\"boolean\"},\"device\":{\"type\":\"string\"},\"granted\":{\"type\":\"boolean\"},\"permissions\":{\"items\":{\"properties\":{\"applied\":{\"type\":\"boolean\"},\"error\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"skipped\":{\"type\":\"string\"}},\"required\":[\"applied\",\"name\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"reset\":{\"type\":\"boolean\"}},\"required\":[\"device\"],\"type\":\"object\"}", + "app_rotate": "{\"properties\":{\"degrees\":{\"type\":\"number\"},\"radius\":{\"type\":\"integer\"},\"target\":{\"type\":\"string\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"degrees\",\"radius\",\"x\",\"y\"],\"type\":\"object\"}", + "app_screen": "{\"properties\":{\"applied\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"dpi\":{\"type\":\"integer\"},\"findings\":{\"items\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"detail\":{\"type\":\"string\"},\"kind\":{\"type\":\"string\"},\"label\":{\"type\":\"string\"},\"locator\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"detail\",\"kind\",\"label\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"height_dp\":{\"type\":\"integer\"},\"height_px\":{\"type\":\"integer\"},\"overridden\":{\"type\":\"boolean\"},\"physical_dpi\":{\"type\":\"integer\"},\"physical_height_px\":{\"type\":\"integer\"},\"physical_width_px\":{\"type\":\"integer\"},\"profiles\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"smallest_width_dp\":{\"type\":\"integer\"},\"width_dp\":{\"type\":\"integer\"},\"width_px\":{\"type\":\"integer\"}},\"required\":[\"device\",\"height_px\",\"overridden\",\"physical_height_px\",\"physical_width_px\",\"profiles\",\"width_px\"],\"type\":\"object\"}", + "app_scroll_to": "{\"properties\":{\"direction\":{\"type\":\"string\"},\"element\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":[\"object\",\"null\"]},\"scrolls\":{\"type\":\"integer\"},\"target\":{\"type\":\"string\"}},\"required\":[\"direction\",\"scrolls\",\"target\"],\"type\":\"object\"}", + "app_session": "{\"properties\":{\"action\":{\"type\":\"string\"},\"app\":{\"type\":\"string\"},\"closed_tabs\":{\"type\":\"integer\"},\"device\":{\"type\":\"string\"},\"driver\":{\"type\":\"string\"},\"ended\":{\"type\":\"boolean\"},\"exposure\":{\"type\":\"string\"},\"platform\":{\"type\":\"string\"},\"reused\":{\"type\":\"boolean\"},\"sessions\":{\"items\":{\"properties\":{\"device\":{\"type\":\"string\"},\"driver\":{\"type\":\"string\"},\"platform\":{\"type\":\"string\"}},\"required\":[\"device\",\"driver\",\"platform\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"terminated\":{\"type\":\"string\"}},\"required\":[\"action\",\"ended\",\"sessions\"],\"type\":\"object\"}", + "app_set": "{\"properties\":{\"changed\":{\"type\":\"boolean\"},\"checked\":{\"type\":\"boolean\"},\"role\":{\"type\":\"string\"},\"target\":{\"type\":\"string\"},\"wanted\":{\"type\":\"boolean\"}},\"required\":[\"changed\",\"checked\",\"target\",\"wanted\"],\"type\":\"object\"}", + "app_shake": "{\"properties\":{\"device\":{\"type\":\"string\"},\"sent\":{\"type\":\"string\"}},\"required\":[\"device\",\"sent\"],\"type\":\"object\"}", + "app_shutdown": "{\"properties\":{\"device\":{\"type\":\"string\"},\"session_ended\":{\"type\":\"boolean\"}},\"required\":[\"device\",\"session_ended\"],\"type\":\"object\"}", + "app_sms": "{\"properties\":{\"device\":{\"type\":\"string\"},\"from\":{\"type\":\"string\"},\"text\":{\"type\":\"string\"}},\"required\":[\"device\",\"from\",\"text\"],\"type\":\"object\"}", + "app_source": "{\"properties\":{\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"format\":{\"type\":\"string\"},\"redacted\":{\"type\":\"integer\"},\"scale\":{\"type\":\"number\"},\"source\":{\"type\":\"string\"},\"units\":{\"type\":\"string\"}},\"required\":[\"device\",\"format\",\"redacted\",\"source\"],\"type\":\"object\"}", + "app_state": "{\"properties\":{\"app\":{\"type\":\"string\"},\"covered_by\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"state\":{\"type\":\"string\"},\"suspended\":{\"type\":[\"boolean\",\"null\"]}},\"required\":[\"app\",\"device\",\"state\"],\"type\":\"object\"}", + "app_storage": "{\"properties\":{\"action\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"skipped\":{\"items\":{\"type\":\"string\"},\"type\":[\"array\",\"null\"]},\"state\":{\"properties\":{\"cookies\":{\"items\":{\"properties\":{\"domain\":{\"type\":\"string\"},\"expires\":{\"type\":\"number\"},\"httpOnly\":{\"type\":\"boolean\"},\"name\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"},\"sameSite\":{\"type\":\"string\"},\"secure\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"}},\"required\":[\"name\",\"value\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"origins\":{\"items\":{\"properties\":{\"localStorage\":{\"items\":{\"properties\":{\"name\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"name\",\"value\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"origin\":{\"type\":\"string\"},\"sessionStorage\":{\"items\":{\"properties\":{\"name\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"name\",\"value\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"localStorage\",\"origin\",\"sessionStorage\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]}},\"required\":[\"cookies\",\"origins\"],\"type\":\"object\"}},\"required\":[\"action\",\"context\",\"device\",\"state\"],\"type\":\"object\"}", + "app_swipe": "{\"properties\":{\"action\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"cover\":{\"properties\":{\"control\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"}},\"required\":[\"control\",\"label\"],\"type\":[\"object\",\"null\"]},\"position\":{\"type\":[\"number\",\"null\"]},\"target\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"action\",\"x\",\"y\"],\"type\":\"object\"}", + "app_tap": "{\"properties\":{\"action\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"cover\":{\"properties\":{\"control\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"}},\"required\":[\"control\",\"label\"],\"type\":[\"object\",\"null\"]},\"position\":{\"type\":[\"number\",\"null\"]},\"target\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"action\",\"x\",\"y\"],\"type\":\"object\"}", + "app_terminate": "{\"properties\":{\"app\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"}},\"required\":[\"app\",\"device\"],\"type\":\"object\"}", + "app_text": "{\"properties\":{\"text\":{\"type\":\"string\"}},\"required\":[\"text\"],\"type\":\"object\"}", + "app_time": "{\"properties\":{\"clock\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"time\":{\"type\":\"string\"},\"zone\":{\"type\":\"string\"}},\"required\":[\"clock\",\"device\",\"time\"],\"type\":\"object\"}", + "app_timezone": "{\"properties\":{\"device\":{\"type\":\"string\"},\"previous\":{\"type\":\"string\"},\"timezone\":{\"type\":\"string\"}},\"required\":[\"device\",\"timezone\"],\"type\":\"object\"}", + "app_trace": "{\"properties\":{\"bytes\":{\"type\":\"integer\"},\"calls\":{\"type\":\"integer\"},\"data\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"elapsed\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"},\"tracing\":{\"type\":\"boolean\"}},\"required\":[\"calls\",\"device\",\"tracing\"],\"type\":\"object\"}", + "app_uninstall": "{\"properties\":{\"app\":{\"type\":\"string\"},\"context\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"}},\"required\":[\"app\",\"device\"],\"type\":\"object\"}", + "app_upload": "{\"properties\":{\"app\":{\"type\":\"string\"},\"bytes\":{\"type\":\"integer\"},\"checked\":{\"type\":\"string\"},\"data\":{\"type\":\"string\"},\"device\":{\"type\":\"string\"},\"files\":{\"type\":\"integer\"},\"folder\":{\"type\":\"boolean\"},\"name\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"},\"where\":{\"type\":\"string\"}},\"required\":[\"bytes\",\"checked\",\"device\",\"name\",\"where\"],\"type\":\"object\"}", + "app_verdict": "{\"properties\":{\"claim\":{\"type\":\"string\"},\"evidence\":{\"items\":{\"properties\":{\"summary\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"}},\"required\":[\"summary\",\"type\"],\"type\":\"object\"},\"type\":[\"array\",\"null\"]},\"record\":{\"type\":\"string\"},\"status\":{\"type\":\"string\"},\"summary\":{\"type\":\"string\"}},\"required\":[\"claim\",\"evidence\",\"record\",\"status\",\"summary\"],\"type\":\"object\"}", + "app_wait_for": "{\"properties\":{\"condition\":{\"type\":\"string\"},\"element\":{\"properties\":{\"bounds\":{\"properties\":{\"x1\":{\"type\":\"integer\"},\"x2\":{\"type\":\"integer\"},\"y1\":{\"type\":\"integer\"},\"y2\":{\"type\":\"integer\"}},\"required\":[\"x1\",\"x2\",\"y1\",\"y2\"],\"type\":\"object\"},\"checked\":{\"type\":[\"boolean\",\"null\"]},\"context\":{\"type\":\"string\"},\"covered\":{\"type\":\"string\"},\"disabled\":{\"type\":\"boolean\"},\"focused\":{\"type\":\"boolean\"},\"label\":{\"type\":\"string\"},\"locator\":{\"properties\":{\"exact\":{\"type\":\"boolean\"},\"kind\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}},\"required\":[\"kind\",\"value\"],\"type\":[\"object\",\"null\"]},\"ref\":{\"type\":\"string\"},\"role\":{\"type\":\"string\"},\"selected\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"value_scale\":{\"type\":\"string\"}},\"required\":[\"bounds\",\"label\",\"ref\"],\"type\":[\"object\",\"null\"]},\"target\":{\"type\":\"string\"},\"waited_ms\":{\"type\":\"integer\"}},\"required\":[\"condition\",\"target\",\"waited_ms\"],\"type\":\"object\"}", + "app_zoom": "{\"properties\":{\"direction\":{\"type\":\"string\"},\"from\":{\"type\":\"integer\"},\"target\":{\"type\":\"string\"},\"to\":{\"type\":\"integer\"},\"x\":{\"type\":\"integer\"},\"y\":{\"type\":\"integer\"}},\"required\":[\"direction\",\"from\",\"to\",\"x\",\"y\"],\"type\":\"object\"}", +} + +// outputZeros make each schema's type, for the test that holds a value of +// it, as encoding/json writes it, to the schema. +var outputZeros = map[string]func() interface{}{ + "app_accessibility": func() interface{} { return AccessibilityView{} }, + "app_alert": func() interface{} { return AlertView{} }, + "app_appearance": func() interface{} { return AppearanceView{} }, + "app_audio": func() interface{} { return AudioView{} }, + "app_audit": func() interface{} { return AuditView{} }, + "app_background": func() interface{} { return BackgroundView{} }, + "app_battery": func() interface{} { return BatteryView{} }, + "app_biometric": func() interface{} { return BiometricView{} }, + "app_boot": func() interface{} { return device.Booted{} }, + "app_call": func() interface{} { return CallView{} }, + "app_check": func() interface{} { return CheckView{} }, + "app_clear_data": func() interface{} { return ClearDataView{} }, + "app_clipboard": func() interface{} { return ClipboardView{} }, + "app_context": func() interface{} { return ContextView{} }, + "app_contexts": func() interface{} { return ContextsView{} }, + "app_cookies": func() interface{} { return CookiesView{} }, + "app_crashes": func() interface{} { return CrashesView{} }, + "app_current": func() interface{} { return AppView{} }, + "app_devices": func() interface{} { return DevicesView{} }, + "app_dialogs": func() interface{} { return DialogsView{} }, + "app_doctor": func() interface{} { return DoctorView{} }, + "app_drag": func() interface{} { return DragView{} }, + "app_eval": func() interface{} { return EvalView{} }, + "app_grant": func() interface{} { return PermissionView{} }, + "app_hit_test": func() interface{} { return HitTestView{} }, + "app_hook": func() interface{} { return HookView{} }, + "app_install": func() interface{} { return InstallView{} }, + "app_keyboard": func() interface{} { return KeyboardView{} }, + "app_launch": func() interface{} { return AppView{} }, + "app_list_apps": func() interface{} { return AppsView{} }, + "app_locale": func() interface{} { return LocaleView{} }, + "app_location": func() interface{} { return LocationView{} }, + "app_lock": func() interface{} { return LockView{} }, + "app_long_press": func() interface{} { return ActionView{} }, + "app_map": func() interface{} { return MapView{} }, + "app_network": func() interface{} { return NetworkView{} }, + "app_notifications": func() interface{} { return NotificationsView{} }, + "app_open_url": func() interface{} { return OpenURLView{} }, + "app_orientation": func() interface{} { return OrientationView{} }, + "app_press": func() interface{} { return PressView{} }, + "app_press_drag": func() interface{} { return PressDragView{} }, + "app_press_tap": func() interface{} { return PressTapView{} }, + "app_record": func() interface{} { return RecordView{} }, + "app_reset_permissions": func() interface{} { return PermissionView{} }, + "app_revoke": func() interface{} { return PermissionView{} }, + "app_rotate": func() interface{} { return RotateView{} }, + "app_screen": func() interface{} { return ScreenView{} }, + "app_scroll_to": func() interface{} { return ScrollView{} }, + "app_session": func() interface{} { return SessionView{} }, + "app_set": func() interface{} { return SetView{} }, + "app_shake": func() interface{} { return ShakeView{} }, + "app_shutdown": func() interface{} { return ShutdownView{} }, + "app_sms": func() interface{} { return SMSView{} }, + "app_source": func() interface{} { return SourceView{} }, + "app_state": func() interface{} { return AppStateView{} }, + "app_storage": func() interface{} { return StorageView{} }, + "app_swipe": func() interface{} { return ActionView{} }, + "app_tap": func() interface{} { return ActionView{} }, + "app_terminate": func() interface{} { return AppView{} }, + "app_text": func() interface{} { return TextView{} }, + "app_time": func() interface{} { return TimeView{} }, + "app_timezone": func() interface{} { return TimezoneView{} }, + "app_trace": func() interface{} { return TraceView{} }, + "app_uninstall": func() interface{} { return AppView{} }, + "app_upload": func() interface{} { return TransferView{} }, + "app_verdict": func() interface{} { return VerdictView{} }, + "app_wait_for": func() interface{} { return WaitView{} }, + "app_zoom": func() interface{} { return ZoomView{} }, +} diff --git a/internal/agent/outputschema_test.go b/internal/agent/outputschema_test.go new file mode 100644 index 0000000..1cf83d1 --- /dev/null +++ b/internal/agent/outputschema_test.go @@ -0,0 +1,204 @@ +package agent + +import ( + "encoding/json" + "fmt" + "reflect" + "sort" + "testing" + "time" +) + +// Every tool's outputSchema holds the values its type takes, as +// encoding/json writes them: empty, with every slice and pointer nil, and +// filled, with every field set and every slice and map holding one element. +// A client may refuse a result that does not match its tool's schema, so a +// schema that is wrong is worse than none. +func TestEveryOutputSchemaHoldsItsTypesValues(t *testing.T) { + if len(outputZeros) != len(outputSchemas) { + t.Fatalf("%d schemas and %d types: regenerate with make api", len(outputSchemas), len(outputZeros)) + } + names := make([]string, 0, len(outputZeros)) + for n := range outputZeros { + names = append(names, n) + } + sort.Strings(names) + for _, name := range names { + schema := OutputSchema(name) + if schema == nil || schema["type"] != "object" { + t.Errorf("%s: schema %v is no object", name, schema) + continue + } + zero := outputZeros[name]() + for which, v := range map[string]interface{}{"empty": zero, "filled": filled(reflect.TypeOf(zero), 0).Interface()} { + raw, err := json.Marshal(v) + if err != nil { + t.Errorf("%s %s: %v", name, which, err) + continue + } + var doc interface{} + if err := json.Unmarshal(raw, &doc); err != nil { + t.Fatal(err) + } + if err := validate(schema, doc, "$"); err != nil { + t.Errorf("%s, %s: %v\n%s", name, which, err, raw) + } + } + } +} + +// The validator is held to a value it must refuse, so its passes mean +// something: a required field missing, and a string where a number goes. +func TestTheValidatorRefuses(t *testing.T) { + s := map[string]interface{}{"type": "object", "required": []interface{}{"n"}, + "properties": map[string]interface{}{"n": map[string]interface{}{"type": "integer"}}} + if validate(s, map[string]interface{}{}, "$") == nil { + t.Error("a missing required field passed") + } + if validate(s, map[string]interface{}{"n": "1"}, "$") == nil { + t.Error("a string passed as an integer") + } + if validate(s, map[string]interface{}{"n": 1.0}, "$") != nil { + t.Error("an integer was refused") + } +} + +func TestTheToolsListCarriesTheSchemas(t *testing.T) { + with := 0 + for _, tl := range GetToolSchemas() { + if tl.OutputSchema != nil { + with++ + } + } + if with != len(outputSchemas) || with < 60 { + t.Errorf("%d tools list an outputSchema, %d generated", with, len(outputSchemas)) + } +} + +// filled is a value of t with every field set. +func filled(t reflect.Type, depth int) reflect.Value { + v := reflect.New(t).Elem() + if depth > 6 { + return v + } + if t == reflect.TypeOf(time.Time{}) { + return reflect.ValueOf(time.Unix(1, 0).UTC()) + } + switch t.Kind() { + case reflect.String: + v.SetString("x") + case reflect.Bool: + v.SetBool(true) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + v.SetInt(1) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + v.SetUint(1) + case reflect.Float32, reflect.Float64: + v.SetFloat(1.5) + case reflect.Pointer: + v.Set(filled(t.Elem(), depth+1).Addr()) + case reflect.Slice: + s := reflect.MakeSlice(t, 1, 1) + s.Index(0).Set(filled(t.Elem(), depth+1)) + v.Set(s) + case reflect.Map: + m := reflect.MakeMap(t) + if t.Key().Kind() == reflect.String { + m.SetMapIndex(reflect.ValueOf("k").Convert(t.Key()), filled(t.Elem(), depth+1)) + } + v.Set(m) + case reflect.Struct: + for i := 0; i < t.NumField(); i++ { + if f := t.Field(i); f.IsExported() { + v.Field(i).Set(filled(f.Type, depth+1)) + } + } + case reflect.Interface: + if t.NumMethod() == 0 { + v.Set(reflect.ValueOf("x")) + } + } + return v +} + +// validate holds doc to the part of JSON Schema the generator writes. +func validate(schema map[string]interface{}, doc interface{}, at string) error { + if len(schema) == 0 { + return nil + } + types := []string{} + switch t := schema["type"].(type) { + case string: + types = append(types, t) + case []interface{}: + for _, x := range t { + types = append(types, x.(string)) + } + } + ok := len(types) == 0 + for _, ty := range types { + if fits(ty, doc) { + ok = true + } + } + if !ok { + return fmt.Errorf("%s: %T %v is not %v", at, doc, doc, types) + } + switch d := doc.(type) { + case map[string]interface{}: + props, _ := schema["properties"].(map[string]interface{}) + if req, ok := schema["required"].([]interface{}); ok { + for _, r := range req { + if _, has := d[r.(string)]; !has { + return fmt.Errorf("%s: required %q missing", at, r) + } + } + } + for k, v := range d { + if ps, ok := props[k].(map[string]interface{}); ok { + if err := validate(ps, v, at+"."+k); err != nil { + return err + } + } else if ap, ok := schema["additionalProperties"].(map[string]interface{}); ok { + if err := validate(ap, v, at+"."+k); err != nil { + return err + } + } + } + case []interface{}: + if items, ok := schema["items"].(map[string]interface{}); ok { + for i, v := range d { + if err := validate(items, v, fmt.Sprintf("%s[%d]", at, i)); err != nil { + return err + } + } + } + } + return nil +} + +func fits(ty string, doc interface{}) bool { + switch ty { + case "null": + return doc == nil + case "object": + _, ok := doc.(map[string]interface{}) + return ok + case "array": + _, ok := doc.([]interface{}) + return ok + case "string": + _, ok := doc.(string) + return ok + case "boolean": + _, ok := doc.(bool) + return ok + case "number": + _, ok := doc.(float64) + return ok + case "integer": + f, ok := doc.(float64) + return ok && f == float64(int64(f)) + } + return false +} diff --git a/internal/agent/protocol.go b/internal/agent/protocol.go index 557f1e9..834907a 100644 --- a/internal/agent/protocol.go +++ b/internal/agent/protocol.go @@ -94,6 +94,10 @@ type Tool struct { // Annotations are MCP's hints about the tool; readOnlyHint is set on // every tool, from readonly.go. Annotations map[string]interface{} `json:"annotations,omitempty"` + // OutputSchema is the shape of the structuredContent every successful + // call returns, generated from the code (outputschema_gen.go), and + // absent for a tool that does not always return one shape. + OutputSchema map[string]interface{} `json:"outputSchema,omitempty"` } type ToolsCallParams struct { diff --git a/internal/agent/schema.go b/internal/agent/schema.go index 78a4f4c..eaae902 100644 --- a/internal/agent/schema.go +++ b/internal/agent/schema.go @@ -2325,6 +2325,7 @@ func GetToolSchemas() []Tool { } for i := range tools { tools[i].Annotations = Annotations(tools[i].Name) + tools[i].OutputSchema = OutputSchema(tools[i].Name) } return tools } diff --git a/internal/apisurface/outputschema/main.go b/internal/apisurface/outputschema/main.go new file mode 100644 index 0000000..0f5a329 --- /dev/null +++ b/internal/apisurface/outputschema/main.go @@ -0,0 +1,408 @@ +// Command outputschema writes internal/agent/outputschema_gen.go: each tool's +// MCP outputSchema, the shape of the structuredContent a successful call +// returns, worked out from the code by Go's own type checker. +// +// A client may validate every result against a tool's outputSchema and +// refuse one that does not match, so a wrong schema is worse than none. A +// tool gets one only when every way its handler can succeed returns the same +// concrete type: dispatch names the handler; each return is followed through +// Result(text, v), which gives v's static type, and through the handlers' +// own methods it delegates to. Anything else — TextResult, a result built +// elsewhere, two types — leaves the tool without a schema, and the run says +// why for each. The schema follows encoding/json: field names from json tags, +// omitempty fields optional and the rest required, pointers, slices, maps and +// interfaces nullable, and a type with its own MarshalJSON anything. +// +// go run ./internal/apisurface/outputschema . (make api runs it) +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "go/ast" + "go/format" + "go/importer" + "go/parser" + "go/token" + "go/types" + "os" + "path/filepath" + "reflect" + "sort" + "strings" +) + +func main() { + root := "." + if len(os.Args) > 1 { + root = os.Args[1] + } + dir := filepath.Join(root, "internal", "agent") + fset := token.NewFileSet() + pkgs, err := parser.ParseDir(fset, dir, func(fi os.FileInfo) bool { + return !strings.HasSuffix(fi.Name(), "_test.go") && fi.Name() != "outputschema_gen.go" + }, parser.ParseComments) + check(err) + var files []*ast.File + for _, f := range pkgs["agent"].Files { + files = append(files, f) + } + sort.Slice(files, func(i, j int) bool { return fset.File(files[i].Pos()).Name() < fset.File(files[j].Pos()).Name() }) + info := &types.Info{Types: map[ast.Expr]types.TypeAndValue{}, Uses: map[*ast.Ident]types.Object{}, Defs: map[*ast.Ident]types.Object{}} + // The file this writes is left out, so the names it defines are the one + // thing the package may be missing; any other type error is real. + var typeErrs []string + conf := types.Config{Importer: importer.ForCompiler(fset, "source", nil), Error: func(e error) { + if msg := e.Error(); !strings.Contains(msg, "undefined: outputSchemas") && !strings.Contains(msg, "undefined: outputZeros") { + typeErrs = append(typeErrs, msg) + } + }} + _, _ = conf.Check("github.com/mobiumdev/mobium/internal/agent", fset, files, info) + if len(typeErrs) > 0 { + check(fmt.Errorf("internal/agent does not type-check:\n%s", strings.Join(typeErrs, "\n"))) + } + + methods := map[string]*ast.FuncDecl{} + for _, f := range files { + for _, d := range f.Decls { + if fd, ok := d.(*ast.FuncDecl); ok && fd.Recv != nil && fd.Body != nil && recvIsHandlers(fd) { + methods[fd.Name.Name] = fd + } + } + } + tools := dispatchTable(methods["dispatch"]) + + a := &analysis{info: info, methods: methods, memo: map[string]outcome{}} + schemas := map[string]json.RawMessage{} + zeros := map[string]string{} + imports := map[string]bool{} + var report []string + names := make([]string, 0, len(tools)) + for n := range tools { + names = append(names, n) + } + sort.Strings(names) + for _, tool := range names { + o := a.method(tools[tool]) + switch { + case o.why != "": + report = append(report, fmt.Sprintf("%-24s no schema: %s", tool, o.why)) + case len(o.types) != 1: + var ts []string + for _, t := range o.types { + ts = append(ts, t.String()) + } + sort.Strings(ts) + report = append(report, fmt.Sprintf("%-24s no schema: %d result types (%s)", tool, len(ts), strings.Join(ts, ", "))) + default: + s := schemaOf(o.types[0], map[types.Type]bool{}) + if s["type"] != "object" { + report = append(report, fmt.Sprintf("%-24s no schema: its result is not an object", tool)) + continue + } + raw, err := json.Marshal(s) + check(err) + schemas[tool] = raw + if n, ok := types.Unalias(o.types[0]).(*types.Named); ok && n.Obj().Pkg() != nil { + if pkg := n.Obj().Pkg(); pkg.Name() == "agent" { + zeros[tool] = n.Obj().Name() + } else if strings.HasPrefix(pkg.Path(), "github.com/mobiumdev/mobium/") { + zeros[tool] = pkg.Name() + "." + n.Obj().Name() + imports[pkg.Path()] = true + } + } + report = append(report, fmt.Sprintf("%-24s %s", tool, o.types[0])) + } + } + write(filepath.Join(dir, "outputschema_gen.go"), schemas, zeros, imports) + fmt.Println(strings.Join(report, "\n")) + fmt.Printf("%d of %d tools have an output schema\n", len(schemas), len(names)) +} + +func recvIsHandlers(fd *ast.FuncDecl) bool { + if len(fd.Recv.List) != 1 { + return false + } + star, ok := fd.Recv.List[0].Type.(*ast.StarExpr) + if !ok { + return false + } + id, ok := star.X.(*ast.Ident) + return ok && id.Name == "Handlers" +} + +// dispatchTable maps each tool to the method its dispatch case returns. +func dispatchTable(fd *ast.FuncDecl) map[string]string { + out := map[string]string{} + ast.Inspect(fd.Body, func(n ast.Node) bool { + cc, ok := n.(*ast.CaseClause) + if !ok || len(cc.Body) != 1 { + return true + } + ret, ok := cc.Body[0].(*ast.ReturnStmt) + if !ok || len(ret.Results) == 0 { + return true + } + m := handlerCall(ret.Results[0]) + for _, e := range cc.List { + if lit, ok := e.(*ast.BasicLit); ok && m != "" { + out[strings.Trim(lit.Value, `"`)] = m + } + } + return true + }) + return out +} + +// handlerCall is the method name of a call h.M(...), or "". +func handlerCall(e ast.Expr) string { + call, ok := e.(*ast.CallExpr) + if !ok { + return "" + } + sel, ok := call.Fun.(*ast.SelectorExpr) + if !ok { + return "" + } + if id, ok := sel.X.(*ast.Ident); ok && id.Name == "h" { + return sel.Sel.Name + } + return "" +} + +type outcome struct { + types []types.Type + why string +} + +type analysis struct { + info *types.Info + methods map[string]*ast.FuncDecl + memo map[string]outcome +} + +func (a *analysis) method(name string) outcome { + if o, ok := a.memo[name]; ok { + return o + } + a.memo[name] = outcome{why: "it delegates back to itself"} // a cycle stops here + fd := a.methods[name] + if fd == nil { + return outcome{why: "its handler is not a method of Handlers"} + } + var o outcome + add := func(t types.Type) { + for _, have := range o.types { + if types.Identical(have, t) { + return + } + } + o.types = append(o.types, t) + } + ast.Inspect(fd.Body, func(n ast.Node) bool { + if o.why != "" { + return false + } + if _, ok := n.(*ast.FuncLit); ok { + return false // a closure's returns are not the handler's + } + // A return is (result, err) or one call yielding both. + ret, ok := n.(*ast.ReturnStmt) + if !ok || len(ret.Results) == 0 || len(ret.Results) > 2 { + return true + } + first := ret.Results[0] + if id, ok := first.(*ast.Ident); ok && id.Name == "nil" { + return true // the error path: a failed call is isError, not this schema's + } + if call, ok := first.(*ast.CallExpr); ok { + if fn, ok := call.Fun.(*ast.Ident); ok { + switch fn.Name { + case "Result": + if len(call.Args) == 2 { + if id, ok := call.Args[1].(*ast.Ident); ok && id.Name == "nil" { + o.why = "a return gives no structured content" + return false + } + t := a.info.TypeOf(call.Args[1]) + if t == nil { + o.why = "a result's type could not be read" + return false + } + add(t) + return false + } + case "TextResult": + o.why = "a return gives text only" + return false + } + } + if m := handlerCall(call); m != "" { + sub := a.method(m) + if sub.why != "" { + o.why = "it delegates to " + m + ", where " + sub.why + return false + } + for _, t := range sub.types { + add(t) + } + return false + } + } + o.why = "a return's result is built elsewhere (" + exprString(first) + ")" + return false + }) + a.memo[name] = o + return o +} + +func exprString(e ast.Expr) string { + var b bytes.Buffer + _ = format.Node(&b, token.NewFileSet(), e) + s := b.String() + if len(s) > 60 { + s = s[:60] + "…" + } + return s +} + +var marshaler = types.NewInterfaceType([]*types.Func{ + types.NewFunc(token.NoPos, nil, "MarshalJSON", types.NewSignatureType(nil, nil, nil, nil, + types.NewTuple(types.NewVar(token.NoPos, nil, "", types.NewSlice(types.Typ[types.Byte])), + types.NewVar(token.NoPos, nil, "", types.Universe.Lookup("error").Type())), false)), +}, nil).Complete() + +// schemaOf is t's JSON Schema, as encoding/json would write a value of it. +func schemaOf(t types.Type, seen map[types.Type]bool) map[string]interface{} { + if types.Implements(t, marshaler) || types.Implements(types.NewPointer(t), marshaler) { + return map[string]interface{}{} // its own encoding: anything + } + switch u := t.Underlying().(type) { + case *types.Pointer: + return nullable(schemaOf(u.Elem(), seen)) + case *types.Basic: + switch { + case u.Info()&types.IsBoolean != 0: + return map[string]interface{}{"type": "boolean"} + case u.Info()&types.IsInteger != 0: + return map[string]interface{}{"type": "integer"} + case u.Info()&types.IsFloat != 0: + return map[string]interface{}{"type": "number"} + case u.Info()&types.IsString != 0: + return map[string]interface{}{"type": "string"} + } + return map[string]interface{}{} + case *types.Slice: + if b, ok := u.Elem().Underlying().(*types.Basic); ok && b.Kind() == types.Byte { + return nullable(map[string]interface{}{"type": "string"}) // base64 + } + return nullable(map[string]interface{}{"type": "array", "items": schemaOf(u.Elem(), seen)}) + case *types.Array: + return map[string]interface{}{"type": "array", "items": schemaOf(u.Elem(), seen)} + case *types.Map: + return nullable(map[string]interface{}{"type": "object", "additionalProperties": schemaOf(u.Elem(), seen)}) + case *types.Interface: + return map[string]interface{}{} + case *types.Struct: + if seen[t] { + return map[string]interface{}{"type": "object"} + } + seen[t] = true + defer delete(seen, t) + props := map[string]interface{}{} + var required []string + fields(u, seen, props, &required) + s := map[string]interface{}{"type": "object", "properties": props} + if len(required) > 0 { + sort.Strings(required) + s["required"] = required + } + return s + } + return map[string]interface{}{} +} + +// fields adds a struct's JSON fields, embedded structs' among them. +func fields(st *types.Struct, seen map[types.Type]bool, props map[string]interface{}, required *[]string) { + for i := 0; i < st.NumFields(); i++ { + f := st.Field(i) + tag := reflect.StructTag(st.Tag(i)).Get("json") + if tag == "-" { + continue + } + name, opts, _ := strings.Cut(tag, ",") + if f.Embedded() && name == "" { + if inner, ok := f.Type().Underlying().(*types.Struct); ok { + fields(inner, seen, props, required) + continue + } + } + if !f.Exported() { + continue + } + if name == "" { + name = f.Name() + } + props[name] = schemaOf(f.Type(), seen) + if !strings.Contains(opts, "omitempty") { + *required = append(*required, name) + } + } +} + +func nullable(s map[string]interface{}) map[string]interface{} { + if t, ok := s["type"].(string); ok { + s["type"] = []interface{}{t, "null"} + } + return s +} + +func write(path string, schemas map[string]json.RawMessage, zeros map[string]string, imports map[string]bool) { + var b bytes.Buffer + b.WriteString("// Code generated by internal/apisurface/outputschema; DO NOT EDIT.\n\n") + b.WriteString("package agent\n\n") + if len(imports) > 0 { + var paths []string + for ip := range imports { + paths = append(paths, ip) + } + sort.Strings(paths) + b.WriteString("import (\n") + for _, ip := range paths { + fmt.Fprintf(&b, "\t%q\n", ip) + } + b.WriteString(")\n\n") + } + b.WriteString("// outputSchemas are the tools' MCP outputSchema, each the shape of the\n") + b.WriteString("// structuredContent every successful call of the tool returns.\n") + b.WriteString("var outputSchemas = map[string]string{\n") + names := make([]string, 0, len(schemas)) + for n := range schemas { + names = append(names, n) + } + sort.Strings(names) + for _, n := range names { + fmt.Fprintf(&b, "\t%q: %q,\n", n, string(schemas[n])) + } + b.WriteString("}\n\n") + b.WriteString("// outputZeros make each schema's type, for the test that holds a value of\n") + b.WriteString("// it, as encoding/json writes it, to the schema.\n") + b.WriteString("var outputZeros = map[string]func() interface{}{\n") + for _, n := range names { + if z, ok := zeros[n]; ok { + fmt.Fprintf(&b, "\t%q: func() interface{} { return %s{} },\n", n, z) + } + } + b.WriteString("}\n") + out, err := format.Source(b.Bytes()) + check(err) + check(os.WriteFile(path, out, 0o644)) +} + +func check(err error) { + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +}