@avasapp/agent-bridge 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,8 +26,9 @@ bridge call can set.
26
26
 
27
27
  ## Run the CLI directly
28
28
 
29
- The examples say `npx agent-bridge` for brevity. Prefer the installed bin,
30
- `./node_modules/.bin/agent-bridge` (or `bunx agent-bridge`): `npx` loads npm's
29
+ The examples say `npx @avasapp/agent-bridge`; never drop the scope, because
30
+ `agent-bridge` on npm is an unrelated package. Prefer the installed bin,
31
+ `./node_modules/.bin/agent-bridge` (with bun too): `npx` loads npm's
31
32
  config on every call, so a project `.npmrc` with keys npm doesn't know prints
32
33
  `npm warn Unknown project config` into your output each time, and it adds
33
34
  roughly 200 ms more startup per call (machine-dependent).
@@ -35,10 +36,15 @@ roughly 200 ms more startup per call (machine-dependent).
35
36
  ## Start a session
36
37
 
37
38
  ```sh
38
- npx agent-bridge session start # add --metro host:port if Metro isn't on localhost:8081
39
- npx agent-bridge tools # what this app exposes
39
+ npx @avasapp/agent-bridge session start # add --metro host:port if Metro isn't on localhost:8081
40
+ npx @avasapp/agent-bridge tools # what this app exposes
40
41
  ```
41
42
 
43
+ If Metro runs on another port, pass the same `--metro` (or set
44
+ `AGENT_BRIDGE_METRO`) on every command that doesn't go through the session. A
45
+ `Nothing is listening on …` error names the Metro it found instead and its apps;
46
+ check it's yours before switching to it.
47
+
42
48
  A session holds one connection for all your calls. It stops itself after 15
43
49
  minutes without calls and runs `bridge.restore` when it does.
44
50
 
@@ -58,14 +64,22 @@ not connected; connected: …` means its app is gone and something else is there
58
64
  If `tools` fails with "agent-bridge isn't running", the hook isn't mounted in
59
65
  this build. Say so; don't fall back to tapping silently.
60
66
 
67
+ If the app doesn't have the package or a bridge file yet, run
68
+ `npx @avasapp/agent-bridge init --json` in the app (`--dir apps/x` from a
69
+ monorepo root). It writes `src/dev/agent-bridge.tsx` but never edits the root
70
+ layout: paste `mount.snippet` into `mount.file` as `mount.note` says. Ask the
71
+ user about each entry in `choices` it reports as `open` (such as network
72
+ tools), then rerun with the `flag` it names, or add its `lines` by hand when
73
+ there's no flag. Then follow `next`, from `runFrom`.
74
+
61
75
  ## Start from a scenario
62
76
 
63
77
  Apps can define named setups, such as a locally signed-in user. Use one
64
78
  instead of signing in by hand or seeding auth state yourself:
65
79
 
66
80
  ```sh
67
- npx agent-bridge scenarios # what this app defines
68
- npx agent-bridge call scenario.apply '["signedIn", {"user": {"name": "Ada"}}]'
81
+ npx @avasapp/agent-bridge scenarios # what this app defines
82
+ npx @avasapp/agent-bridge call scenario.apply '["signedIn", {"user": {"name": "Ada"}}]'
69
83
  ```
70
84
 
71
85
  `scenarios` shows each one's options as a JSON Schema. Bad options fail
@@ -85,11 +99,11 @@ real account instead. If you're asked to add one, read
85
99
  ## See and use the screen
86
100
 
87
101
  ```sh
88
- npx agent-bridge call screen.snapshot # buttons, inputs, text on the focused screen
89
- npx agent-bridge call screen.press '"add-plant"' # by testID, label or text
90
- npx agent-bridge call screen.fill '["plant-name", "Fern"]' # runs the input's handlers
91
- npx agent-bridge call screen.waitFor '"Name is required"' # {"gone": true} waits for it to go
92
- npx agent-bridge call router.navigate /inbox
102
+ npx @avasapp/agent-bridge call screen.snapshot # buttons, inputs, text on the focused screen
103
+ npx @avasapp/agent-bridge call screen.press '"add-plant"' # by testID, label or text
104
+ npx @avasapp/agent-bridge call screen.fill '["plant-name", "Fern"]' # runs the input's handlers
105
+ npx @avasapp/agent-bridge call screen.waitFor '"Name is required"' # {"gone": true} waits for it to go
106
+ npx @avasapp/agent-bridge call router.navigate /inbox
93
107
  ```
94
108
 
95
109
  `press` and `fill` return once the app has rendered the result, so the next
@@ -100,14 +114,14 @@ spread into the tool's arguments.
100
114
 
101
115
  Every reply carries errors the app logged or threw since the previous reply,
102
116
  printed as `! error during <tool>` or `! error after <tool>`. Treat them as
103
- failures of the step they name. `npx agent-bridge call bridge.logs` shows the
104
- last 200 errors and warnings.
117
+ failures of the step they name. `npx @avasapp/agent-bridge call bridge.logs`
118
+ shows the last 200 errors and warnings.
105
119
 
106
120
  ## Clean up
107
121
 
108
122
  ```sh
109
- npx agent-bridge call bridge.pending # what restore will put back, per area
110
- npx agent-bridge session stop # runs bridge.restore; --keep leaves the app as is
123
+ npx @avasapp/agent-bridge call bridge.pending # what restore will put back, per area
124
+ npx @avasapp/agent-bridge session stop # runs bridge.restore; --keep leaves the app as is
111
125
  ```
112
126
 
113
127
  `bridge.restore` unpins queries, puts back store values, removes network mocks,
@@ -138,4 +152,7 @@ The app may expose its own tools for hooks the bridge has no tool for
138
152
  overlap. Finish a flow with one real UI check or screenshot from agent-device.
139
153
  - `fill` skips the keyboard: autocorrect and native-only input behaviour need
140
154
  one real typing step from agent-device.
155
+ - Swipe and drag gestures need agent-device, unless the control is screen-reader
156
+ operable: `press` sends its `activate` accessibility action (see
157
+ [references/screen.md](references/screen.md)).
141
158
  - With several apps on one Metro, pass `--device`.
@@ -8,7 +8,7 @@ one JSON line back per call.
8
8
 
9
9
  ```sh
10
10
  printf '%s\n' 'router.navigate /inbox' 'screen.waitFor "Inbox"' 'screen.snapshot' \
11
- | npx agent-bridge call --batch --stop-on-error
11
+ | npx @avasapp/agent-bridge call --batch --stop-on-error
12
12
  # {"tool":"router.navigate","ok":true,"ms":1.8,"appMs":1,"value":...}
13
13
  # {"tool":"screen.waitFor","ok":false,"ms":2003.1,"error":"..."} (plus "logs"/"notice" when present)
14
14
  ```
@@ -29,7 +29,8 @@ reading the output.
29
29
  ## A flow file
30
30
 
31
31
  Write the steps into a flow file and run it when a step depends on an earlier
32
- result, and for timing checks.
32
+ result, and for timing checks. Name it `flows/<name>.flow.mjs` in the app: plain
33
+ `.mjs`, never under `app/`, never `*.test.*`.
33
34
 
34
35
  ```js
35
36
  export const scenario = 'signedIn' // applied first, undone after, even on failure
@@ -43,9 +44,9 @@ export default async ({ step }) => {
43
44
  ```
44
45
 
45
46
  ```sh
46
- npx agent-bridge run flow.mjs --strict # --strict fails if the app logged an error
47
- npx agent-bridge run flow.mjs --scenario signedIn # add a scenario the flow doesn't declare
48
- npx agent-bridge run flow.mjs --scenario 'signedIn={"user":{"name":"Ada"}}' # with options
47
+ npx @avasapp/agent-bridge run flows/check.flow.mjs --strict # --strict fails if the app logged an error
48
+ npx @avasapp/agent-bridge run flows/check.flow.mjs --scenario signedIn # add a scenario the flow doesn't declare
49
+ npx @avasapp/agent-bridge run flows/check.flow.mjs --scenario 'signedIn={"user":{"name":"Ada"}}' # with options
49
50
  ```
50
51
 
51
52
  A flow can declare several scenarios, with options:
@@ -11,9 +11,9 @@ and `connect()` always get the full value.
11
11
  Narrow the call before reaching for `--out`:
12
12
 
13
13
  ```sh
14
- npx agent-bridge call query.get '["feed", {"pages": [0, 2]}]' # first two pages of an infinite query, plus totalPages
15
- npx agent-bridge call query.get '["feed", {"path": "pages.0.items"}]' # just that value
16
- npx agent-bridge call net.mocks '[{"full": true}]' # net.mocks cuts bodies over ~2 KB unless full
14
+ npx @avasapp/agent-bridge call query.get '["feed", {"pages": [0, 2]}]' # first two pages of an infinite query, plus totalPages
15
+ npx @avasapp/agent-bridge call query.get '["feed", {"path": "pages.0.items"}]' # just that value
16
+ npx @avasapp/agent-bridge call net.mocks '[{"full": true}]' # net.mocks cuts bodies over ~2 KB unless full
17
17
  ```
18
18
 
19
19
  `pages` is `[from, to]` with `to` exclusive, like `Array.slice`; `path` applies
@@ -25,9 +25,9 @@ The shell caps one argument at about 128 KB on Linux. For a bigger value (a long
25
25
  feed, a large `net.mock` body), write JSON to a file and pass `@file`:
26
26
 
27
27
  ```sh
28
- npx agent-bridge call query.pin @args.json # the file is the argument list, like the inline form
29
- npx agent-bridge call net.mock '"/feed"' @feed.json # several words: each is one argument; @file is its JSON as-is
30
- some-generator | npx agent-bridge call store.set @- # @- reads stdin
28
+ npx @avasapp/agent-bridge call query.pin @args.json # the file is the argument list, like the inline form
29
+ npx @avasapp/agent-bridge call net.mock '"/feed"' @feed.json # several words: each is one argument; @file is its JSON as-is
30
+ some-generator | npx @avasapp/agent-bridge call store.set @- # @- reads stdin
31
31
  ```
32
32
 
33
33
  A file holding an array is the argument list; any other JSON value is one
@@ -1,11 +1,11 @@
1
1
  # Network mocks and logs
2
2
 
3
3
  ```sh
4
- npx agent-bridge call net.mock '["/inbox", {"status": 500}]' # or {"offline": true}
5
- npx agent-bridge call net.log '[{"since": 1700000000000}]' # entries carry startedAt (epoch ms)
6
- npx agent-bridge call net.entry 3 # one request, bodies whole
7
- npx agent-bridge call net.mockFromLog '[3, {"user": {"name": "Moss"}}]' # a real response, patched
8
- npx agent-bridge call net.mocks '[{"full": true}]' # active mocks; bodies over ~2 KB are cut unless full
4
+ npx @avasapp/agent-bridge call net.mock '["/inbox", {"status": 500}]' # or {"offline": true}
5
+ npx @avasapp/agent-bridge call net.log '[{"since": 1700000000000}]' # entries carry startedAt (epoch ms)
6
+ npx @avasapp/agent-bridge call net.entry 3 # one request, bodies whole
7
+ npx @avasapp/agent-bridge call net.mockFromLog '[3, {"user": {"name": "Moss"}}]' # a real response, patched
8
+ npx @avasapp/agent-bridge call net.mocks '[{"full": true}]' # active mocks; bodies over ~2 KB are cut unless full
9
9
  ```
10
10
 
11
11
  `net.log` cuts bodies at about 2 KB; use `net.entry <id>` (or `{"full": true}`)
@@ -25,8 +25,8 @@ answers fails with a 501, and the reply carries an error that names it
25
25
  (`! error during …: agent-bridge strict network: no mock for GET https://…`).
26
26
  Add a mock for it (`net.mock`), don't turn strict mode off.
27
27
 
28
- `npx agent-bridge call net.strict` lists what it blocked. Strict mode sees JS
29
- `fetch`/XHR only, not images, WebSockets or native SDKs.
28
+ `npx @avasapp/agent-bridge call net.strict` lists what it blocked. Strict mode
29
+ sees JS `fetch`/XHR only, not images, WebSockets or native SDKs.
30
30
 
31
31
  ## Mocks and cached queries
32
32
 
@@ -4,11 +4,11 @@ If the app has `realtime.*` tools, you can see its realtime messages and fake
4
4
  them instead of waiting for a backend to send one:
5
5
 
6
6
  ```sh
7
- npx agent-bridge call realtime.channels # what the app listens on
8
- npx agent-bridge call realtime.log '{"channel": "chat"}' # recent messages, real and faked
9
- npx agent-bridge call realtime.mute '"chat"' # stop real ones overwriting your state
10
- npx agent-bridge call realtime.emit '["chat", {"name": "message", "data": {"text": "hi"}}]'
11
- npx agent-bridge call realtime.connection '"disconnected"' # null goes back to the real state
7
+ npx @avasapp/agent-bridge call realtime.channels # what the app listens on
8
+ npx @avasapp/agent-bridge call realtime.log '{"channel": "chat"}' # recent messages, real and faked
9
+ npx @avasapp/agent-bridge call realtime.mute '"chat"' # stop real ones overwriting your state
10
+ npx @avasapp/agent-bridge call realtime.emit '["chat", {"name": "message", "data": {"text": "hi"}}]'
11
+ npx @avasapp/agent-bridge call realtime.connection '"disconnected"' # null goes back to the real state
12
12
  ```
13
13
 
14
14
  Copy the shape of a real message from `realtime.log` before you emit one. With
@@ -1,10 +1,10 @@
1
1
  # What restore undoes
2
2
 
3
3
  ```sh
4
- npx agent-bridge call bridge.pending # what restore will put back, per area
5
- npx agent-bridge session stop --dry-run # the same, and keeps the session
6
- npx agent-bridge session stop # runs bridge.restore
7
- npx agent-bridge session stop --keep # leaves the app as is; warns about anything still pending
4
+ npx @avasapp/agent-bridge call bridge.pending # what restore will put back, per area
5
+ npx @avasapp/agent-bridge session stop --dry-run # the same, and keeps the session
6
+ npx @avasapp/agent-bridge session stop # runs bridge.restore
7
+ npx @avasapp/agent-bridge session stop --keep # leaves the app as is; warns about anything still pending
8
8
  ```
9
9
 
10
10
  `bridge.restore` unpins queries, puts back store and MMKV values, removes
@@ -1,22 +1,30 @@
1
1
  # See and use the screen
2
2
 
3
3
  ```sh
4
- npx agent-bridge call screen.snapshot # buttons, inputs, text on the focused screen (`hidden` counts what was skipped; {"all":true} lists everything)
5
- npx agent-bridge call screen.findText "Payment" # text or accessibility label; {"labels":false} for text only
6
- npx agent-bridge call screen.press '"add-plant"' # by testID, label or text
7
- npx agent-bridge call screen.press '[{"at":[350,60]}]' # icon-only button: by point; {"index":1} picks among matches; {"force":true} presses disabled
8
- npx agent-bridge call screen.press '["save-plant", {"scroll":true}]' # scrolls an off-screen target into view first
9
- npx agent-bridge call screen.scroll '"Notes"' # bring a target to the middle of its ScrollView/FlatList; {"toEnd":true}, {"by":400}, [{"toEnd":true},{"within":"list"}]
10
- npx agent-bridge call screen.refresh # pull to refresh (the RefreshControl's onRefresh); then screen.waitFor the data
11
- npx agent-bridge call screen.fill '["plant-name", "Fern"]' # runs the input's handlers
12
- npx agent-bridge call screen.waitFor '"Name is required"' # {"gone": true} waits for it to go
13
- npx agent-bridge call screen.waitFor '["Section title", {"scroll":true}]' # also below the fold: scrolls it into view (not with gone)
4
+ npx @avasapp/agent-bridge call screen.snapshot # buttons, inputs, text on the focused screen (`hidden` counts what was skipped; {"all":true} lists everything)
5
+ npx @avasapp/agent-bridge call screen.findText "Payment" # text or accessibility label; {"labels":false} for text only
6
+ npx @avasapp/agent-bridge call screen.press '"add-plant"' # by testID, label or text
7
+ npx @avasapp/agent-bridge call screen.press '[{"at":[350,60]}]' # icon-only button: by point; {"index":1} picks among matches; {"force":true} presses disabled
8
+ npx @avasapp/agent-bridge call screen.press '["save-plant", {"scroll":true}]' # scrolls an off-screen target into view first
9
+ npx @avasapp/agent-bridge call screen.press '"Swipe to confirm"' # no onPress: sends the "activate" accessibility action
10
+ npx @avasapp/agent-bridge call screen.press '["Volume", {"action":"increment"}]' # any action in the element's snapshot `actions`
11
+ npx @avasapp/agent-bridge call screen.scroll '"Notes"' # bring a target to the middle of its ScrollView/FlatList; {"toEnd":true}, {"by":400}, [{"toEnd":true},{"within":"list"}]
12
+ npx @avasapp/agent-bridge call screen.refresh # pull to refresh (the RefreshControl's onRefresh); then screen.waitFor the data
13
+ npx @avasapp/agent-bridge call screen.fill '["plant-name", "Fern"]' # runs the input's handlers
14
+ npx @avasapp/agent-bridge call screen.waitFor '"Name is required"' # {"gone": true} waits for it to go
15
+ npx @avasapp/agent-bridge call screen.waitFor '["Section title", {"scroll":true}]' # also below the fold: scrolls it into view (not with gone)
14
16
  ```
15
17
 
16
18
  `press` and `fill` return once the app has rendered the result, so the next
17
19
  check sees it. `fill` skips the keyboard: autocorrect and native-only input
18
20
  behaviour need one real typing step from agent-device.
19
21
 
22
+ A swipe-to-confirm or slider with no `onPress` shows as a button (or a view)
23
+ with `actions` in the snapshot. `press` calls its `onAccessibilityAction` with
24
+ `activate`, as a screen reader's double tap does, and the reply says
25
+ `via: "accessibilityAction:activate"`. A gesture control with no `actions`
26
+ needs a real swipe from agent-device.
27
+
20
28
  A WebView shows in the snapshot as one element (`webview "checkout"`);
21
29
  `screen.*` can't reach inside it. See [webview.md](webview.md).
22
30
 
@@ -3,11 +3,11 @@
3
3
  ## Set state
4
4
 
5
5
  ```sh
6
- npx agent-bridge call query.pin '[["features"], <data>]' # stays through refetches
7
- npx agent-bridge call store.call '["settings", "setTheme", "dark"]'
8
- npx agent-bridge call router.navigate /inbox
9
- npx agent-bridge call router.current
10
- npx agent-bridge call router.dismiss # closes a route-based modal
6
+ npx @avasapp/agent-bridge call query.pin '[["features"], <data>]' # stays through refetches
7
+ npx @avasapp/agent-bridge call store.call '["settings", "setTheme", "dark"]'
8
+ npx @avasapp/agent-bridge call router.navigate /inbox
9
+ npx @avasapp/agent-bridge call router.current
10
+ npx @avasapp/agent-bridge call router.dismiss # closes a route-based modal
11
11
  ```
12
12
 
13
13
  `router.back` only pops the navigator: an in-app modal or sheet the app renders
@@ -19,12 +19,12 @@ own tool (e.g. `modal.close`) if it has one; check `tools` first.
19
19
  Read the current value first and change only what you need:
20
20
 
21
21
  ```sh
22
- npx agent-bridge call query.get '["todos", 1]' # a flat key or '[["todos", 1]]'
23
- npx agent-bridge call query.list '["todos"]' # key prefix; shows isStale, isInvalidated, fetchStatus
24
- npx agent-bridge call query.refetch '["todos"]' # {matched, refetched, data}; errors when nothing matches
25
- npx agent-bridge call store.get '["app", "auth.isLoggedIn"]' # or ["app","auth","isLoggedIn"]
26
- npx agent-bridge call store.get '["app", {"pick": ["auth.isLoggedIn", "settings.fontScale"]}]'
27
- npx agent-bridge call store.get '["app", {"keys": true}]' # top-level keys and types, no values
22
+ npx @avasapp/agent-bridge call query.get '["todos", 1]' # a flat key or '[["todos", 1]]'
23
+ npx @avasapp/agent-bridge call query.list '["todos"]' # key prefix; shows isStale, isInvalidated, fetchStatus
24
+ npx @avasapp/agent-bridge call query.refetch '["todos"]' # {matched, refetched, data}; errors when nothing matches
25
+ npx @avasapp/agent-bridge call store.get '["app", "auth.isLoggedIn"]' # or ["app","auth","isLoggedIn"]
26
+ npx @avasapp/agent-bridge call store.get '["app", {"pick": ["auth.isLoggedIn", "settings.fontScale"]}]'
27
+ npx @avasapp/agent-bridge call store.get '["app", {"keys": true}]' # top-level keys and types, no values
28
28
  ```
29
29
 
30
30
  `query.get` errors on a key that is not cached (with similar keys), so a
@@ -5,15 +5,15 @@
5
5
  `tools`), use the same verbs on the page:
6
6
 
7
7
  ```sh
8
- npx agent-bridge call webview.list # name, url, loaded, allowed
9
- npx agent-bridge call webview.snapshot '"checkout"' # buttons, links, inputs, text in the page
10
- npx agent-bridge call webview.press '["Pay now", {"webview": "checkout"}]'
11
- npx agent-bridge call webview.fill '["Email", "ada@example.com"]' # {"submit":true} presses Enter
12
- npx agent-bridge call webview.waitFor '["Payment complete", {"timeoutMs": 8000}]' # {"gone":true}
13
- npx agent-bridge call webview.messages '"checkout"' # page <-> app, last 100, bodies cut at 2 KB
14
- npx agent-bridge call webview.message 17 # one in full
15
- npx agent-bridge call webview.send '["checkout", {"type": "auth", "ok": true}]' # as if the app sent it
16
- npx agent-bridge call webview.receive '["checkout", {"type": "done"}]' # runs the app's onMessage
8
+ npx @avasapp/agent-bridge call webview.list # name, url, loaded, allowed
9
+ npx @avasapp/agent-bridge call webview.snapshot '"checkout"' # buttons, links, inputs, text in the page
10
+ npx @avasapp/agent-bridge call webview.press '["Pay now", {"webview": "checkout"}]'
11
+ npx @avasapp/agent-bridge call webview.fill '["Email", "ada@example.com"]' # {"submit":true} presses Enter
12
+ npx @avasapp/agent-bridge call webview.waitFor '["Payment complete", {"timeoutMs": 8000}]' # {"gone":true}
13
+ npx @avasapp/agent-bridge call webview.messages '"checkout"' # page <-> app, last 100, bodies cut at 2 KB
14
+ npx @avasapp/agent-bridge call webview.message 17 # one in full
15
+ npx @avasapp/agent-bridge call webview.send '["checkout", {"type": "auth", "ok": true}]' # as if the app sent it
16
+ npx @avasapp/agent-bridge call webview.receive '["checkout", {"type": "done"}]' # runs the app's onMessage
17
17
  ```
18
18
 
19
19
  Targets match in `screen.*` order: `data-testid` (also `data-test-id`,
@@ -56,8 +56,8 @@ useAgentBridge({ tools, scenarios })
56
56
  is back in its real state. If `apply` throws, the callbacks it had registered
57
57
  run straight away.
58
58
  - Tools: `scenario.list`, `scenario.apply [name, options?]` (applying an active
59
- one again undoes it first) and `scenario.restore`. `npx agent-bridge scenarios`
60
- lists them.
59
+ one again undoes it first) and `scenario.restore`.
60
+ `npx @avasapp/agent-bridge scenarios` lists them.
61
61
  - Flows declare scenarios with `export const scenario` or
62
62
  `export const scenarios`; see [flows.md](flows.md).
63
63
 
@@ -93,5 +93,5 @@ In a release build it's always open. `realtime.connection` isn't enough on its
93
93
  own: it hides the state from the app, but the client still connects.
94
94
 
95
95
  The agent-bridge repo's example app has a complete local `signedIn` in
96
- `example/src/dev/scenarios.ts`, and `example/flows/checks/signed-in.mjs`
96
+ `example/src/dev/scenarios.ts`, and `example/flows/checks/signed-in.flow.mjs`
97
97
  declares it.