You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(result.logs); // all captured output, newline-separated
276
-
277
-
awaitbridge.stopAsync();
278
-
```
279
-
280
-
The legacy API launches Studio, injects a temporary plugin, executes a script, and tears everything down. Use `BridgeConnection` instead for persistent workflows.
281
-
282
-
## WebSocket Protocol
283
-
284
-
All messages are JSON: `{ type, sessionId, payload }`. The plugin sends `register` on connect with its capabilities; the server dispatches actions and the plugin replies via `requestId` correlation.
285
-
286
-
**Plugin to Server:**
287
-
288
-
| Type | Payload | Description |
289
-
|------|---------|-------------|
290
-
|`register`|`{ sessionId, capabilities, pluginVersion, … }`| Handshake with capabilities |
291
-
|`scriptComplete`|`{ requestId, success, error?, output? }`| Response to `execute`|
292
-
|`stateResult`|`{ requestId, mode, placeName, placeId, gameId }`| Response to `queryState`|
293
-
|`screenshotResult`|`{ requestId, base64, width, height }`| Response to `captureScreenshot`|
294
-
|`dataModelResult`|`{ requestId, instances }`| Response to `queryDataModel`|
295
-
|`logsResult`|`{ requestId, entries }`| Response to `queryLogs`|
296
-
|`stateChange`|`{ state, previousState }`| Push event on state transition |
The bridge plugin ships as a thin runtime — no static Luau action modules. Instead, action code is pushed dynamically over the wire when a plugin connects:
328
-
329
-
1. Plugin connects and sends `register` with `registerAction` capability
330
-
2. Bridge host scans co-located `.luau` files from `src/commands/<group>/<name>/`
331
-
3. Each action's source is sent via `registerAction` message
332
-
4. Plugin calls `loadstring()` to install the handler at runtime
333
-
334
-
This means:
335
-
- Adding a new command requires only a `.ts` + `.luau` file in the command directory
336
-
- No plugin reinstallation needed when actions change
337
-
- Hot-reload during development: reconnect pushes updated action code
338
-
339
-
## Plugin Discovery
340
-
341
-
The persistent plugin discovers the bridge host automatically:
2. Health endpoint returns `{ status, port, sessions, uptime }`
345
-
3. Connect to `ws://localhost:{port}/plugin`
346
-
4. Send `register` message with capabilities
347
-
6. Receive `registerAction` messages for each command's Luau action
348
-
349
-
If the health endpoint is unreachable, the plugin retries with backoff. The plugin survives Studio restarts and reconnects automatically when a host becomes available.
350
-
351
-
### Role Detection
352
-
353
-
When a CLI command runs, `BridgeConnection` automatically detects whether to be host or client:
354
-
355
-
1. If `--remote` specified — connect as client
356
-
2. If inside a devcontainer — attempt remote connection first (3s timeout)
357
-
3. Try to bind the port — success means become host
358
-
4. Port in use — check `/health` — if healthy, become client; if stale, retry
0 commit comments