feat: add static previews to the room pane
The preview tool could only name a port, so a static build needed a server the terminal had to keep alive. `preview` now accepts a path: the app reads the file or folder over the room's ssh sandbox and serves it from a signed host, with `..` and dotfiles refused and a 16 MiB cap. The target is stored with the room and replayed as a durable event. The pane shows a static path with a reload control and keeps the port field as a local fallback.
This commit is contained in:
1 parent
5be17cf4ef
commit
36de0aace7
20 files changed
+1046
-145
No files matched your search
+39
-25
@@ -328,48 +328,62 @@ cost. The footer is per turn, not per message.
|
||||
|
||||
### Preview
|
||||
|
||||
Iframe at a preview URL. Discovery is a manual port field plus a scrape
|
||||
of `bash` output for `localhost:<port>` and `127.0.0.1:<port>` shown as
|
||||
suggestions. No heuristics beyond that.
|
||||
The pane shows one target per room, either a port inside the sandbox or a
|
||||
static file or folder. The agent sets it with the `preview` tool. The target
|
||||
is stored and written to the room log as a durable `preview` event, so every
|
||||
open pane updates and a reconnecting viewer gets it with the room detail.
|
||||
The port field remains as a local fallback.
|
||||
|
||||
Serving: the app's listener recognizes preview hosts and tunnels each
|
||||
request over ssh `direct-tcpip` to the sandbox. The ssh connection is
|
||||
opened once per sandbox target and reused by every room and port on it.
|
||||
TLS and DNS happen in the reverse proxy.
|
||||
Port targets tunnel each request over ssh `direct-tcpip` to the sandbox. The
|
||||
ssh connection is opened once per sandbox target and reused by every room and
|
||||
port on it.
|
||||
|
||||
Static targets are read over ssh and served by the app. No server process is
|
||||
started, so a preview does not depend on what a terminal is doing. A static
|
||||
path is workspace-relative. A folder must contain `index.html`; a file is
|
||||
served as itself and its parent becomes the asset root. Requests map onto that
|
||||
root, and `/` serves the entry file. `..`, NUL bytes, and dotfiles are refused
|
||||
in requests, and a target path that names a hidden file or folder is refused.
|
||||
Files above 16 MiB are refused. The read uses the same ssh target as the
|
||||
agent, so it adds no network path or permission.
|
||||
|
||||
Layout, one wildcard record:
|
||||
|
||||
```
|
||||
app https://together.<domain>/room/<id>/
|
||||
preview https://r<room>-p<port>-<expiry>-<sig>.preview.<domain>/
|
||||
https://r<room>-s<hash>-<expiry>-<sig>.preview.<domain>/
|
||||
```
|
||||
|
||||
The room, port, expiry, and a 24-hex HMAC signature form the first
|
||||
label. The signature is minted by the app when the pane opens and
|
||||
checked by the proxy, so the URL is not guessable from a room id. It
|
||||
expires after 24 hours, and loading the room mints a fresh one. Treat a
|
||||
copied preview URL as a read capability for that port until it expires.
|
||||
`hash` is 12 hex characters over the static root and entry file. A link
|
||||
minted for one static target stops matching when the agent points the preview
|
||||
somewhere else. The room, target, expiry, and a 24-hex HMAC signature form
|
||||
the first label. The signature is minted by the app when the pane requests a
|
||||
URL and checked by the proxy, so the URL is not guessable from a room id. It
|
||||
expires after 24 hours, and loading the room mints a fresh one. Treat a copied
|
||||
preview URL as a read capability for that target until it expires.
|
||||
|
||||
The preview needs its own hostname. It is repo code, and on the app's
|
||||
origin it could call the API with the viewer's cookie, which turns every
|
||||
opened preview into an account-stealer for the other members. A separate
|
||||
`preview.` host has no app cookie (the cookie is `__Host-`, no `Domain`),
|
||||
and preview responses carry
|
||||
The preview needs its own hostname. It is repo code, and on the app's origin
|
||||
it could call the API with the viewer's cookie, which turns every opened
|
||||
preview into an account-stealer for the other members. A separate `preview.`
|
||||
host has no app cookie (the cookie is `__Host-`, no `Domain`), and preview
|
||||
responses carry
|
||||
`Content-Security-Policy: frame-ancestors https://together.<domain>`.
|
||||
The iframe carries `sandbox="allow-scripts allow-same-origin allow-forms
|
||||
allow-popups"`.
|
||||
|
||||
Each room+port gets its own hostname, so root-absolute asset URLs
|
||||
Each room and target gets its own hostname, so root-absolute asset URLs
|
||||
(`/assets/app.js`), JS-constructed URLs, and `Location` headers need no
|
||||
rewriting. Vite's HMR WebSocket is not proxied in v1; reload with the
|
||||
button after an edit, or disable HMR in the previewed server.
|
||||
rewriting. Vite's HMR WebSocket is not proxied in v1. Static previews ignore
|
||||
HMR; port previews can disable it and use the reload button.
|
||||
|
||||
Auth: the preview host carries no app cookie, and the signed label is
|
||||
the whole capability. Preview responses carry `Referrer-Policy:
|
||||
no-referrer` so the signed host does not leak to third-party resources.
|
||||
The app's CSP names `*.<preview host>` in `frame-src`.
|
||||
Auth: the preview host carries no app cookie, and the signed label is the
|
||||
whole capability. Preview responses carry `Referrer-Policy: no-referrer` so
|
||||
the signed host does not leak to third-party resources. The app's CSP names
|
||||
`*.<preview host>` in `frame-src`.
|
||||
|
||||
Refresh: a button and a reload when a turn ends.
|
||||
Refresh: the pane reloads when a `preview` event arrives, and the button
|
||||
reloads the current target.
|
||||
|
||||
### Terminal
|
||||
|
||||
|
||||
Reference in new issue
Block a user