Skip to content

Commit cfc56e8

Browse files
authored
docs: add agent skill guidance for remote tenant leases (#137)
1 parent 2e0f5da commit cfc56e8

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

skills/agent-device/SKILL.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Use this skill as a router, not a full manual.
2525
- Normal UI task: `open` -> `snapshot -i` -> `press/fill` -> `diff snapshot -i` -> `close`
2626
- Debug/crash: `open <app>` -> `logs clear --restart` -> reproduce -> `network dump` -> `logs path` -> targeted `grep`
2727
- Replay drift: `replay -u <path>` -> verify updated selectors
28+
- Remote multi-tenant run: allocate lease -> run commands with tenant isolation flags -> heartbeat/release lease
2829

2930
## Canonical Flows
3031

@@ -57,6 +58,34 @@ Logging is off by default. Enable only for debugging windows.
5758
agent-device replay -u ./session.ad
5859
```
5960

61+
### 4) Remote Tenant Lease Flow (HTTP JSON-RPC)
62+
63+
```bash
64+
# Allocate lease
65+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
66+
-H "content-type: application/json" \
67+
-H "Authorization: Bearer <token>" \
68+
-d '{"jsonrpc":"2.0","id":"alloc-1","method":"agent_device.lease.allocate","params":{"runId":"run-123","tenantId":"acme","ttlMs":60000}}'
69+
70+
# Use lease in tenant-isolated command execution
71+
agent-device --daemon-transport http \
72+
--tenant acme \
73+
--session-isolation tenant \
74+
--run-id run-123 \
75+
--lease-id <lease-id> \
76+
session list --json
77+
78+
# Heartbeat and release
79+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
80+
-H "content-type: application/json" \
81+
-H "Authorization: Bearer <token>" \
82+
-d '{"jsonrpc":"2.0","id":"hb-1","method":"agent_device.lease.heartbeat","params":{"leaseId":"<lease-id>","ttlMs":60000}}'
83+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
84+
-H "content-type: application/json" \
85+
-H "Authorization: Bearer <token>" \
86+
-d '{"jsonrpc":"2.0","id":"rel-1","method":"agent_device.lease.release","params":{"leaseId":"<lease-id>"}}'
87+
```
88+
6089
## Command Skeleton (Minimal)
6190

6291
### Session and navigation
@@ -139,13 +168,16 @@ agent-device batch --steps-file /tmp/batch-steps.json --json
139168
- `full|limited` mode applies only to iOS `photos`; other targets reject mode.
140169
- On Android, non-ASCII `fill/type` may require an ADB keyboard IME on some system images; only install IME APKs from trusted sources and verify checksum/signature.
141170
- If using `--save-script`, prefer explicit path syntax (`--save-script=flow.ad` or `./flow.ad`).
171+
- For tenant-isolated remote runs, always pass `--tenant`, `--session-isolation tenant`, `--run-id`, and `--lease-id` together.
172+
- Use short lease TTLs and heartbeat only while work is active; release leases immediately after run completion/failure.
142173

143174
## Security and Trust Notes
144175

145176
- Prefer a preinstalled `agent-device` binary over on-demand package execution.
146177
- If install is required, pin an exact version (for example: `npx --yes agent-device@<exact-version> --help`).
147178
- Signing/provisioning environment variables are optional, sensitive, and only for iOS physical-device setup.
148179
- Logs/artifacts are written under `~/.agent-device`; replay scripts write to explicit paths you provide.
180+
- For remote daemon mode, prefer `AGENT_DEVICE_DAEMON_SERVER_MODE=http|dual` with `AGENT_DEVICE_HTTP_AUTH_HOOK` and tenant-scoped lease admission.
149181
- Keep logging off unless debugging and use least-privilege/isolated environments for autonomous runs.
150182

151183
## Common Mistakes
@@ -165,3 +197,4 @@ agent-device batch --steps-file /tmp/batch-steps.json --json
165197
- [references/coordinate-system.md](references/coordinate-system.md)
166198
- [references/batching.md](references/batching.md)
167199
- [references/perf-metrics.md](references/perf-metrics.md)
200+
- [references/remote-tenancy.md](references/remote-tenancy.md)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Remote Tenancy and Lease Admission
2+
3+
Use this reference for remote daemon HTTP flows that require explicit
4+
tenant/run admission control.
5+
6+
## Transport prerequisites
7+
8+
- Start daemon in HTTP mode (`AGENT_DEVICE_DAEMON_SERVER_MODE=http|dual`).
9+
- Use a token from daemon metadata or `Authorization: Bearer <token>`.
10+
- Prefer an auth hook (`AGENT_DEVICE_HTTP_AUTH_HOOK`) for caller validation and
11+
tenant injection.
12+
13+
## Lease lifecycle (JSON-RPC)
14+
15+
Use `POST /rpc` with JSON-RPC 2.0 methods:
16+
17+
- `agent_device.lease.allocate`
18+
- `agent_device.lease.heartbeat`
19+
- `agent_device.lease.release`
20+
21+
Example allocate:
22+
23+
```bash
24+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
25+
-H "content-type: application/json" \
26+
-H "Authorization: Bearer <token>" \
27+
-d '{"jsonrpc":"2.0","id":"alloc-1","method":"agent_device.lease.allocate","params":{"tenantId":"acme","runId":"run-123","ttlMs":60000}}'
28+
```
29+
30+
Example heartbeat:
31+
32+
```bash
33+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
34+
-H "content-type: application/json" \
35+
-H "Authorization: Bearer <token>" \
36+
-d '{"jsonrpc":"2.0","id":"hb-1","method":"agent_device.lease.heartbeat","params":{"leaseId":"<lease-id>","ttlMs":60000}}'
37+
```
38+
39+
Example release:
40+
41+
```bash
42+
curl -sS http://127.0.0.1:${AGENT_DEVICE_DAEMON_HTTP_PORT}/rpc \
43+
-H "content-type: application/json" \
44+
-H "Authorization: Bearer <token>" \
45+
-d '{"jsonrpc":"2.0","id":"rel-1","method":"agent_device.lease.release","params":{"leaseId":"<lease-id>"}}'
46+
```
47+
48+
## Command admission contract
49+
50+
For tenant-isolated command execution, pass all four flags:
51+
52+
```bash
53+
agent-device --daemon-transport http \
54+
--tenant acme \
55+
--session-isolation tenant \
56+
--run-id run-123 \
57+
--lease-id <lease-id> \
58+
session list --json
59+
```
60+
61+
Admission checks require tenant/run/lease scope alignment.
62+
63+
## Failure semantics
64+
65+
- Missing tenant/run/lease fields in tenant isolation mode: `INVALID_ARGS`
66+
- Lease not active or wrong scope: `UNAUTHORIZED`
67+
- Method mismatch: JSON-RPC `-32601` (HTTP 404)
68+
69+
## Operational guidance
70+
71+
- Keep TTL short and heartbeat only while a run is active.
72+
- Release lease immediately on run completion/error paths.
73+
- For bounded hosts, configure:
74+
- `AGENT_DEVICE_MAX_SIMULATOR_LEASES`
75+
- `AGENT_DEVICE_LEASE_TTL_MS`
76+
- `AGENT_DEVICE_LEASE_MIN_TTL_MS`
77+
- `AGENT_DEVICE_LEASE_MAX_TTL_MS`

skills/agent-device/references/session-management.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Sessions isolate device context. A device can only be held by one session at a t
1414
- Name sessions semantically.
1515
- Close sessions when done.
1616
- Use separate sessions for parallel work.
17+
- For remote tenant-scoped automation, run commands with:
18+
`--tenant <id> --session-isolation tenant --run-id <id> --lease-id <id>`
1719
- In iOS sessions, use `open <app>`. `open <url>` opens deep links; on devices `http(s)://` opens Safari when no app is active, and custom schemes require an active app in the session.
1820
- In iOS sessions, `open <app> <url>` opens a deep link.
1921
- On iOS, `appstate` is session-scoped and requires a matching active session on the target device.
@@ -35,3 +37,9 @@ agent-device session list
3537
agent-device replay ./session.ad --session auth
3638
agent-device replay -u ./session.ad --session auth
3739
```
40+
41+
## Tenant isolation note
42+
43+
When session isolation is set to tenant mode, session namespace is scoped as
44+
`<tenant>:<session>`. For remote runs, allocate and maintain an active lease
45+
for the same tenant/run scope before executing tenant-isolated commands.

0 commit comments

Comments
 (0)