How cplieger/web-terminal-kiro works
1. What this repo is
- web-terminal-kiro is a small Go server that exposes a browser-based terminal for kiro-cli.
- It is not a generic chat app or IDE; each browser tab gets its own live PTY session running the CLI directly.
2. Top-level runtime shape
- The backend is a Go HTTP server (main.go, routes.go) that serves the web app, upgrades terminal sessions over WebSocket, and manages startup/bootstrap.
- The frontend is a TypeScript app in static-src/ that is built into the committed static/ assets and served by the Go binary.
3. Request/data path
- Browser → HTTP server → WebSocket terminal protocol → terminal engine / PTY session → kiro-cli.
- Terminal output is rendered in the browser using real text nodes, not a canvas, which is why selection, scrolling, and touch interaction behave like native text.
4. Session model
- The central unit is a per-tab session.
- Sessions are PTY-backed and isolated from each other; reconnect logic replays screen state and scrollback so a dropped connection does not lose the terminal context.
5. Backend responsibilities
- The Go service is responsible for:
- listening on KWEB_ADDR (:9848 by default),
- creating session managers,
- serving static files,
- handling WebSocket connections,
- logging client access,
- and enforcing trusted proxy handling.
- Most terminal semantics are delegated to shared terminal libraries rather than reimplemented here.
6. Frontend responsibilities
- static-src/app.ts is the browser UI for tabs, keyboard toolbar, touch interactions, selection, and reconnect behavior.
- The build/test tooling in static-src/ indicates a modern TypeScript toolchain with unit tests, linting, and type checking.
- The compiled output is checked in under static/, so the Go binary can serve a self-contained UI.
7. Persistence and filesystem boundaries
- /config is the persistent control plane for user state: kiro-cli auth, settings, installed tools, SSH config, git config, and MCP settings.
- /workspace is the working directory where terminal sessions start and where repos/files live.
- The container intentionally runs as root so tools like git, gh, and SSH work without extra setup.
8. Bootstrap and tool installation
- On first boot, the server ensures kiro-cli is installed; it is downloaded on demand rather than shipped in the image.
- Additional tools are defined in /config/tools.json and installed into /config/tools/, which persists across restarts.
- This makes tool availability part of runtime configuration rather than build-time packaging.
9. Proxying and security boundary
- The app has no built-in authentication; the intended deployment boundary is a reverse proxy or loopback-only binding.
- TRUSTED_PROXIES controls whether X-Forwarded-For is trusted for access logs; if unset, the direct socket peer is used.
- This is a meaningful architectural boundary because it determines whether client IPs are derived from the proxy chain or from the transport peer.
10. Containerization and deployment
- Dockerfile, compose.yaml, and entrypoint.sh define the standard deployment shape.
- The image is multi-arch and intended for GHCR/Docker Hub use.
- The healthcheck is part of the architecture: it only reports healthy when both the server and the kiro-cli install are usable.
11. Testing and verification
- Go tests cover server behavior and trust-proxy logic (main_test.go, routes_test.go, trusted_proxies_test.go).
- There are frontend tests in static-src/app.test.ts.
- CI is split across linting, coverage, security, CodeQL, and release workflows, which suggests a strong emphasis on supply-chain and runtime safety.
12. Overall system boundary
- The repo’s boundary is intentionally narrow: it glues together a browser UI, a PTY/session engine, and the kiro-cli process.
- The main architectural diagram should show the browser on one side, the Go server and session manager in the middle, and kiro-cli plus persisted /config and /workspace volumes on the other side.
Main entry points: main.go HTTP server · routes.go Routes · entrypoint.sh Bootstrap · main_test.go Tests
Components 16
Client
Browser-facing runtime and UI
- Browser · User opens a tab and interacts with the terminal UI
- Terminal UI · Tab UI, keyboard toolbar, touch, selection, and reconnect logic
static-src/app.ts - Static assets · Built browser bundle and HTML served by the Go binary
static/index.html
Go backend
HTTP server, routing, session management, and bootstrap
- HTTP server · Main process that listens, serves files, and starts the app
main.go - Routes · Request handling, WebSocket upgrades, access logging, and proxy-aware client IPs
routes.go - Bootstrap · Startup flow that prepares the runtime and verifies prerequisites
entrypoint.sh
Terminal runtime
PTY-backed terminal sessions and external CLI
- Session manager · Creates isolated tab sessions and reconnects dropped clients
- PTY engine · Streams terminal input/output and preserves scrollback state
- kiro-cli · The terminal application launched inside each session
Persistent state
Config, workspace, and tool installation boundaries
- Config tools · Auth, settings, SSH, git, MCP, and installed tool state
tools.json - Workspace · Session working directory for repos and files
- Tool install · On-demand tool definitions and installs managed at runtime
setup-tools.sh
Delivery
Container packaging and startup
- Container image · Docker and compose packaging for the runnable service
Dockerfile - Healthcheck · Reports healthy only when the server and CLI install are usable
compose.yaml
Verification
Tests and automation
- Tests · Go and frontend tests for server behavior and UI behavior
main_test.go - CI workflows · Lint, coverage, security, CodeQL, and release automation
.github/workflows/ci.yaml
Connections 18
- Browser → Terminal UI: uses · The browser loads and interacts with the terminal UI
- Terminal UI → Static assets: loads from · The UI is served as built static content
- Static assets → HTTP server: served by · The Go binary serves the compiled frontend assets
- Browser → Routes: HTTP/WebSocket · Tabs connect to the backend over normal requests and upgraded terminal channels
- HTTP server → Routes: hosts · Main process wires routes and startup behavior
- Routes → Session manager: creates · Each browser tab gets an isolated session
- Session manager → PTY engine: drives · Sessions are backed by PTY I/O and replayable screen state
- PTY engine → kiro-cli: runs · The terminal engine launches and communicates with kiro-cli
- Session manager → Workspace: uses · Sessions start in the shared workspace directory
- HTTP server → Config tools: reads/writes · Startup and runtime settings come from persistent config
- Bootstrap → Tool install: installs · First boot and runtime tool setup are driven by tool definitions
- Bootstrap → kiro-cli: ensures · Startup flow ensures kiro-cli is available before normal operation
- Container image → Bootstrap: starts · Deployment entrypoint launches the service inside the container
- Container image → Healthcheck: reports · Container health depends on server readiness and tool availability
- Tests → HTTP server: verifies · Backend tests cover server and proxy behavior
- Tests → Terminal UI: verifies · Frontend tests cover browser interaction logic
- CI workflows → Tests: runs · CI automates linting, coverage, security, and release checks
- Routes → Config tools: trusts proxy config · Access logging can derive client IPs from trusted proxy headers