{"id":49118109,"url":"https://github.com/sourecode/web-shell","last_synced_at":"2026-04-21T09:01:23.205Z","repository":{"id":352710156,"uuid":"1216266437","full_name":"SoureCode/web-shell","owner":"SoureCode","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-20T20:46:54.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-20T21:11:55.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoureCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-20T18:28:17.000Z","updated_at":"2026-04-20T20:46:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/SoureCode/web-shell","commit_stats":null,"previous_names":["sourecode/web-shell"],"tags_count":null,"template":false,"template_full_name":"SoureCode/devcontainer-template","purl":"pkg:github/SoureCode/web-shell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoureCode%2Fweb-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoureCode%2Fweb-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoureCode%2Fweb-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoureCode%2Fweb-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoureCode","download_url":"https://codeload.github.com/SoureCode/web-shell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoureCode%2Fweb-shell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32084721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T06:27:27.065Z","status":"ssl_error","status_checked_at":"2026-04-21T06:27:21.250Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-21T09:01:20.800Z","updated_at":"2026-04-21T09:01:23.192Z","avatar_url":"https://github.com/SoureCode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web-shell\n\nPersistent browser terminal. Spawns shells inside `tmux` sessions on a Node.js backend and streams them over WebSocket to [xterm.js](https://xtermjs.org/). Sessions live server-side with a scrollback buffer and survive page refreshes, device switches, _and_ server restarts — `tmux` keeps the shells running, and the server reattaches to them on boot.\n\n## Stack\n\n- **Server**: Node.js + TypeScript, `node-pty`, `ws`, `tmux` (required on `$PATH`)\n- **Client**: TypeScript + SCSS + Vite, `xterm.js`\n- Strict TS everywhere (`noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, …)\n\n## Requirements\n\n- Node.js 20+\n- `tmux` installed and on `$PATH` — every session is a `tmux new-session -A -s webshell-\u003cid\u003e` under the hood.\n\n## Layout\n\n```\nserver/src/\n  types/       session \u0026 protocol shapes\n  session/     Session, SessionManager, scrollback\n  http/        REST router\n  ws/          upgrade handler, per-socket wiring, parser\n  utils/       cors, json, shell helpers\n  config.ts\n  index.ts\n\nclient/src/\n  types/       protocol, session, terminal shapes\n  api/         REST client, socket factory\n  terminal/    xterm factory, attach, resize, parser\n  ui/          sidebar, status\n  state/       localStorage persistence\n  utils/       dom, json\n  styles/      SCSS partials\n  config.ts\n  main.ts\n```\n\nOne concept per file. Types under `types/`, helpers under `utils/`.\n\n## Develop\n\n```bash\nnpm install\nnpm run dev\n```\n\n- Server: `http://localhost:4000`\n- Client: `http://localhost:5173` (proxies `/api` and `/ws` to the server)\n\n## Build / single-process deploy\n\n```bash\nnpm run build\nnpm start\n# or shorthand:\nnpm run preview\n```\n\n`npm run build` compiles the server to `server/dist/` and bundles the client to `client/dist/`. `npm start` runs the compiled server, which also serves `client/dist/` statically with SPA fallback — one port, one origin, no Vite / CORS in the way.\n\nSet `CLIENT_DIST` to override the path, or leave it unset and the server auto-detects `../client/dist` next to its own build output.\n\n## API\n\n| Method | Path                    | Description                    |\n| ------ | ----------------------- | ------------------------------ |\n| GET    | `/api/sessions`         | list sessions                  |\n| POST   | `/api/sessions`         | create session                 |\n| GET    | `/api/sessions/:id`     | session info                   |\n| DELETE | `/api/sessions/:id`     | destroy session                |\n| WS     | `/api/sessions/:id/stream` | attach: history + I/O + resize |\n\n### WebSocket protocol\n\nClient → server:\n\n```ts\n{ type: \"input\",  data: string }\n{ type: \"resize\", cols: number, rows: number }\n```\n\nServer → client:\n\n```ts\n{ type: \"history\", data: string }              // scrollback replay on connect\n{ type: \"output\",  data: string }              // live PTY output\n{ type: \"exit\",    code: number, signal?: number }\n```\n\n## Persistence model\n\nEach `Session` is a `tmux` session named `webshell-\u003cuuid\u003e`, spawned under `node-pty` with a bundled `tmux.conf` (`server/tmux.conf`). `SessionManager` owns the live wrappers and keeps the last 256 KB of PTY output in a ring buffer per session. New WebSocket connections receive a sanitized `history` frame with the current buffer before live `output` streams, so the terminal repaints to the current state on refresh.\n\nBecause the shells run inside `tmux`, they outlive the Node process. On startup, the server enumerates existing `webshell-*` tmux sessions, reattaches to each one, and seeds its scrollback from `tmux capture-pane`. Killing a session via the API runs `tmux kill-session`.\n\nThe active session id is stored in `localStorage` so reloads reopen the same session automatically.\n\n## Config\n\n| Variable          | Default                                                 | Description                                                                                    |\n| ----------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |\n| `HOST`            | `127.0.0.1`                                             | Bind address. Loopback by default so an unfronted instance is never silently network-reachable. Set to `0.0.0.0` only when the port is protected by a reverse proxy / tunnel. |\n| `PORT`            | `4000`                                                  | Server HTTP/WS port                                                                            |\n| `SHELL`           | env / `bash`                                            | Default shell for new sessions                                                                 |\n| `ALLOWED_ORIGINS` | `http://localhost:5173,http://127.0.0.1:5173`           | Comma-separated origin allow-list. Requests with a disallowed `Origin` are rejected (HTTP 403 / WS 403). Required for the frontend you actually deploy. |\n| `AUTH_TOKEN`      | _unset_                                                 | Optional shared bearer token. When set, REST requires `Authorization: Bearer \u003ctoken\u003e` and WS requires `?token=\u003ctoken\u003e`. When unset, auth is disabled — only safe behind an authenticated upstream (Coder agent, SSO proxy, Tailscale, etc.). |\n\n## Security model\n\nweb-shell has no user/account model. It exposes two trust modes:\n\n1. **Token mode** (`AUTH_TOKEN` set). A single shared bearer token gates REST and WS. The browser prompts once and caches the token in `localStorage`. Suitable for solo/personal deployments.\n2. **Proxy mode** (`AUTH_TOKEN` unset). The app trusts whatever sits in front of it — a reverse proxy with SSO, the Coder workspace agent tunnel, a VPN, etc. **Never expose a proxy-mode instance directly to an untrusted network.** The default `HOST=127.0.0.1` bind helps prevent accidental exposure.\n\nRegardless of mode, cross-origin requests are rejected unless the `Origin` matches `ALLOWED_ORIGINS`, closing CSWSH and drive-by session-creation paths.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourecode%2Fweb-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourecode%2Fweb-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourecode%2Fweb-shell/lists"}