Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
Terminal door: tty gating test for mute, end-turn and chat, and tty writes reaching web viewers live #47
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
The room now has a terminal door: forge.json declares a tty, so ssh to the app opens the arm's chat and queue. The server checks every terminal command with the same rules it uses for the web page. How it works.
shipped merged
The room now has a terminal door: forge.json declares a tty, so ssh to the app opens the arm's chat and queue. The server checks every terminal command with the same rules it uses for the web page.
How it works. The forge's own source (trevato/forge src/apps/tty.ts, src/apps/runtime.ts) answers @smith's question about the terminal contract:
- The forge runs the
ttycommand on a pty, from the deployed checkout. - It gets the app's own environment (
PORT,FORGE_APP_IDENTITY_KEY), plusFORGE_APP_USER,FORGE_APP_USER_IDandFORGE_APP_USER_ROLE(adminfor anyone who may write the repository,userfor other accounts, empty for a guest). - Its cell may reach the running app on
127.0.0.1:$PORT; the forge's comment there calls the terminal "the app's own client".
So the terminal connects to the running server's /live socket like a browser does. It signs the person's identity with the app key and the server checks that signature as it does a browser's. Who may do what is decided only on the server, and I didn't refactor the Lobby. That refactor was part of the closed #41.
Files to look at:
Software/so101/src/terminal.ts(new):
- builds the signed identity (valid for 60 s, which only the handshake needs) and the socket address from PORT;
- turns typed lines into the existing socket messages: plain text is said in the chat, plus /join, /leave, /end [name], /mute <name>, /unmute <name>, /who, /help, /quit;
- strips control and escape characters from room text, so a chat line cannot drive someone's terminal.
src/tty.ts(new): the program the forge starts. It reads input only once connected, so nothing typed meanwhile is lost, and/quitdoesn't report "server went away".src/terminal.test.ts(new), run against a real relay andLobbywith a web viewer and terminals in the same room:
- a guest at the terminal can watch but can't chat or join the queue;
- a terminal line reaches web viewers live as plain text (<b> arrives as typed), and web lines reach the terminal;
- a terminal join and hand-back show on the page;
- mute and end-turn are refused for non-owners at the terminal;
- the owner's terminal mute reaches the muted person's page, and that person can't chat from either their page or a terminal;
- the owner's terminal /end passes the turn on.
src/manifest.test.ts: checks that thettyfile named inforge.jsonexists.src/chat.ts,src/identity.ts: three existing patterns are now exported so the terminal reuses them; no behaviour change.Software/README.md: a new "The terminal" section.
Not done: guests can't pick a name at the terminal (that sign-up is browser-only). The terminal has no moderation commands beyond mute and end (ban, delete, settings); those stay on the page and /admin.
Testing: the type check passes; the terminal, manifest, lobby, chat and identity suites (41 tests) pass. In one of 8 repeated runs, the existing lobby test "/admin is the owner's…" timed out at 2 s. It passed in the other 7 runs and on its own, and this change doesn't touch it. I also ran fake-serve.ts with a key and drove it through tty.ts as the owner (chat, /join, /who, /end) and as a guest (refused with "join to take part").
Try it: locally, run PORT=8102 bun run Software/so101/bench/fake-serve.ts, then PORT=8102 bun run Software/so101/src/tty.ts in a second shell (you're the owner there). On the preview, use the command in FORGE_APP_SSH, with a web viewer open beside it.
Closes #37
🤖 Generated with Claude Code
Approved. The terminal is a real client of /live: it signs the forge-supplied identity with FORGE_APP_IDENTITY_KEY (60 s lifetime), so the Lobby gates it exactly like the page. A guest gets no headers and is refused chat and join. Mute and end are owner-only on the server, and the tests run both doors against a real relay. Room text is stripped of control characters, PORT is validated, and no shell or SQL is built from input. forge.json, the manifest test and the README all cover the tty. I could not reach the preview from my sandbox, so this rests on the source and tests. Next: (1) add a test that a muted or banned person reconnecting at the terminal is still refused after the server restarts, if mute state persists; (2) the terminal has no ban or delete commands, so add them, or say in the README that they stay on the page. The tty also exits on server loss with no reconnect, so consider a short retry.
The room now has a terminal door:
forge.jsondeclares atty, sosshto the app opens the arm's chat and queue. The server checks every terminal command with the same rules it uses for the web page.How it works. The forge's own source (
trevato/forgesrc/apps/tty.ts,src/apps/runtime.ts) answers @smith's question about the terminal contract:ttycommand on a pty, from the deployed checkout.PORT,FORGE_APP_IDENTITY_KEY), plusFORGE_APP_USER,FORGE_APP_USER_IDandFORGE_APP_USER_ROLE(adminfor anyone who may write the repository,userfor other accounts, empty for a guest).127.0.0.1:$PORT; the forge's comment there calls the terminal "the app's own client".So the terminal connects to the running server's
/livesocket like a browser does. It signs the person's identity with the app key and the server checks that signature as it does a browser's. Who may do what is decided only on the server, and I didn't refactor theLobby. That refactor was part of the closed #41.Files to look at:
Software/so101/src/terminal.ts(new):- builds the signed identity (valid for 60 s, which only the handshake needs) and the socket address from
PORT; - turns typed lines into the existing socket messages: plain text is said in the chat, plus/join,/leave,/end [name],/mute <name>,/unmute <name>,/who,/help,/quit; - strips control and escape characters from room text, so a chat line cannot drive someone's terminal.src/tty.ts(new): the program the forge starts. It reads input only once connected, so nothing typed meanwhile is lost, and/quitdoesn't report "server went away".src/terminal.test.ts(new), run against a real relay andLobbywith a web viewer and terminals in the same room:- a guest at the terminal can watch but can't chat or join the queue; - a terminal line reaches web viewers live as plain text (
<b>arrives as typed), and web lines reach the terminal; - a terminal join and hand-back show on the page; - mute and end-turn are refused for non-owners at the terminal; - the owner's terminal mute reaches the muted person's page, and that person can't chat from either their page or a terminal; - the owner's terminal/endpasses the turn on.src/manifest.test.ts: checks that thettyfile named inforge.jsonexists.src/chat.ts,src/identity.ts: three existing patterns are now exported so the terminal reuses them; no behaviour change.Software/README.md: a new "The terminal" section.Not done: guests can't pick a name at the terminal (that sign-up is browser-only). The terminal has no moderation commands beyond mute and end (ban, delete, settings); those stay on the page and
/admin.Testing: the type check passes; the terminal, manifest, lobby, chat and identity suites (41 tests) pass. In one of 8 repeated runs, the existing lobby test "/admin is the owner's…" timed out at 2 s. It passed in the other 7 runs and on its own, and this change doesn't touch it. I also ran
fake-serve.tswith a key and drove it throughtty.tsas the owner (chat,/join,/who,/end) and as a guest (refused with "join to take part").Try it: locally, run
PORT=8102 bun run Software/so101/bench/fake-serve.ts, thenPORT=8102 bun run Software/so101/src/tty.tsin a second shell (you're the owner there). On the preview, use the command inFORGE_APP_SSH, with a web viewer open beside it.Closes #37
🤖 Generated with Claude Code
Closes #37