tring-chat 0.1.6 → 0.1.8

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
@@ -50,6 +50,21 @@ sudo dnf install -y gcc-c++ make python3 # Fedora/RHEL
50
50
  Without those, `npm i -g tring-chat` fails while building node-pty. It takes a few seconds
51
51
  once they are present.
52
52
 
53
+ **macOS needs no compiler, but node-pty's prebuilds carry one defect.** It
54
+ publishes `prebuilds/darwin-*/spawn-helper` without the execute bit
55
+ ([node-pty#850](https://github.com/microsoft/node-pty/issues/850)), and every
56
+ PTY on macOS is forked through that binary — so an untreated install answers
57
+ the first tile with `posix_spawnp failed` and starts no shell. tring puts the
58
+ bit back, at install time and again before the first spawn, so this should
59
+ never be visible. If you installed with `--ignore-scripts` into a prefix you
60
+ do not own, the one-liner is:
61
+
62
+ ```
63
+ sudo chmod +x "$(npm root -g)/tring-chat/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper"
64
+ ```
65
+
66
+ All of this goes away when node-pty publishes a stable release carrying the fix.
67
+
53
68
  `tring` starts the daemon and opens a chromeless browser window — no address bar, no
54
69
  tab strip, its own taskbar entry. In that window the browser stops reserving
55
70
  `Ctrl+1`–`Ctrl+8` for tab switching, so slots 11–16 get their natural keys.
@@ -97,9 +112,9 @@ npm test # vitest
97
112
  npm i -g ./packages/server # install this checkout as `tring`
98
113
  ```
99
114
 
100
- Flags: `--port` (7331), `--host` (127.0.0.1), `--token`, `--scrollback` (5000),
101
- `--idle-ms` (3000), `--shell`, `--fs-root`, `--allow-origin`, `--insecure-no-token`,
102
- `--no-open`, `--no-update-check`, `--version`.
115
+ Flags: `--port` (7331), `--host` (127.0.0.1), `--token`, `--tls-cert`, `--tls-key`,
116
+ `--scrollback` (5000), `--idle-ms` (3000), `--shell`, `--fs-root`, `--allow-origin`,
117
+ `--insecure-no-token`, `--no-open`, `--no-update-check`, `--version`.
103
118
 
104
119
  ## On a phone
105
120
 
@@ -108,49 +123,89 @@ bar under the project tabs shows which session you are in. Tap it to get the sam
108
123
  `Ctrl+Space` opens on desktop, as a sheet you can thumb through; the button beside it jumps
109
124
  to the next finished session and counts how many are waiting.
110
125
 
111
- The daemon only listens on `127.0.0.1` by default. To reach it from a phone, bind it to
112
- the network and require a token:
126
+ The daemon only listens on `127.0.0.1` by default. Reaching it from a phone means binding
127
+ it to the network, and that traffic has to be encrypted — it carries the token, every
128
+ keystroke you type into a shell and everything the shell prints back, which is exactly
129
+ where SSH passphrases, API keys and `.env` contents live.
130
+
131
+ **Use an encrypted overlay network.** Tailscale or WireGuard, with the daemon still on the
132
+ address that network gives you. This is the supported way, not the cautious one:
113
133
 
114
134
  ```
115
- tring --host 0.0.0.0 --token "$(openssl rand -hex 32)"
135
+ tring --host 100.x.y.z # the Tailscale address of this machine
116
136
  ```
117
137
 
118
- then open `http://<your-machine>:7331/?token=some-long-secret` on the phone. A private
119
- network such as Tailscale is the safer way to do this than opening the port on a LAN.
138
+ If you must serve the LAN directly, terminate TLS yourself:
120
139
 
121
- Binding off localhost without a token is refused at startup rather than warned about: the
122
- daemon spawns shells, and off loopback the token is the only thing in front of them.
123
- `--insecure-no-token` overrides that if the network is already trusted that far.
140
+ ```
141
+ tring --host 0.0.0.0 --tls-cert cert.pem --tls-key key.pem
142
+ ```
143
+
144
+ Then open the link the daemon prints on the phone. `--tls-cert`/`--tls-key` switch the
145
+ daemon to `https` and `wss`; the page follows automatically. Bound off localhost over
146
+ plain `http`, the daemon warns at startup, because anyone on that network segment can read
147
+ the token off the wire and then has a shell.
148
+
149
+ Binding off localhost with `--insecure-no-token` is refused at startup rather than warned
150
+ about: the daemon spawns shells, and off loopback the token is the only thing in front of
151
+ them.
124
152
 
125
153
  The token is remembered on that first visit and then taken back off the address bar, but
126
154
  a secret that has travelled in a URL is only as private as the URL: it has already been
127
155
  through your history, any proxy log on the way, and whatever chat app you sent the link
128
- in. Treat the link as the secret, and rotate with a new `--token` rather than assuming an
129
- old link has expired.
156
+ in. Treat the link as the secret, and rotate it by deleting `~/.config/tring/token` (or
157
+ passing a new `--token`) rather than assuming an old link has expired.
130
158
 
131
159
  ## Who can reach the daemon
132
160
 
133
- The daemon spawns shells, so it only answers requests from the page it serves itself.
134
- That check matters more than the bind address: the same-origin policy does not cover
135
- WebSockets, so without it any website you happened to have open could open a socket to
136
- `ws://127.0.0.1:7331` and type into your terminals. Binding to loopback keeps other
137
- machines out, not other websites.
161
+ The daemon spawns shells, so **it requires a bearer token by default, on loopback as much
162
+ as off it.** Binding to `127.0.0.1` is not an authentication boundary: every process on
163
+ the machine can reach it — a postinstall script in some dependency of some project, a
164
+ second user account, a container sharing the host network namespace — and "can run code
165
+ on this box as any user" is not a boundary worth having in front of a shell.
166
+
167
+ If you do not pass `--token`, one is generated on first run and kept at
168
+ `~/.config/tring/token` with mode `0600`. It is stable across restarts, and the daemon
169
+ hands it to the browser window it opens, so there is nothing to copy by hand.
170
+
171
+ - **Scripts on the same machine** read the token back out of that file, which is what
172
+ keeps curl and `/api/sessions` working while other users on the box stay out:
173
+
174
+ ```
175
+ curl -s -H "Authorization: Bearer $(cat ~/.config/tring/token)" \
176
+ http://127.0.0.1:7331/api/sessions
177
+ ```
178
+
179
+ Inside a tring session there is nothing to read: `$TRING_TOKEN` is already set.
180
+ - **Another browser** needs the link once — `http://127.0.0.1:7331/?token=<secret>`. The
181
+ page stores it and scrubs it from the address bar, so installed PWAs start without it.
182
+ - `--insecure-no-token` turns authentication off entirely, and says so at startup. It is
183
+ the only way to get the old unauthenticated behaviour back.
184
+
185
+ On top of the token, the daemon only answers requests from the page it serves itself. The
186
+ same-origin policy does not cover WebSockets, so without that check any website you
187
+ happened to have open could open a socket to `ws://127.0.0.1:7331` and type into your
188
+ terminals.
138
189
 
139
190
  - A browser page from another origin is refused at the handshake. So is a domain rebound
140
191
  to 127.0.0.1, while the daemon is on loopback.
141
- - Non-browser clients send no `Origin` and are unaffected — the Claude Code hooks, curl
142
- and `/api/sessions` scripts keep working exactly as before.
192
+ - Non-browser clients send no `Origin` and are unaffected by *that* check — they need the
193
+ token instead.
143
194
  - `--allow-origin <origin>` adds one, for a front end you serve yourself. `npm run dev`
144
195
  sets it for the Vite server on :5173.
145
- - `--token` is what gates access once you bind past loopback, and is compared in constant
146
- time. The origin check cannot cover for it there: the hostname is then your own and
147
- unguessable to the daemon, so `Host` goes unpinned and a rebound name matches it. That
148
- is why a token is required rather than recommended off loopback.
196
+ - The token is compared in constant time. Off loopback the origin check cannot cover for
197
+ it: the hostname is then your own and unguessable to the daemon, so `Host` goes unpinned
198
+ and a rebound name matches it.
149
199
  - The directory picker (`/api/fs`) browses your home directory and the roots of projects
150
200
  you have already created. `--fs-root <path>` adds another — useful if your projects
151
201
  live somewhere like `D:\work`. Paths are resolved through symlinks before the check, so
152
202
  a link inside a root is not a way back out of it.
153
203
 
204
+ What this does **not** protect against: the browser window the daemon opens is launched
205
+ with the token on its command line, so on a shared machine another user who can read
206
+ `/proc/<pid>/cmdline` can read it there. The same is true of `--token` on your own command
207
+ line. If that matters, start with `--no-open` and open the printed link by hand.
208
+
154
209
  ## Install it as an app
155
210
 
156
211
  tring is a progressive web app. Once it is open in a browser, install it and it gets its
@@ -160,9 +215,10 @@ own icon and window with no address bar:
160
215
  - **iPhone and iPad (Safari):** the share button, then *Add to Home Screen*.
161
216
  - **Desktop (Chrome, Edge):** the install icon at the right of the address bar.
162
217
 
163
- If the daemon runs with `--token`, open it once with `?token=<secret>` on the URL before
164
- installing. The token is remembered in the browser, so the installed app starts without
165
- it. Opening a link with a new token replaces the remembered one.
218
+ Open it once with `?token=<secret>` on the URL before installing — the window the daemon
219
+ opens for you already carries it, and `~/.config/tring/token` holds it otherwise. The
220
+ token is remembered in the browser, so the installed app starts without it. Opening a link
221
+ with a new token replaces the remembered one.
166
222
 
167
223
  ## Projects
168
224
 
@@ -351,6 +407,25 @@ Two things are deliberate:
351
407
  Auto-executing whatever was there last time is how four dev servers end up fighting
352
408
  over a port.
353
409
 
410
+ ## Dropping images on a terminal
411
+
412
+ Drag a screenshot onto the centre terminal and its path is typed into the prompt,
413
+ the way dropping a file on any other terminal types one. Claude Code reads the
414
+ path from there.
415
+
416
+ It cannot work the way a native terminal's does. A browser hands a dropped file
417
+ over as bytes and withholds its location by design, and that location would be
418
+ the wrong machine's anyway whenever you have the deck open on a phone or a laptop
419
+ across the room. So the bytes go to the daemon, which writes them down on the
420
+ machine the shell is actually running on and answers with the path it chose.
421
+
422
+ - PNG, JPEG, GIF and WebP, up to 10MB. The type is read from the file's first
423
+ bytes, not from what the browser called it.
424
+ - The daemon names every file itself, under `~/.config/tring/uploads`. Nothing
425
+ a client sends reaches a filesystem path.
426
+ - The last 20 are kept. The directory is emptied when the daemon stops.
427
+ - The upload goes through the same token as the rest of the API.
428
+
354
429
  ## Claude Code
355
430
 
356
431
  Optional. Add a `Stop` hook to `~/.claude/settings.json` so a tile turns green the
@@ -361,7 +436,7 @@ instant Claude ends its turn instead of after the idle timeout:
361
436
  "hooks": {
362
437
  "Stop": [
363
438
  { "hooks": [ { "type": "command",
364
- "command": "curl -s -X POST \"$TRING_URL/api/sessions/$TRING_SESSION_ID/done\"" } ] }
439
+ "command": "curl -s -X POST -H \"Authorization: Bearer $TRING_TOKEN\" \"$TRING_URL/api/sessions/$TRING_SESSION_ID/done\"" } ] }
365
440
  ]
366
441
  }
367
442
  }
@@ -370,14 +445,18 @@ instant Claude ends its turn instead of after the idle timeout:
370
445
  In a PowerShell session the same hook is:
371
446
 
372
447
  ```powershell
373
- curl.exe -s -X POST "$env:TRING_URL/api/sessions/$env:TRING_SESSION_ID/done"
448
+ curl.exe -s -X POST -H "Authorization: Bearer $env:TRING_TOKEN" "$env:TRING_URL/api/sessions/$env:TRING_SESSION_ID/done"
374
449
  ```
375
450
 
376
451
  `curl.exe` rather than `curl`, which PowerShell aliases to `Invoke-WebRequest`.
377
452
 
378
- `TRING_URL`, `TRING_SESSION_ID`, `TRING_SLOT` and `TRING_PROJECT` are set in every
379
- session's environment. Session ids are globally unique, so this one snippet is correct
380
- in every session of every project and does not change as projects come and go.
453
+ `TRING_URL`, `TRING_TOKEN`, `TRING_SESSION_ID`, `TRING_SLOT` and `TRING_PROJECT` are set
454
+ in every session's environment. Session ids are globally unique, so this one snippet is
455
+ correct in every session of every project and does not change as projects come and go.
456
+
457
+ The `Authorization` header is what changed when the daemon started requiring a token by
458
+ default. A hook written against an older tring still runs, but the request now comes back
459
+ `401` and the tile waits for the idle timeout instead of turning green immediately.
381
460
 
382
461
  ## Stack
383
462
 
@@ -0,0 +1,55 @@
1
+ // src/spawn-helper.ts
2
+ import {
3
+ closeSync,
4
+ constants,
5
+ fchmodSync,
6
+ fstatSync,
7
+ openSync,
8
+ readdirSync
9
+ } from "node:fs";
10
+ import { createRequire } from "node:module";
11
+ import path from "node:path";
12
+ var EXEC = 73;
13
+ function nodePtyRoot() {
14
+ try {
15
+ return path.dirname(createRequire(import.meta.url).resolve("node-pty/package.json"));
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function spawnHelperPaths(root) {
21
+ const found = [path.join(root, "build", "Release", "spawn-helper")];
22
+ let prebuilds;
23
+ try {
24
+ prebuilds = readdirSync(path.join(root, "prebuilds"), { withFileTypes: true });
25
+ } catch {
26
+ return found;
27
+ }
28
+ for (const entry of prebuilds) {
29
+ if (entry.isDirectory()) found.push(path.join(root, "prebuilds", entry.name, "spawn-helper"));
30
+ }
31
+ return found;
32
+ }
33
+ function fixSpawnHelper(root = nodePtyRoot()) {
34
+ if (process.platform === "win32" || root === null) return [];
35
+ const fixed = [];
36
+ for (const file of spawnHelperPaths(root)) {
37
+ let fd = null;
38
+ try {
39
+ fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
40
+ const info = fstatSync(fd);
41
+ if (!info.isFile()) continue;
42
+ const mode = info.mode & 511;
43
+ if (mode & EXEC) continue;
44
+ fchmodSync(fd, mode | EXEC);
45
+ fixed.push(file);
46
+ } catch {
47
+ } finally {
48
+ if (fd !== null) closeSync(fd);
49
+ }
50
+ }
51
+ return fixed;
52
+ }
53
+
54
+ // <stdin>
55
+ for (const file of fixSpawnHelper()) console.log(`tring: made ${file} executable`);