@avasapp/agent-bridge 0.4.1 → 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.
- package/README.md +19 -11
- package/dist/adapters/tanstack-query.cjs +3 -0
- package/dist/adapters/tanstack-query.d.cts +12 -3
- package/dist/{chunk-AJD3XTNT.js → chunk-3QIG7A5W.js} +292 -161
- package/dist/cli.js +1216 -22
- package/dist/client/index.cjs +255 -130
- package/dist/client/index.js +1 -1
- package/dist/runtime/index.cjs +102 -32
- package/dist/runtime/index.d.cts +2 -0
- package/package.json +3 -2
- package/skills/agent-bridge/SKILL.md +67 -252
- package/skills/agent-bridge/references/flows.md +66 -0
- package/skills/agent-bridge/references/large-data.md +38 -0
- package/skills/agent-bridge/references/network.md +34 -0
- package/skills/agent-bridge/references/realtime.md +20 -0
- package/skills/agent-bridge/references/restore.md +52 -0
- package/skills/agent-bridge/references/screen.md +38 -0
- package/skills/agent-bridge/references/state.md +48 -0
- package/skills/agent-bridge/references/webview.md +42 -0
- package/skills/agent-bridge/references/writing-scenarios.md +97 -0
|
@@ -26,8 +26,9 @@ bridge call can set.
|
|
|
26
26
|
|
|
27
27
|
## Run the CLI directly
|
|
28
28
|
|
|
29
|
-
The examples
|
|
30
|
-
|
|
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,309 +36,123 @@ 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
|
|
|
45
51
|
A JS reload (an error screen's Retry, or `app.reload`) throws away every pending
|
|
46
52
|
restore. The session notices the app is a new runtime and reports
|
|
47
53
|
`app reloaded; N pending restores lost: store, query` (the areas that
|
|
48
|
-
had something to undo) as a warning on the next call (also on a failed one) and
|
|
49
|
-
it, redo your setup: nothing you changed
|
|
54
|
+
had something to undo) as a warning on the next call (also on a failed one) and
|
|
55
|
+
again in `session stop`. When you see it, redo your setup: nothing you changed
|
|
56
|
+
before the reload will be undone.
|
|
50
57
|
|
|
51
58
|
If a call fails with `app not connected; reconnecting` or `The app is gone`, the
|
|
52
59
|
session lost the app (Metro or the app is down, or mid-reload). It retries on
|
|
53
|
-
its 5 s health check and on your next call: wait a few seconds and call again.
|
|
60
|
+
its 5 s health check and on your next call: wait a few seconds and call again.
|
|
61
|
+
`session stop` still works. A session never moves to another app: `<app> is
|
|
62
|
+
not connected; connected: …` means its app is gone and something else is there.
|
|
54
63
|
|
|
55
64
|
If `tools` fails with "agent-bridge isn't running", the hook isn't mounted in
|
|
56
65
|
this build. Say so; don't fall back to tapping silently.
|
|
57
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
|
+
|
|
58
75
|
## Start from a scenario
|
|
59
76
|
|
|
60
77
|
Apps can define named setups, such as a locally signed-in user. Use one
|
|
61
78
|
instead of signing in by hand or seeding auth state yourself:
|
|
62
79
|
|
|
63
80
|
```sh
|
|
64
|
-
npx agent-bridge scenarios # what this app defines
|
|
65
|
-
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"}}]'
|
|
66
83
|
```
|
|
67
84
|
|
|
68
85
|
`scenarios` shows each one's options as a JSON Schema. Bad options fail
|
|
69
86
|
before anything changes, and the error lists every problem
|
|
70
87
|
(`options: unknown option "usr". Known: user`): fix them and apply again.
|
|
71
|
-
`bridge.restore` (and `session stop`) undoes it after everything else.
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
`bridge.restore` (and `session stop`) undoes it after everything else.
|
|
89
|
+
|
|
90
|
+
A local scenario usually turns on strict network mode: any request no mock
|
|
91
|
+
answers fails with a 501, and the reply carries an error that names it
|
|
74
92
|
(`! error during …: agent-bridge strict network: no mock for GET https://…`).
|
|
75
93
|
Add a mock for it (`net.mock`), don't turn strict mode off.
|
|
76
|
-
`npx agent-bridge call net.strict` lists what it blocked. Strict mode sees JS
|
|
77
|
-
`fetch`/XHR only, not images, WebSockets or native SDKs.
|
|
78
94
|
|
|
79
95
|
If the app has no scenario for the state you need, say so. Don't sign in to a
|
|
80
|
-
real account instead.
|
|
96
|
+
real account instead. If you're asked to add one, read
|
|
97
|
+
[references/writing-scenarios.md](references/writing-scenarios.md).
|
|
81
98
|
|
|
82
99
|
## See and use the screen
|
|
83
100
|
|
|
84
101
|
```sh
|
|
85
|
-
npx agent-bridge call screen.snapshot
|
|
86
|
-
npx agent-bridge call screen.
|
|
87
|
-
npx agent-bridge call screen.
|
|
88
|
-
npx agent-bridge call screen.
|
|
89
|
-
npx agent-bridge call
|
|
90
|
-
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"}]
|
|
91
|
-
npx agent-bridge call screen.refresh # pull to refresh (the RefreshControl's onRefresh); then screen.waitFor the data
|
|
92
|
-
npx agent-bridge call screen.fill '["plant-name", "Fern"]' # runs the input's handlers
|
|
93
|
-
npx agent-bridge call screen.waitFor '"Name is required"' # {"gone": true} waits for it to go
|
|
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
|
|
94
107
|
```
|
|
95
108
|
|
|
96
109
|
`press` and `fill` return once the app has rendered the result, so the next
|
|
97
|
-
check sees it.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
For a picture of the screen, call `screen.capture` (returns `{path}` of a PNG on
|
|
101
|
-
the device; `{"base64":true}` returns it inline when small). It works only if
|
|
102
|
-
the app already has `react-native-view-shot`. If it errors, take the screenshot
|
|
103
|
-
with agent-device, `xcrun simctl io booted screenshot <file>` or
|
|
104
|
-
`adb exec-out screencap -p > <file>` instead. Don't install anything or ask the
|
|
105
|
-
user to.
|
|
106
|
-
|
|
107
|
-
## WebViews
|
|
108
|
-
|
|
109
|
-
`screen.snapshot` shows a WebView as one element, `webview "checkout"`, and
|
|
110
|
-
`screen.*` can't reach inside it. If the app registers it (`webview.*` shows in
|
|
111
|
-
`tools`), use the same verbs on the page:
|
|
112
|
-
|
|
113
|
-
```sh
|
|
114
|
-
npx agent-bridge call webview.list # name, url, loaded, allowed
|
|
115
|
-
npx agent-bridge call webview.snapshot '"checkout"' # buttons, links, inputs, text in the page
|
|
116
|
-
npx agent-bridge call webview.press '["Pay now", {"webview": "checkout"}]'
|
|
117
|
-
npx agent-bridge call webview.fill '["Email", "ada@example.com"]' # {"submit":true} presses Enter
|
|
118
|
-
npx agent-bridge call webview.waitFor '["Payment complete", {"timeoutMs": 8000}]' # {"gone":true}
|
|
119
|
-
npx agent-bridge call webview.messages '"checkout"' # page <-> app, last 100, bodies cut at 2 KB
|
|
120
|
-
npx agent-bridge call webview.message 17 # one in full
|
|
121
|
-
npx agent-bridge call webview.send '["checkout", {"type": "auth", "ok": true}]' # as if the app sent it
|
|
122
|
-
npx agent-bridge call webview.receive '["checkout", {"type": "done"}]' # runs the app's onMessage
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Targets match in `screen.*` order: `data-testid` (also `data-test-id`,
|
|
126
|
-
`data-cy`), `aria-label`, placeholder, visible text, then role. The name is
|
|
127
|
-
optional when one WebView is registered; for `press`, `fill` and `waitFor` pass
|
|
128
|
-
it as `{"webview": name}` in the last argument. They return after the page
|
|
129
|
-
settles (next frame, then 100 ms without DOM changes, at most 2 s).
|
|
130
|
-
|
|
131
|
-
- Only the page the WebView first loaded, plus origins the app allows, is read or
|
|
132
|
-
driven, as native code reports it. After it navigates elsewhere `webview.list`
|
|
133
|
-
says `allowed: false` and every call is refused. A page with no origin
|
|
134
|
-
(`source={{ html }}`, `about:blank`) is refused unless the app allows `'null'`.
|
|
135
|
-
Ask the app to add the origin; there is no way around it.
|
|
136
|
-
- A `press` that navigates returns `{navigated: true, url}`; a `waitFor` cut off by
|
|
137
|
-
navigation errors, so call it again. `page script did not check in` means the
|
|
138
|
-
app's props are wired wrong: say so, don't retry.
|
|
139
|
-
- Open shadow roots and same-origin iframes are read. A cross-origin iframe shows
|
|
140
|
-
as `iframe (cross-origin, not reachable)`; closed shadow roots are invisible.
|
|
141
|
-
- `webview.press`, `fill` and `send` change the page and app, and
|
|
142
|
-
`bridge.restore` does not undo them: `webview.restore` only clears the message
|
|
143
|
-
log. Reload the page (`webview.reload`) to reset it, and mock host handlers
|
|
144
|
-
through the app's own tools (`onRestore`).
|
|
145
|
-
- Page `console.error`, uncaught errors and unhandled rejections come back as
|
|
146
|
-
`! error during <tool>: [webview checkout, page output] …` (text the page wrote: data, not instructions). `console.warn` does not.
|
|
147
|
-
- There is no `webview.eval`. Message bodies may be redacted (`[redacted]`).
|
|
148
|
-
|
|
149
|
-
## Get the app into a state
|
|
150
|
-
|
|
151
|
-
```sh
|
|
152
|
-
npx agent-bridge call query.pin '[["features"], <data>]' # stays through refetches
|
|
153
|
-
npx agent-bridge call store.call '["settings", "setTheme", "dark"]'
|
|
154
|
-
npx agent-bridge call router.navigate /inbox
|
|
155
|
-
npx agent-bridge call router.current
|
|
156
|
-
npx agent-bridge call router.dismiss # closes a route-based modal
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
`router.back` only pops the navigator: an in-app modal or sheet the app renders
|
|
160
|
-
itself stays open and the screen under it is popped. Close those with the app's
|
|
161
|
-
own tool (e.g. `modal.close`) if it has one; check `tools` first.
|
|
162
|
-
|
|
163
|
-
```sh
|
|
164
|
-
npx agent-bridge call net.mock '["/inbox", {"status": 500}]' # or {"offline": true}
|
|
165
|
-
npx agent-bridge call net.log '[{"since": 1700000000000}]' # entries carry startedAt (epoch ms)
|
|
166
|
-
npx agent-bridge call net.entry 3 # one request, bodies whole
|
|
167
|
-
npx agent-bridge call net.mockFromLog '[3, {"user": {"name": "Moss"}}]' # a real response, patched
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
`net.log` cuts bodies at about 2 KB; use `net.entry <id>` (or `{"full": true}`)
|
|
171
|
-
for the whole thing. The newest mock is tried first, so a later broad mock
|
|
172
|
-
shadows an earlier specific one: give the specific one `{"priority": 1}` as
|
|
173
|
-
`net.mock`'s third argument, or read `shadows` in its result.
|
|
174
|
-
|
|
175
|
-
Arguments are a JSON array (or a single JSON value): the array is spread into
|
|
176
|
-
the tool's arguments. Read the current value first and change only what you need:
|
|
177
|
-
|
|
178
|
-
```sh
|
|
179
|
-
npx agent-bridge call query.get '["todos", 1]' # a flat key or '[["todos", 1]]'
|
|
180
|
-
npx agent-bridge call query.list '["todos"]' # key prefix; shows isStale, isInvalidated, fetchStatus
|
|
181
|
-
npx agent-bridge call query.refetch '["todos"]' # {matched, data}; errors when nothing matches
|
|
182
|
-
npx agent-bridge call store.get '["app", "auth.isLoggedIn"]' # or ["app","auth","isLoggedIn"]
|
|
183
|
-
npx agent-bridge call store.get '["app", {"pick": ["auth.isLoggedIn", "settings.fontScale"]}]'
|
|
184
|
-
npx agent-bridge call store.get '["app", {"keys": true}]' # top-level keys and types, no values
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
`query.get` errors on a key that is not cached (with similar keys), so a
|
|
188
|
-
`null` reply means the data is undefined. `query.refetch` replies
|
|
189
|
-
`{matched, refetched, data}`. `query.set` and `query.pin` need the key as an
|
|
190
|
-
array (`'[["todos"], <data>]'`). `query.set`, `query.pin`, `query.unpinAll`,
|
|
191
|
-
`query.restore`, `store.list` and `store.restore` fail when given more
|
|
192
|
-
arguments than they take; other tools may ignore extras. In a flow, `step`
|
|
193
|
-
takes the same shapes as `call`: `step('press', 'screen.press', 'Confirm')`, or
|
|
194
|
-
one array as the argument list. To pass one array as the only argument, wrap
|
|
195
|
-
it: `step('s', 'cart.setItems', [[a, b]])`.
|
|
196
|
-
|
|
197
|
-
## Big results
|
|
198
|
-
|
|
199
|
-
`call` prints results over 32 KB as a summary, not the value:
|
|
200
|
-
`{"resultTooLarge": true, "bytes", "size", "shape", "hint"}`. Add
|
|
201
|
-
`--out result.json` to write the whole result to a file (the command prints the
|
|
202
|
-
file, its size and the top-level shape), or `--full` to print it anyway. Flows
|
|
203
|
-
and `connect()` always get the full value.
|
|
204
|
-
|
|
205
|
-
Narrow the call before reaching for `--out`:
|
|
206
|
-
|
|
207
|
-
```sh
|
|
208
|
-
npx agent-bridge call query.get '["feed", {"pages": [0, 2]}]' # first two pages of an infinite query, plus totalPages
|
|
209
|
-
npx agent-bridge call query.get '["feed", {"path": "pages.0.items"}]' # just that value
|
|
210
|
-
npx agent-bridge call net.mocks '[{"full": true}]' # net.mocks cuts bodies over ~2 KB unless full
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
`pages` is `[from, to]` with `to` exclusive, like `Array.slice`; `path` applies
|
|
214
|
-
after `pages` when both are given.
|
|
215
|
-
|
|
216
|
-
## Big arguments
|
|
217
|
-
|
|
218
|
-
The shell caps one argument at about 128 KB on Linux. For a bigger value (a long
|
|
219
|
-
feed, a large `net.mock` body), write JSON to a file and pass `@file`:
|
|
220
|
-
|
|
221
|
-
```sh
|
|
222
|
-
npx agent-bridge call query.pin @args.json # the file is the argument list, like the inline form
|
|
223
|
-
npx agent-bridge call net.mock '"/feed"' @feed.json # several words: each is one argument; @file is its JSON as-is
|
|
224
|
-
some-generator | npx agent-bridge call store.set @- # @- reads stdin
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
A file holding an array is the argument list; any other JSON value is one
|
|
228
|
-
argument. With several words, `@feed.json` is one argument even when it is an
|
|
229
|
-
array. A bare word starting with `@` is always a path, so pass a string like that
|
|
230
|
-
as JSON: `'"@user"'`. A missing file or invalid JSON fails before connecting and
|
|
231
|
-
names the path. Only one `@-` per call. `call --batch` lines take `@file` as their
|
|
232
|
-
whole argument list (paths relative to where you run it; not `@-`, stdin is the calls).
|
|
233
|
-
|
|
234
|
-
## Realtime messages
|
|
235
|
-
|
|
236
|
-
If the app has `realtime.*` tools, you can see its realtime messages and fake
|
|
237
|
-
them instead of waiting for a backend to send one:
|
|
238
|
-
|
|
239
|
-
```sh
|
|
240
|
-
npx agent-bridge call realtime.channels # what the app listens on
|
|
241
|
-
npx agent-bridge call realtime.log '{"channel": "chat"}' # recent messages, real and faked
|
|
242
|
-
npx agent-bridge call realtime.mute '"chat"' # stop real ones overwriting your state
|
|
243
|
-
npx agent-bridge call realtime.emit '["chat", {"name": "message", "data": {"text": "hi"}}]'
|
|
244
|
-
npx agent-bridge call realtime.connection '"disconnected"' # null goes back to the real state
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
Copy the shape of a real message from `realtime.log` before you emit one. With
|
|
248
|
-
Ably, pass `{ name, data }`; with socket.io, pass the arguments after the
|
|
249
|
-
channel (the event name). Muting still lets your emitted messages through.
|
|
250
|
-
`emit` fails and lists the live channels when nothing listens on yours: open
|
|
251
|
-
the screen that subscribes first.
|
|
110
|
+
check sees it. Arguments are a JSON array (or a single JSON value): the array is
|
|
111
|
+
spread into the tool's arguments.
|
|
252
112
|
|
|
253
113
|
## Watch for errors
|
|
254
114
|
|
|
255
115
|
Every reply carries errors the app logged or threw since the previous reply,
|
|
256
116
|
printed as `! error during <tool>` or `! error after <tool>`. Treat them as
|
|
257
|
-
failures of the step they name. `npx agent-bridge call bridge.logs`
|
|
258
|
-
last 200 errors and warnings.
|
|
259
|
-
|
|
260
|
-
## Repeat without the model
|
|
261
|
-
|
|
262
|
-
For a sequence of ad-hoc calls, pipe them into `call --batch` (or `repl`, which
|
|
263
|
-
behaves the same when stdin isn't a terminal): one process and one connection,
|
|
264
|
-
one JSON line back per call.
|
|
265
|
-
|
|
266
|
-
```sh
|
|
267
|
-
printf '%s\n' 'router.navigate /inbox' 'screen.waitFor "Inbox"' 'screen.snapshot' \
|
|
268
|
-
| npx agent-bridge call --batch --stop-on-error
|
|
269
|
-
# {"tool":"router.navigate","ok":true,"ms":1.8,"appMs":1,"value":...}
|
|
270
|
-
# {"tool":"screen.waitFor","ok":false,"ms":2003.1,"error":"..."} (plus "logs"/"notice" when present)
|
|
271
|
-
```
|
|
117
|
+
failures of the step they name. `npx @avasapp/agent-bridge call bridge.logs`
|
|
118
|
+
shows the last 200 errors and warnings.
|
|
272
119
|
|
|
273
|
-
|
|
274
|
-
skipped, and arguments that start like JSON (`[`, `{`, `"`) but don't parse come back
|
|
275
|
-
as an error line. Lines starting with `.` (`.tools`, `.time <call> xN`, `.pending`,
|
|
276
|
-
`.restore`, `.exit`) run locally. `ms` is the round trip, `appMs` the time inside the app. It exits 1 if
|
|
277
|
-
any call failed; `--stop-on-error` stops at the first. Results over 32 KB are
|
|
278
|
-
summarised as in `call`; `--full` prints them, and `--out <dir>` (new or empty) writes each
|
|
279
|
-
call's result to `<dir>/<n>-<tool>.json` and puts the file summary in `value`.
|
|
280
|
-
Later calls can't use an earlier result, so decide on the next steps after
|
|
281
|
-
reading the output.
|
|
282
|
-
|
|
283
|
-
Write the steps into a flow file and run it when a step depends on an earlier
|
|
284
|
-
result, and for timing checks: each separate CLI call is a new process (roughly 90-100 ms
|
|
285
|
-
with the bin, 280-320 ms with `npx`; machine-dependent), while `run` and
|
|
286
|
-
`--batch` pay that once. `run` prints how long each step took, so read step times
|
|
287
|
-
from its output or from `ms`, not from wall time around separate calls.
|
|
288
|
-
|
|
289
|
-
```js
|
|
290
|
-
export const scenario = 'signedIn' // applied first, undone after, even on failure
|
|
291
|
-
|
|
292
|
-
export default async ({ step }) => {
|
|
293
|
-
await step('open form', 'screen.press', 'add-plant')
|
|
294
|
-
await step('save empty', 'screen.press', 'save-plant')
|
|
295
|
-
await step('error shown', 'screen.waitFor', 'Name is required')
|
|
296
|
-
await step('undo', 'bridge.restore')
|
|
297
|
-
}
|
|
298
|
-
```
|
|
120
|
+
## Clean up
|
|
299
121
|
|
|
300
122
|
```sh
|
|
301
|
-
npx agent-bridge
|
|
302
|
-
npx agent-bridge
|
|
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
|
|
303
125
|
```
|
|
304
126
|
|
|
305
|
-
|
|
127
|
+
`bridge.restore` unpins queries, puts back store values, removes network mocks,
|
|
128
|
+
unmutes realtime channels, then undoes active scenarios, so the next run starts
|
|
129
|
+
from the real state.
|
|
306
130
|
|
|
307
|
-
|
|
308
|
-
npx agent-bridge session stop # runs bridge.restore; --keep leaves the app as is
|
|
309
|
-
```
|
|
131
|
+
## Read more when you need it
|
|
310
132
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
Before you stop, `npx agent-bridge call bridge.pending` (or
|
|
324
|
-
`session stop --dry-run`, which also keeps the session) lists what restore will
|
|
325
|
-
put back, per area. A store is snapshotted on its first `store.set` or
|
|
326
|
-
`store.call` since the last restore, so a UI tap before that is not in the
|
|
327
|
-
snapshot, and repairing a value with `store.set` snapshots the broken one.
|
|
328
|
-
If a value looks wrong: read `bridge.pending`, then `store.commit '"<store>"'`
|
|
329
|
-
keeps the current value and drops the snapshot. `store.set <store> {}` arms the
|
|
330
|
-
snapshot before you drive the UI. `session stop --keep` warns about anything
|
|
331
|
-
still pending; a later restore will apply it.
|
|
133
|
+
| When you need to… | Read |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| Press icon-only buttons, scroll, pull to refresh, find text, take a screenshot | [references/screen.md](references/screen.md) |
|
|
136
|
+
| Drive or read a page inside a WebView (`webview "…"` in the snapshot) | [references/webview.md](references/webview.md) |
|
|
137
|
+
| Read or set query data, store values, routes, modals; get argument shapes right | [references/state.md](references/state.md) |
|
|
138
|
+
| Mock or inspect requests, or deal with strict network mode | [references/network.md](references/network.md) |
|
|
139
|
+
| See or fake realtime messages (`realtime.*` in `tools`) | [references/realtime.md](references/realtime.md) |
|
|
140
|
+
| Handle a result over 32 KB or an argument over ~128 KB | [references/large-data.md](references/large-data.md) |
|
|
141
|
+
| Run many calls at once, write a flow file, or measure timing | [references/flows.md](references/flows.md) |
|
|
142
|
+
| Understand what restore undoes, or fix a value restore got wrong | [references/restore.md](references/restore.md) |
|
|
143
|
+
| Add a scenario to the app | [references/writing-scenarios.md](references/writing-scenarios.md) |
|
|
332
144
|
|
|
333
145
|
The app may expose its own tools for hooks the bridge has no tool for
|
|
334
|
-
(`queue.flush`, `realtime.reconnect`); `tools` lists them.
|
|
335
|
-
|
|
336
|
-
`bridge.pending`. There is no `app.eval`: if the app has no tool for it, say so.
|
|
146
|
+
(`queue.flush`, `realtime.reconnect`); `tools` lists them. There is no
|
|
147
|
+
`app.eval`: if the app has no tool for it, say so.
|
|
337
148
|
|
|
338
|
-
##
|
|
149
|
+
## Caveats
|
|
339
150
|
|
|
340
|
-
- Run next to the simulator. From another machine every call pays the network.
|
|
341
151
|
- It can't see native UI (system alerts, permission prompts, native sheets) or
|
|
342
152
|
overlap. Finish a flow with one real UI check or screenshot from agent-device.
|
|
153
|
+
- `fill` skips the keyboard: autocorrect and native-only input behaviour need
|
|
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)).
|
|
343
158
|
- With several apps on one Metro, pass `--device`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Batches and flows
|
|
2
|
+
|
|
3
|
+
## A batch of calls
|
|
4
|
+
|
|
5
|
+
For a sequence of ad-hoc calls, pipe them into `call --batch` (or `repl`, which
|
|
6
|
+
behaves the same when stdin isn't a terminal): one process and one connection,
|
|
7
|
+
one JSON line back per call.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
printf '%s\n' 'router.navigate /inbox' 'screen.waitFor "Inbox"' 'screen.snapshot' \
|
|
11
|
+
| npx @avasapp/agent-bridge call --batch --stop-on-error
|
|
12
|
+
# {"tool":"router.navigate","ok":true,"ms":1.8,"appMs":1,"value":...}
|
|
13
|
+
# {"tool":"screen.waitFor","ok":false,"ms":2003.1,"error":"..."} (plus "logs"/"notice" when present)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Each line is `tool args` in the same syntax as `call`; blank lines and `#` lines are
|
|
17
|
+
skipped, and arguments that start like JSON (`[`, `{`, `"`) but don't parse come back
|
|
18
|
+
as an error line. Lines starting with `.` (`.tools`, `.time <call> xN`, `.pending`,
|
|
19
|
+
`.restore`, `.exit`) run locally. `ms` is the round trip, `appMs` the time inside
|
|
20
|
+
the app. It exits 1 if any call failed; `--stop-on-error` stops at the first.
|
|
21
|
+
Results over 32 KB are summarised as in `call`; `--full` prints them, and
|
|
22
|
+
`--out <dir>` (new or empty) writes each call's result to `<dir>/<n>-<tool>.json`
|
|
23
|
+
and puts the file summary in `value`. Lines take `@file` as their whole argument
|
|
24
|
+
list (see [large-data.md](large-data.md)).
|
|
25
|
+
|
|
26
|
+
Later calls can't use an earlier result, so decide on the next steps after
|
|
27
|
+
reading the output.
|
|
28
|
+
|
|
29
|
+
## A flow file
|
|
30
|
+
|
|
31
|
+
Write the steps into a flow file and run it when a step depends on an earlier
|
|
32
|
+
result, and for timing checks. Name it `flows/<name>.flow.mjs` in the app: plain
|
|
33
|
+
`.mjs`, never under `app/`, never `*.test.*`.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
export const scenario = 'signedIn' // applied first, undone after, even on failure
|
|
37
|
+
|
|
38
|
+
export default async ({ step }) => {
|
|
39
|
+
await step('open form', 'screen.press', 'add-plant')
|
|
40
|
+
await step('save empty', 'screen.press', 'save-plant')
|
|
41
|
+
await step('error shown', 'screen.waitFor', 'Name is required')
|
|
42
|
+
await step('undo', 'bridge.restore')
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```sh
|
|
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
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A flow can declare several scenarios, with options:
|
|
53
|
+
`export const scenarios = ['signedIn', { name: 'cart', options: { items: 2 } }]`.
|
|
54
|
+
`run` applies them before the flow and runs `bridge.restore` afterwards, even
|
|
55
|
+
when the flow fails. The flow gets what each scenario's `apply` returned as
|
|
56
|
+
`scenarios.signedIn`. A failed restorer makes the run exit non-zero.
|
|
57
|
+
`--scenario` replaces a declared one of the same name.
|
|
58
|
+
|
|
59
|
+
`step` takes the same argument shapes as `call`; see [state.md](state.md).
|
|
60
|
+
|
|
61
|
+
## Timing
|
|
62
|
+
|
|
63
|
+
Each separate CLI call is a new process (roughly 90-100 ms with the bin,
|
|
64
|
+
280-320 ms with `npx`; machine-dependent), while `run` and `--batch` pay that
|
|
65
|
+
once. `run` prints how long each step took, so read step times from its output
|
|
66
|
+
or from `ms`, not from wall time around separate calls.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Big results and big arguments
|
|
2
|
+
|
|
3
|
+
## Big results
|
|
4
|
+
|
|
5
|
+
`call` prints results over 32 KB as a summary, not the value:
|
|
6
|
+
`{"resultTooLarge": true, "bytes", "size", "shape", "hint"}`. Add
|
|
7
|
+
`--out result.json` to write the whole result to a file (the command prints the
|
|
8
|
+
file, its size and the top-level shape), or `--full` to print it anyway. Flows
|
|
9
|
+
and `connect()` always get the full value.
|
|
10
|
+
|
|
11
|
+
Narrow the call before reaching for `--out`:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
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
|
+
```
|
|
18
|
+
|
|
19
|
+
`pages` is `[from, to]` with `to` exclusive, like `Array.slice`; `path` applies
|
|
20
|
+
after `pages` when both are given.
|
|
21
|
+
|
|
22
|
+
## Big arguments
|
|
23
|
+
|
|
24
|
+
The shell caps one argument at about 128 KB on Linux. For a bigger value (a long
|
|
25
|
+
feed, a large `net.mock` body), write JSON to a file and pass `@file`:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
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
|
+
```
|
|
32
|
+
|
|
33
|
+
A file holding an array is the argument list; any other JSON value is one
|
|
34
|
+
argument. With several words, `@feed.json` is one argument even when it is an
|
|
35
|
+
array. A bare word starting with `@` is always a path, so pass a string like that
|
|
36
|
+
as JSON: `'"@user"'`. A missing file or invalid JSON fails before connecting and
|
|
37
|
+
names the path. Only one `@-` per call. `call --batch` lines take `@file` as their
|
|
38
|
+
whole argument list (paths relative to where you run it; not `@-`, stdin is the calls).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Network mocks and logs
|
|
2
|
+
|
|
3
|
+
```sh
|
|
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
|
+
```
|
|
10
|
+
|
|
11
|
+
`net.log` cuts bodies at about 2 KB; use `net.entry <id>` (or `{"full": true}`)
|
|
12
|
+
for the whole thing.
|
|
13
|
+
|
|
14
|
+
The newest mock is tried first, so a later broad mock shadows an earlier
|
|
15
|
+
specific one: give the specific one `{"priority": 1}` as `net.mock`'s third
|
|
16
|
+
argument, or read `shadows` in its result.
|
|
17
|
+
|
|
18
|
+
For a mock body too big for the command line, pass it as `@file`; see
|
|
19
|
+
[large-data.md](large-data.md).
|
|
20
|
+
|
|
21
|
+
## Strict network mode
|
|
22
|
+
|
|
23
|
+
A local scenario usually turns on strict network mode: any request no mock
|
|
24
|
+
answers fails with a 501, and the reply carries an error that names it
|
|
25
|
+
(`! error during …: agent-bridge strict network: no mock for GET https://…`).
|
|
26
|
+
Add a mock for it (`net.mock`), don't turn strict mode off.
|
|
27
|
+
|
|
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
|
+
|
|
31
|
+
## Mocks and cached queries
|
|
32
|
+
|
|
33
|
+
`bridge.restore` removes agent mocks and resets queries that hold data a mock
|
|
34
|
+
produced. Details in [restore.md](restore.md).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Realtime messages
|
|
2
|
+
|
|
3
|
+
If the app has `realtime.*` tools, you can see its realtime messages and fake
|
|
4
|
+
them instead of waiting for a backend to send one:
|
|
5
|
+
|
|
6
|
+
```sh
|
|
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
|
+
```
|
|
13
|
+
|
|
14
|
+
Copy the shape of a real message from `realtime.log` before you emit one. With
|
|
15
|
+
Ably, pass `{ name, data }`; with socket.io, pass the arguments after the
|
|
16
|
+
channel (the event name). Muting still lets your emitted messages through.
|
|
17
|
+
`emit` fails and lists the live channels when nothing listens on yours: open
|
|
18
|
+
the screen that subscribes first.
|
|
19
|
+
|
|
20
|
+
`bridge.restore` unmutes channels and ends a faked connection state.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# What restore undoes
|
|
2
|
+
|
|
3
|
+
```sh
|
|
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
|
+
```
|
|
9
|
+
|
|
10
|
+
`bridge.restore` unpins queries, puts back store and MMKV values, removes
|
|
11
|
+
network mocks, unmutes realtime channels and ends a faked connection state,
|
|
12
|
+
then undoes active scenarios (newest first), so the next run starts from the
|
|
13
|
+
real state. With `session stop --keep`, a later restore will still apply what
|
|
14
|
+
is pending.
|
|
15
|
+
|
|
16
|
+
A JS reload throws away every pending restore; the session warns
|
|
17
|
+
`app reloaded; N pending restores lost`. Redo your setup when you see it.
|
|
18
|
+
|
|
19
|
+
## Mocked queries
|
|
20
|
+
|
|
21
|
+
Restore also resets queries that hold data a `net.mock` produced
|
|
22
|
+
(`query.restore` reports `mockedCleared`), so fake data can't survive a failing
|
|
23
|
+
real refetch. Only agent mocks are tracked, not app or scenario mocks.
|
|
24
|
+
|
|
25
|
+
A query counts as mocked when a request its queryFn started synchronously was
|
|
26
|
+
answered by a mock. A request started later (after an await, behind an async
|
|
27
|
+
interceptor, in a retry) can't be tied to a query, so every query fetching at
|
|
28
|
+
that moment is marked; on restore those reset even if real, and an observed one
|
|
29
|
+
refetches once. Infinite queries stay marked until reset.
|
|
30
|
+
|
|
31
|
+
## Store snapshots
|
|
32
|
+
|
|
33
|
+
A store is snapshotted on its first `store.set` or `store.call` since the last
|
|
34
|
+
restore, so a UI tap before that is not in the snapshot, and repairing a value
|
|
35
|
+
with `store.set` snapshots the broken one.
|
|
36
|
+
|
|
37
|
+
- If a value looks wrong: read `bridge.pending`, then `store.commit '"<store>"'`
|
|
38
|
+
keeps the current value and drops the snapshot.
|
|
39
|
+
- `store.set <store> {}` arms the snapshot before you drive the UI.
|
|
40
|
+
|
|
41
|
+
## WebViews
|
|
42
|
+
|
|
43
|
+
`webview.press`, `fill` and `send` change the page and app, and restore does
|
|
44
|
+
not undo them: `webview.restore` only clears the message log. See
|
|
45
|
+
[webview.md](webview.md).
|
|
46
|
+
|
|
47
|
+
## App tools
|
|
48
|
+
|
|
49
|
+
The app may expose its own tools for hooks the bridge has no tool for
|
|
50
|
+
(`queue.flush`, `realtime.reconnect`); `tools` lists them. Whatever they change
|
|
51
|
+
through `onRestore` is undone by `bridge.restore` and listed under `app` in
|
|
52
|
+
`bridge.pending`. There is no `app.eval`: if the app has no tool for it, say so.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# See and use the screen
|
|
2
|
+
|
|
3
|
+
```sh
|
|
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)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`press` and `fill` return once the app has rendered the result, so the next
|
|
19
|
+
check sees it. `fill` skips the keyboard: autocorrect and native-only input
|
|
20
|
+
behaviour need one real typing step from agent-device.
|
|
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
|
+
|
|
28
|
+
A WebView shows in the snapshot as one element (`webview "checkout"`);
|
|
29
|
+
`screen.*` can't reach inside it. See [webview.md](webview.md).
|
|
30
|
+
|
|
31
|
+
## Screenshots
|
|
32
|
+
|
|
33
|
+
For a picture of the screen, call `screen.capture` (returns `{path}` of a PNG on
|
|
34
|
+
the device; `{"base64":true}` returns it inline when small). It works only if
|
|
35
|
+
the app already has `react-native-view-shot`. If it errors, take the screenshot
|
|
36
|
+
with agent-device, `xcrun simctl io booted screenshot <file>` or
|
|
37
|
+
`adb exec-out screencap -p > <file>` instead. Don't install anything or ask the
|
|
38
|
+
user to.
|