tring-chat 0.1.5 → 0.1.7

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 CHANGED
@@ -97,8 +97,9 @@ npm test # vitest
97
97
  npm i -g ./packages/server # install this checkout as `tring`
98
98
  ```
99
99
 
100
- Flags: `--port` (7331), `--host` (127.0.0.1), `--token`, `--scrollback` (5000),
101
- `--idle-ms` (3000), `--shell`, `--no-open`, `--no-update-check`, `--version`.
100
+ Flags: `--port` (7331), `--host` (127.0.0.1), `--token`, `--tls-cert`, `--tls-key`,
101
+ `--scrollback` (5000), `--idle-ms` (3000), `--shell`, `--fs-root`, `--allow-origin`,
102
+ `--insecure-no-token`, `--no-open`, `--no-update-check`, `--version`.
102
103
 
103
104
  ## On a phone
104
105
 
@@ -107,15 +108,89 @@ bar under the project tabs shows which session you are in. Tap it to get the sam
107
108
  `Ctrl+Space` opens on desktop, as a sheet you can thumb through; the button beside it jumps
108
109
  to the next finished session and counts how many are waiting.
109
110
 
110
- The daemon only listens on `127.0.0.1` by default. To reach it from a phone, bind it to
111
- the network and require a token:
111
+ The daemon only listens on `127.0.0.1` by default. Reaching it from a phone means binding
112
+ it to the network, and that traffic has to be encrypted — it carries the token, every
113
+ keystroke you type into a shell and everything the shell prints back, which is exactly
114
+ where SSH passphrases, API keys and `.env` contents live.
115
+
116
+ **Use an encrypted overlay network.** Tailscale or WireGuard, with the daemon still on the
117
+ address that network gives you. This is the supported way, not the cautious one:
118
+
119
+ ```
120
+ tring --host 100.x.y.z # the Tailscale address of this machine
121
+ ```
122
+
123
+ If you must serve the LAN directly, terminate TLS yourself:
112
124
 
113
125
  ```
114
- tring --host 0.0.0.0 --token some-long-secret
126
+ tring --host 0.0.0.0 --tls-cert cert.pem --tls-key key.pem
115
127
  ```
116
128
 
117
- then open `http://<your-machine>:7331/?token=some-long-secret` on the phone. A private
118
- network such as Tailscale is the safer way to do this than opening the port on a LAN.
129
+ Then open the link the daemon prints on the phone. `--tls-cert`/`--tls-key` switch the
130
+ daemon to `https` and `wss`; the page follows automatically. Bound off localhost over
131
+ plain `http`, the daemon warns at startup, because anyone on that network segment can read
132
+ the token off the wire and then has a shell.
133
+
134
+ Binding off localhost with `--insecure-no-token` is refused at startup rather than warned
135
+ about: the daemon spawns shells, and off loopback the token is the only thing in front of
136
+ them.
137
+
138
+ The token is remembered on that first visit and then taken back off the address bar, but
139
+ a secret that has travelled in a URL is only as private as the URL: it has already been
140
+ through your history, any proxy log on the way, and whatever chat app you sent the link
141
+ in. Treat the link as the secret, and rotate it by deleting `~/.config/tring/token` (or
142
+ passing a new `--token`) rather than assuming an old link has expired.
143
+
144
+ ## Who can reach the daemon
145
+
146
+ The daemon spawns shells, so **it requires a bearer token by default, on loopback as much
147
+ as off it.** Binding to `127.0.0.1` is not an authentication boundary: every process on
148
+ the machine can reach it — a postinstall script in some dependency of some project, a
149
+ second user account, a container sharing the host network namespace — and "can run code
150
+ on this box as any user" is not a boundary worth having in front of a shell.
151
+
152
+ If you do not pass `--token`, one is generated on first run and kept at
153
+ `~/.config/tring/token` with mode `0600`. It is stable across restarts, and the daemon
154
+ hands it to the browser window it opens, so there is nothing to copy by hand.
155
+
156
+ - **Scripts on the same machine** read the token back out of that file, which is what
157
+ keeps curl and `/api/sessions` working while other users on the box stay out:
158
+
159
+ ```
160
+ curl -s -H "Authorization: Bearer $(cat ~/.config/tring/token)" \
161
+ http://127.0.0.1:7331/api/sessions
162
+ ```
163
+
164
+ Inside a tring session there is nothing to read: `$TRING_TOKEN` is already set.
165
+ - **Another browser** needs the link once — `http://127.0.0.1:7331/?token=<secret>`. The
166
+ page stores it and scrubs it from the address bar, so installed PWAs start without it.
167
+ - `--insecure-no-token` turns authentication off entirely, and says so at startup. It is
168
+ the only way to get the old unauthenticated behaviour back.
169
+
170
+ On top of the token, the daemon only answers requests from the page it serves itself. The
171
+ same-origin policy does not cover WebSockets, so without that check any website you
172
+ happened to have open could open a socket to `ws://127.0.0.1:7331` and type into your
173
+ terminals.
174
+
175
+ - A browser page from another origin is refused at the handshake. So is a domain rebound
176
+ to 127.0.0.1, while the daemon is on loopback.
177
+ - Non-browser clients send no `Origin` and are unaffected by *that* check — they need the
178
+ token instead.
179
+ - `--allow-origin <origin>` adds one, for a front end you serve yourself. `npm run dev`
180
+ sets it for the Vite server on :5173.
181
+ - The token is compared in constant time. Off loopback the origin check cannot cover for
182
+ it: the hostname is then your own and unguessable to the daemon, so `Host` goes unpinned
183
+ and a rebound name matches it.
184
+ - The directory picker (`/api/fs`) browses your home directory and the roots of projects
185
+ you have already created. `--fs-root <path>` adds another — useful if your projects
186
+ live somewhere like `D:\work`. Paths are resolved through symlinks before the check, so
187
+ a link inside a root is not a way back out of it.
188
+
189
+ What this does **not** protect against: the browser window the daemon opens is launched
190
+ with the token on its command line, so on a shared machine another user who can read
191
+ `/proc/<pid>/cmdline` can read it there. The same is true of `--token` on your own command
192
+ line. If that matters, start with `--no-open` and open the printed link by hand.
193
+
119
194
  ## Install it as an app
120
195
 
121
196
  tring is a progressive web app. Once it is open in a browser, install it and it gets its
@@ -125,9 +200,10 @@ own icon and window with no address bar:
125
200
  - **iPhone and iPad (Safari):** the share button, then *Add to Home Screen*.
126
201
  - **Desktop (Chrome, Edge):** the install icon at the right of the address bar.
127
202
 
128
- If the daemon runs with `--token`, open it once with `?token=<secret>` on the URL before
129
- installing. The token is remembered in the browser, so the installed app starts without
130
- it. Opening a link with a new token replaces the remembered one.
203
+ Open it once with `?token=<secret>` on the URL before installing — the window the daemon
204
+ opens for you already carries it, and `~/.config/tring/token` holds it otherwise. The
205
+ token is remembered in the browser, so the installed app starts without it. Opening a link
206
+ with a new token replaces the remembered one.
131
207
 
132
208
  ## Projects
133
209
 
@@ -174,18 +250,9 @@ Browsers reserve `Ctrl+1`–`Ctrl+8` for tab switching, so `Shift+digit` is the
174
250
  fallback that always works in an ordinary tab. Clicking a thumbnail also focuses it,
175
251
  and right-clicking one opens the same dialog `r` does.
176
252
 
177
- Those are picker keys. Everything else you type goes to the focused session, with one
178
- exception: **`Ctrl+Enter` and `Shift+Enter` insert a newline** instead of submitting.
179
- A terminal has no modifier bits for Enter — every variant is a bare `\r` on the wire —
180
- so tring sends `ESC`+`CR` for those two chords, which is what Claude Code and other
181
- agent CLIs read as "break the line". Native terminals need `/terminal-setup` to do the
182
- same thing; here it works out of the box.
183
-
184
253
  ## Naming and colouring tiles
185
254
 
186
255
  Right-click a tile — or press `r` in the picker — to give it a name and a colour.
187
- The same dialog has a **Delete** button, which kills the session and frees the slot
188
- back to empty; `x` in the picker does the same thing.
189
256
 
190
257
  The colour is a ring *outside* the status border, never instead of it, so a tile you
191
258
  have tinted still reports whether it is busy, finished or dead. Twenty-four choices:
@@ -335,7 +402,7 @@ instant Claude ends its turn instead of after the idle timeout:
335
402
  "hooks": {
336
403
  "Stop": [
337
404
  { "hooks": [ { "type": "command",
338
- "command": "curl -s -X POST \"$TRING_URL/api/sessions/$TRING_SESSION_ID/done\"" } ] }
405
+ "command": "curl -s -X POST -H \"Authorization: Bearer $TRING_TOKEN\" \"$TRING_URL/api/sessions/$TRING_SESSION_ID/done\"" } ] }
339
406
  ]
340
407
  }
341
408
  }
@@ -344,14 +411,18 @@ instant Claude ends its turn instead of after the idle timeout:
344
411
  In a PowerShell session the same hook is:
345
412
 
346
413
  ```powershell
347
- curl.exe -s -X POST "$env:TRING_URL/api/sessions/$env:TRING_SESSION_ID/done"
414
+ curl.exe -s -X POST -H "Authorization: Bearer $env:TRING_TOKEN" "$env:TRING_URL/api/sessions/$env:TRING_SESSION_ID/done"
348
415
  ```
349
416
 
350
417
  `curl.exe` rather than `curl`, which PowerShell aliases to `Invoke-WebRequest`.
351
418
 
352
- `TRING_URL`, `TRING_SESSION_ID`, `TRING_SLOT` and `TRING_PROJECT` are set in every
353
- session's environment. Session ids are globally unique, so this one snippet is correct
354
- in every session of every project and does not change as projects come and go.
419
+ `TRING_URL`, `TRING_TOKEN`, `TRING_SESSION_ID`, `TRING_SLOT` and `TRING_PROJECT` are set
420
+ in every session's environment. Session ids are globally unique, so this one snippet is
421
+ correct in every session of every project and does not change as projects come and go.
422
+
423
+ The `Authorization` header is what changed when the daemon started requiring a token by
424
+ default. A hook written against an older tring still runs, but the request now comes back
425
+ `401` and the tile waits for the idle timeout instead of turning green immediately.
355
426
 
356
427
  ## Stack
357
428