Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
d1f74bc
test: a holder's rotate of its iOS-simulator lease answers and sends …
leonardoxr Oct 31, 2026
6a87186
test: a holder opens the tunnel socket, sends HELLO with reverse tunn…
leonardoxr Oct 31, 2026
98cfb13
feat(tunnel): a reverse tunnel answers READY and carries device conne…
leonardoxr Oct 31, 2026
a42ade3
feat(daemon): device.rotate turns a leased simulator through its devi…
leonardoxr Oct 31, 2026
21516b5
test: a holder's HELLO that cannot be met is refused whole with REFUS…
leonardoxr Oct 31, 2026
e308d56
feat(tunnel): a HELLO that cannot be met is refused whole with its co…
leonardoxr Oct 31, 2026
fe1c197
test: a caller rotates a lease it may not touch, or names a bad orien…
leonardoxr Oct 31, 2026
2f1ebec
feat(contract): device.rotate is authorized like device.exec (#1107)
leonardoxr Oct 31, 2026
e54e3f2
test: a holder rotates a lease not on an iOS phone or tablet simulato…
leonardoxr Oct 31, 2026
18acbd7
feat(daemon): device.rotate refuses a lease not on an iOS phone or ta…
leonardoxr Oct 31, 2026
642a392
test: a holder rotates when the helper cannot start or the write fail…
leonardoxr Oct 31, 2026
770e4f0
feat(daemon): device.rotate answers INPUT_UNAVAILABLE with the reason…
leonardoxr Oct 31, 2026
50dac1b
test: an input socket opened after a rotate's helper closed gets a fr…
leonardoxr Oct 31, 2026
2084eab
test: bytes flow both ways under a 262144-byte window per direction, …
leonardoxr Oct 31, 2026
c4f93c0
feat(tunnel): data flows both ways under a per-connection window and …
leonardoxr Oct 31, 2026
42899a1
test: a bad frame is refused BAD_REQUEST and closed 4003, a frame for…
leonardoxr Oct 31, 2026
22b171d
feat(daemon): one device input per lease, shared by the input module'…
leonardoxr Oct 31, 2026
0751cc1
feat(tunnel): a bad frame is refused BAD_REQUEST with close 4003 (#1112)
leonardoxr Oct 31, 2026
7afdb40
test: the worker removes a tunnel's rules and closes its connections …
leonardoxr Oct 31, 2026
736d3ba
test: a client program calls client.rotate(leaseId, orientation) and …
leonardoxr Oct 31, 2026
746b8d0
feat(tunnel): closing the socket, the lease's end and a drain remove …
leonardoxr Oct 31, 2026
e778c34
feat(client): client.rotate turns a lease's simulator through device.…
leonardoxr Oct 31, 2026
a4d9f18
test: an agent calls POST /v1/leases/{id}/rotate on a worker and thro…
leonardoxr Oct 31, 2026
e330b80
test: a caller reaches the tunnel route on a lone worker only when it…
leonardoxr Oct 31, 2026
45ad185
feat(tunnel): a holder or operator reaches the tunnel route on a lone…
leonardoxr Oct 31, 2026
0dc922c
feat(http): POST /v1/leases/{id}/rotate on a worker and through a gat…
leonardoxr Oct 31, 2026
6f2f973
docs: rotate over HTTP and its two error codes (#1107)
leonardoxr Oct 31, 2026
d8d222b
test: the alias parser maps a spelling to an orientation or the unkno…
leonardoxr Oct 31, 2026
4bae4e7
feat(contract): parseOrientation maps an alias to an orientation or t…
leonardoxr Oct 31, 2026
c6834bc
test: the gateway coordinator forwards device.rotate and names the ca…
leonardoxr Oct 31, 2026
38af91d
feat(android): the driver's reverse sets adb reverse --no-rebind to a…
leonardoxr Oct 31, 2026
cd00d68
feat(tunnel): an iOS lease is refused TUNNEL_UNSUPPORTED and a driver…
leonardoxr Oct 31, 2026
c267dac
test: a user runs simlock rotate <orientation> and sees Rotated lease…
leonardoxr Oct 31, 2026
adb10f2
feat(cli): simlock rotate turns the holder's only lease (#1108)
leonardoxr Oct 31, 2026
0759879
test: two tunnels, END half-closes from each side, and a device conne…
leonardoxr Oct 31, 2026
661ddab
feat(tunnel): END half-closes a connection from each side and a devic…
leonardoxr Oct 31, 2026
8972aca
test: --lease names the lease to rotate before or after the orientati…
leonardoxr Oct 31, 2026
fa9b7cf
feat(cli): simlock rotate --lease names the lease (#1108)
leonardoxr Oct 31, 2026
617b3dd
fix(ports): a peer's half-close ends a TCP stream's readable (#1112)
leonardoxr Oct 31, 2026
17858cd
test: simlock rotate takes aliases, refuses unknown names and ambiguo…
leonardoxr Oct 31, 2026
9f1396f
test: an MCP client calls rotate_device {orientation} and the held le…
leonardoxr Oct 31, 2026
29c7aec
docs(tunnel): the tunnel socket on a lone worker, its capability, por…
leonardoxr Oct 31, 2026
bc1a869
feat(mcp): rotate_device turns the session's held lease (#1108)
leonardoxr Oct 31, 2026
a8dda2f
test: rotate_device answers NO_LEASE, BAD_REQUEST and the daemon's re…
leonardoxr Oct 31, 2026
77edefa
test: simlock instructions lists simlock rotate and rotate_device (#1…
leonardoxr Oct 31, 2026
eae80be
test: a socket whose write fails closes 1013 while the daemon keeps r…
leonardoxr Oct 31, 2026
6d6c5ea
feat(instructions): simlock instructions lists simlock rotate and rot…
leonardoxr Oct 31, 2026
e5bb97b
test: simlock rotate --help and the root usage name the command (#1108)
leonardoxr Oct 31, 2026
aced7b4
test: fold the coordinator's rotate case into the HTTP gateway test t…
leonardoxr Oct 31, 2026
0844848
chore: name how the coordinator's rotate is reached for Fallow (#1107)
leonardoxr Oct 31, 2026
600ec74
test: a holder opens the tunnel socket through a gateway and it is re…
leonardoxr Oct 31, 2026
5a8d932
test: a socket closing while hello awaits reverse leaves no rule set …
leonardoxr Oct 31, 2026
bb30a14
fix(tunnel): a rule that arrives after the socket closed is removed (…
leonardoxr Oct 31, 2026
01f44f7
feat(tunnel): a gateway relays the tunnel socket to the lease's worke…
leonardoxr Oct 31, 2026
d679267
test: a worker with tunnels off answers 503 TUNNEL_UNAVAILABLE throug…
leonardoxr Oct 31, 2026
c28989a
feat(tunnel): a worker with tunnels off answers 503 TUNNEL_UNAVAILABL…
leonardoxr Oct 31, 2026
364bb73
test: a full-size DATA is relayed and a worker's REFUSED closes the h…
leonardoxr Oct 31, 2026
8c98b94
feat(cli): simlock rotate --help, the root usage, the CLI reference a…
leonardoxr Oct 31, 2026
892278a
feat(tunnel): the worker's close frame closes the holder's socket wit…
leonardoxr Oct 31, 2026
68d70ac
test: a caller frame over 65541 bytes is refused BAD_REQUEST and clos…
leonardoxr Oct 31, 2026
12d19c7
feat(android): reclaim and daemon start remove stale tunnel rules, on…
leonardoxr Oct 31, 2026
1db9bab
feat(tunnel): a caller frame over 65541 bytes is refused BAD_REQUEST …
leonardoxr Oct 31, 2026
bc08674
docs(android): the cleanup of stale tunnel rules at reclaim and start…
leonardoxr Oct 31, 2026
a859b67
test: through a gateway the lease's end closes 4001, a stopping worke…
leonardoxr Oct 31, 2026
19d0ca4
chore(tunnel): Fallow findings of the tunnel cycles (#1112)
leonardoxr Oct 31, 2026
18735fc
Merge remote-tracking branch 'origin/task/1107' into task/1108
leonardoxr Oct 31, 2026
3f09619
feat(tunnel): a stopping worker closes the holder 1011 and a draining…
leonardoxr Oct 31, 2026
f09c789
test: the gateway's tunnel bridge bounds every wait on the worker (#1…
leonardoxr Oct 31, 2026
4c09bca
feat(tunnel): the gateway bounds its open to 10 s and a lease's remov…
leonardoxr Oct 31, 2026
719e405
feat(tunnel): the worker's relay door sends a heartbeat every 5 s and…
leonardoxr Oct 31, 2026
277d2fa
test: the tunnel route's 503 TUNNEL_UNAVAILABLE and WORKER_UNREACHABL…
leonardoxr Oct 31, 2026
f3a35d5
feat(tunnel): the route's 503 statuses, the remote-agents page and th…
leonardoxr Oct 31, 2026
f18c495
chore(tunnel): merge task/1108 into task/1114 (#1114)
leonardoxr Oct 31, 2026
766482d
chore(tunnel): merge origin/task/1112 into task/1113 (#1113)
leonardoxr Oct 31, 2026
6442e27
test: the CLI against a lone worker with fake devices opens a reverse…
leonardoxr Oct 31, 2026
34eb975
feat(cli): simlock tunnel reverse opens a tunnel on a lone worker and…
leonardoxr Oct 31, 2026
1672cab
fix(tunnel): a channel frame is at most one message, the heartbeat st…
leonardoxr Oct 31, 2026
53e0ec8
test: the CLI against a lone worker with fake devices refuses with th…
leonardoxr Oct 31, 2026
945fa70
feat(cli): a tunnel the worker refuses exits with the worker's code (…
leonardoxr Oct 31, 2026
dc91fe1
test: a user's simlock tunnel that cannot run exits with its code and…
leonardoxr Oct 31, 2026
12a5613
feat(cli): simlock tunnel checks its arguments, url and token before …
leonardoxr Oct 31, 2026
2a2f2f8
test: simlock tunnel prints one line per tunnel and words its lease e…
leonardoxr Oct 31, 2026
0fb0d01
feat(cli): simlock tunnel words its lease errors for the token and an…
leonardoxr Oct 31, 2026
5ee8b88
test: nothing listening warns once per 10 s per tunnel and a 1 MiB re…
leonardoxr Oct 31, 2026
1049697
test(tunnel): the audit's missing cases, the reclaim fixtures and the…
leonardoxr Oct 31, 2026
c315e7d
feat(cli): simlock tunnel warns when nothing listens and honours the …
leonardoxr Oct 31, 2026
5e55c81
test: simlock tunnel that is refused or loses its worker exits with t…
leonardoxr Oct 31, 2026
287bfd0
feat(cli): simlock tunnel exits with the worker's code, times out sil…
leonardoxr Oct 31, 2026
7a59360
test: lazy-loading shows ws loaded by simlock tunnel alone (#1114)
leonardoxr Oct 31, 2026
5029153
test: the http-json and websocket-client adapters against a real serv…
leonardoxr Oct 31, 2026
92e4024
docs(cli): the tunnel command, its lease resolver and the lazy ws ada…
leonardoxr Oct 31, 2026
e999928
test: a page on the caller's loopback port loads on a real emulator t…
leonardoxr Oct 31, 2026
e08812e
chore(tunnel): Fallow findings of the cli and ports cycles (#1114)
leonardoxr Oct 31, 2026
49a5f23
Merge remote-tracking branch 'origin/task/1112' into task/1114
leonardoxr Oct 31, 2026
7603ff6
fix: the website's MCP summaries say six tools; rotate_device's alias…
leonardoxr Oct 31, 2026
7aa86a7
fix(gateway): name the caller's lease id in every worker error, and p…
leonardoxr Oct 31, 2026
6382188
docs: list POST /v1/leases/{id}/rotate and device.rotate in the manua…
leonardoxr Oct 31, 2026
de2bc7b
Merge remote-tracking branch 'origin/task/1107' into task/1108
leonardoxr Oct 31, 2026
33b7b53
test: pin rotate's agent role, client close and the rotate_device inp…
leonardoxr Oct 31, 2026
22169a8
fix(android): hold tunnel ports until reclaim, keep a leased device's…
leonardoxr Oct 31, 2026
c19bc15
chore(tunnel): Fallow findings of the review fixes (#1112)
leonardoxr Oct 31, 2026
dedafb1
test: drop a leftover debug assertion from the MCP smoke table (#1108)
leonardoxr Oct 31, 2026
4893d50
chore(tunnel): merge origin/task/1112 and share one relay-channel imp…
leonardoxr Oct 31, 2026
53012f8
fix(modules): drop the pipe type from the index now that only the rel…
leonardoxr Oct 31, 2026
eb7baaf
test(tunnel): the audit's missing cases, safe frame JSON and the http…
leonardoxr Oct 31, 2026
2d0c579
Merge remote-tracking branch 'origin/task/1112' into task/1114
leonardoxr Oct 31, 2026
facfe9c
Merge remote-tracking branch 'origin/task/1113' into task/1114
leonardoxr Oct 31, 2026
cefda33
Merge remote-tracking branch 'origin/task/1108' into task/1114
leonardoxr Oct 31, 2026
11d80a8
fix(tunnel): close every connection and the socket on each exit, rese…
leonardoxr Oct 31, 2026
aeb76cf
refactor(tunnel): split checkedUrl and the carrying-connections test …
leonardoxr Oct 31, 2026
ef0194e
Merge origin/main into task/1112
V3RON Nov 1, 2026
01e7d87
Merge task/1112 (with origin/main) into task/1113
V3RON Nov 1, 2026
a66d101
Merge task/1113 (with origin/main) into task/1114
V3RON Nov 1, 2026
35d8bbf
chore(tunnel): merge origin/main into task/1114 (#1114)
V3RON Nov 1, 2026
137b7dd
fix(tunnel): terminate the socket after the 2 s Ctrl-C bound; name th…
V3RON Nov 1, 2026
50c1f69
test(tunnel): the 45 s silence and 90 s no-READY ends terminate the s…
V3RON Nov 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ worker daemon ── uplink (WebSocket to /v1/uplink, worker dials) ──┘
| bus | Post-commit business events and their in-memory ring | [bus](../../src/bus/AGENTS.md) |
| state | `state.db`: opens it, refuses an old file, damage and a newer version, migrates each owner's tables | [state](../../src/state/AGENTS.md) |
| history | The durable event history: `history.db`, prune, set-aside, projections (usage: request, minute and device fact rows) | [history](../../src/history/AGENTS.md) |
| ports | Every external API behind an interface, with a fake | [ports](../../src/ports/AGENTS.md) |
| ports | Every external API behind an interface, with a fake; `ws` loads lazily, in the CLI only for `simlock tunnel` | [ports](../../src/ports/AGENTS.md) |
| host-load | CPU, memory and disk load samples | [host-load](../../src/host-load/AGENTS.md) |
| instructions | The static rules text for agents: `simlock instructions`, the MCP server instructions and resource; `simlock setup`, which installs the router skill | [instructions](../../src/instructions/AGENTS.md) |
| agent-identity | Default requester id for CLI and MCP | [agent-identity](../../src/agent-identity/AGENTS.md) |
Expand Down
108 changes: 108 additions & 0 deletions e2e/slow-android-tunnel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { existsSync } from "node:fs";
import { createServer } from "node:http";
import { homedir } from "node:os";
import { join } from "node:path";
import { describe, expect, it } from "vitest";

import { DEVICE_READY_MS, freeLoopbackPort, waitFor, withHttpDaemon } from "./helpers/index.js";

const ANDROID_HOME =
process.env.ANDROID_HOME ??
process.env.ANDROID_SDK_ROOT ??
join(homedir(), "Library/Android/sdk");
const hasAndroidSdk =
existsSync(ANDROID_HOME) && existsSync(join(ANDROID_HOME, "platform-tools", "adb"));

const BODY = "simlock-tunnel-ok";

// why: only a real emulator proves that `adb reverse` reaches the caller's loopback listener through the tunnel socket; the fast end-to-end test fakes the device side.
describe.skipIf(!hasAndroidSdk)(
"simlock tunnel reverse on a real emulator against a lone worker",
{ tags: ["slow", "android"] },
() => {
it(
"serves a page held on the caller's loopback port to the emulator through reverse",
{ timeout: 420_000 },
async () => {
const { env, port } = await withHttpDaemon((httpPort) => ({
configOverrides: {
capabilities: { tunnel: { enabled: true } },
http: { enabled: true, host: "127.0.0.1", port: httpPort },
idle: { shutdownAfterMs: 300_000 },
warmPool: { learn: false },
},
driver: "real",
}));
const page = createServer((_request, response) => {
response.writeHead(200, { "content-type": "text/plain" }).end(BODY);
});
try {
const callerPort = await freeLoopbackPort();
await new Promise<void>((resolve) => page.listen(callerPort, "127.0.0.1", resolve));

const lease = await env.cli(
[
"lease",
"--platform",
"android",
"--device",
"Pixel 9",
"--agent-id",
"tunnel",
"--detach",
],
{ timeout: DEVICE_READY_MS },
);
expect(lease.code, `lease failed: ${lease.stderr}`).toBe(0);
const leaseId = (lease.json as { lease: { id: string } }).lease.id;

const created = await env.cli(["token", "create", "--role", "operator"]);
expect(created.code, created.stderr).toBe(0);
const secret = (created.json as { secret: string }).secret;

const tunnel = env.cliBackground([
"--token",
secret,
"tunnel",
"reverse",
String(callerPort),
"--url",
`http://127.0.0.1:${String(port)}`,
"--lease",
leaseId,
]);
expect(await tunnel.firstStdoutLine(60_000)).toBe(
`reverse device:${String(callerPort)} -> localhost:${String(callerPort)} (lease ${leaseId})`,
);

let answer = "";
await waitFor(
async () => {
const fetched = await env.cli([
"adb",
"shell",
`(printf 'GET / HTTP/1.0\\r\\n\\r\\n'; sleep 2) | nc 127.0.0.1 ${String(callerPort)}`,
]);
answer = fetched.stdout;
return answer.includes(BODY);
},
{
interval: 1_000,
label: "the device reading the caller's page through reverse",
timeout: 60_000,
},
);
expect(answer).toContain(BODY);

tunnel.kill("SIGINT");
expect((await tunnel.waitForExit(10_000)).code).toBe(0);
} finally {
await new Promise<void>((resolve) => page.close(() => resolve()));
await env
.cli(["nuke", "--delete-devices", "--yes"], { timeout: 120_000 })
.catch(() => undefined);
}
},
);
},
);
48 changes: 28 additions & 20 deletions src/cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ Surface: [cli.mdx](../../website/src/content/docs/docs/reference/cli.mdx) — ev

## Files

| File | Role |
| ----------------- | ------------------------------------------------------------------------------------------------- |
| `index.ts` | `runCli`: the global `--token`, `--gateway` and `--local`, the command lookup, the error boundary |
| `tree.ts` | The command tree — each node names the module that implements it |
| `environment.ts` | `buildCliEnvironment`: the ports a command may reach, from the ports it is handed |
| `types.ts` | `CliEnvironment` and its ports — types only, so routing loads no code |
| `errors.ts` | The error → code/exit mapping |
| `usage-error.ts` | `UsageError` and `withHelpHint`, the help pointer's one wording |
| `connect.ts` | `connectDaemonClient`: credential order, the admin session, the notice |
| `args.ts` | `commandArgs` / `requiredPositional` / `subcommandOrUsage` / `writeResult` |
| `commands/*.ts` | One module per command, `run(argv, context)`; loaded by the tree on a hit |
| `format.ts` | The human renderers for `status`, `worker list`, `daemon start`, etc. |
| `duration.ts` | `parseDuration` for `--ttl`-style flags |
| `termination.ts` | The signals and parent-exit wait a held lease blocks on |
| `log-file.ts` | `readLogFile`: `daemon.log` plus a rotated generation |
| `stdio.ts` | `readPipedStdin`: stdin for `simctl`/`adb --stdin`, read to EOF, a terminal included |
| `remote-lease.ts` | `resolveRemoteLeaseId`: the requester's only lease, shared by `simctl`/`adb` and `rotate` |
| `passthrough.ts` | `spawnPassthrough`: runs a resolved simctl/adb command, stdio inherited |
| `follow-log.ts` | `followLog`: `daemon logs --follow` across rotations |
| `main.ts` | The bin; sets `process.exitCode` |
| File | Role |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `index.ts` | `runCli`: the global `--token`, `--gateway` and `--local`, the command lookup, the error boundary |
| `tree.ts` | The command tree — each node names the module that implements it |
| `environment.ts` | `buildCliEnvironment`: the ports a command may reach, from the ports it is handed |
| `types.ts` | `CliEnvironment` and its ports — types only, so routing loads no code |
| `errors.ts` | The error → code/exit mapping |
| `usage-error.ts` | `UsageError` and `withHelpHint`, the help pointer's one wording |
| `connect.ts` | `connectDaemonClient`: credential order, the admin session, the notice |
| `args.ts` | `commandArgs` / `requiredPositional` / `subcommandOrUsage` / `writeResult` |
| `commands/*.ts` | One module per command, `run(argv, context)`; loaded by the tree on a hit |
| `format.ts` | The human renderers for `status`, `worker list`, `daemon start`, etc. |
| `duration.ts` | `parseDuration` for `--ttl`-style flags |
| `termination.ts` | The signals and parent-exit wait a held lease blocks on |
| `log-file.ts` | `readLogFile`: `daemon.log` plus a rotated generation |
| `stdio.ts` | `readPipedStdin`: stdin for `simctl`/`adb --stdin`, read to EOF, a terminal included |
| `remote-lease.ts` | `resolveRemoteLeaseId`: the requester's only lease, shared by `simctl`/`adb` and `rotate`; `selectOnlyLease` words a token's errors for `tunnel` |
| `passthrough.ts` | `spawnPassthrough`: runs a resolved simctl/adb command, stdio inherited |
| `follow-log.ts` | `followLog`: `daemon logs --follow` across rotations |
| `main.ts` | The bin; sets `process.exitCode` |

`format.ts`, `duration.ts` and `termination.ts` are reached only from a command module, and
`follow-log.ts` and `passthrough.ts` only from a dynamic import inside `environment.ts`.
Expand Down Expand Up @@ -96,6 +96,14 @@ Surface: [cli.mdx](../../website/src/content/docs/docs/reference/cli.mdx) — ev
orientation, an unknown one is a usage error (exit 2); the lease is `--lease` (anywhere on the line)
or the requester's only lease (`resolveRemoteLeaseId`); `device.rotate` answers, and the line printed
is `Rotated lease <id> to <orientation>` from the answer. Worker or gateway alike.
5b. **`simlock tunnel reverse <d>[:<c>] … [--lease <id>] [--url <u>]`** — talks to a worker or gateway over
HTTP and a WebSocket, never the local daemon: `--url`/`SIMLOCK_URL` (`https://`, or `http://` on loopback only; the origin, no path, query or fragment)
and `--token`/`SIMLOCK_TOKEN`. Without `--lease`, `GET /v1/identity` and `/v1/leases` pick an agent token's only
lease (`selectOnlyLease`; an operator token must name one). One line per tunnel on `READY`; each `OPEN` connects
to the caller's loopback port (no listener: `RESET` and a stderr warning per tunnel every 10 s), and `CREDIT`
flows both ways. Failures print one JSON line itself: a refused upgrade or `REFUSED` frame with the worker's code,
close 4001 exit 14 `TUNNEL_LEASE_ENDED`, a lost socket, 45 s of silence or 90 s without `READY` `TUNNEL_DISCONNECTED`.
Ctrl-C and SIGTERM close the socket, wait at most 2 s, exit 0. `ws` loads on the first connect, for this command only.
6. **`simlock events --follow`** — subscribe, then replay, then print buffered pushes not
already replayed (by `eventKey`). `--since` without `--follow` never launches a daemon;
with none running it reads `history.db` itself (read-only; no file is empty, an unreadable
Expand Down
Loading
Loading