diff --git a/docker-compose.yml b/docker-compose.yml index 13be6e01..a5417288 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ # CLAUDE_CONFIG_DIR=/mnt/user/appdata/workshop/claude # PUID=99 # PGID=100 +# DEV_HOST=tower.lan # host name/IP you browse to, used in dev-server URLs services: workshop: build: . @@ -20,6 +21,8 @@ services: restart: unless-stopped ports: - "3002:3002" + # Dev servers agents start (docs/docker.md); keep in sync with WORKSHOP_DEV_PORTS + - "4100-4119:4100-4119" environment: PORT: "3002" NODE_ENV: production @@ -30,6 +33,9 @@ services: # Optional: Ollama server + model for the "Local (Ollama)" provider WORKSHOP_LOCAL_LLM_URL: "${WORKSHOP_LOCAL_LLM_URL:-}" WORKSHOP_LOCAL_MODEL: "${WORKSHOP_LOCAL_MODEL:-}" + # Read by the dev-server skill: which ports reach the host, and the URL host to report + WORKSHOP_DEV_PORTS: "4100-4119" + WORKSHOP_DEV_HOST: "${DEV_HOST:-}" volumes: # Persistent Workshop state (SQLite db, auth-token, sessions, vault, sprites) - workshop-state:/config diff --git a/docs/docker.md b/docs/docker.md index 6bf48eec..50e76fc5 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -83,6 +83,26 @@ No `sshd`, no `docker exec`, no Docker socket mount. The "Open in Terminal" butt in the pane header is a *host*-side launcher (iTerm/Konsole/Windows Terminal) and is only useful for native, non-Docker installs. +## Dev servers + +Agents run inside the container, so a dev server they start (`npm run dev`, etc.) +is only reachable from your browser if it listens on a **published** port and on +`0.0.0.0`, not `localhost`. The compose file and unraid template publish +`4100-4119` for this (host and container ports must match) and pass it to sessions as `WORKSHOP_DEV_PORTS`. + +Install the **dev-server** skill (Settings → Skills) and ask an agent to "start a +dev server". It picks a free port in the range, binds `0.0.0.0`, runs the server in +a detached `dev-` tmux session so it outlives the agent, and reports +`http://$WORKSHOP_DEV_HOST:` — set `DEV_HOST` (compose `.env`) or the +template's **Dev server host** to the name or IP you browse to. Ask it to list or stop dev servers the same way. +On a native (non-Docker) install the variables are unset and any local port works. + +**Away from home**: the dev ports are plain host ports with no Workshop auth in +front of them. Don't port-forward them; install the Tailscale plugin on unraid and +browse to `http://:` from anywhere. Use that name as `DEV_HOST` +so reported URLs work both on the LAN and remotely. Vite (5.4.12+) rejects unknown +`Host` headers, so the skill passes it via `__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS`. + ## Per-user editor paths "Open in Editor" hands `` to your local editor. If you SSH into diff --git a/docs/unraid/workshop.xml b/docs/unraid/workshop.xml index 5f13f5b4..a2b1db72 100644 --- a/docs/unraid/workshop.xml +++ b/docs/unraid/workshop.xml @@ -29,7 +29,8 @@ Productivity: Tools: http://[IP]:[PORT:3002]/ https://raw.githubusercontent.com/devbdavis/workshop/main/public/favicon.png - --init + + --init -p 4100-4119:4100-4119 @@ -60,4 +61,12 @@ 3002 + + 4100-4119 + + diff --git a/templates/skills/dev-server/SKILL.md b/templates/skills/dev-server/SKILL.md new file mode 100644 index 00000000..cfe6eb6a --- /dev/null +++ b/templates/skills/dev-server/SKILL.md @@ -0,0 +1,31 @@ +--- +name: dev-server +description: "Start, list, or stop a long-running dev server the user can open in their browser. Use when the user asks to spawn, start, run, or serve the app 'so I can play with it', asks for a preview URL, or asks which dev servers are running or to stop one. Tagged: workshop." +--- + +# Dev Server + +Workshop often runs in Docker, where only a published port range reaches the user's browser. Follow this exactly so the URL you report actually works. + +## Start + +1. Pick a port. If `$WORKSHOP_DEV_PORTS` is set (e.g. `4100-4119`), use the first port in that range with nothing listening — `(exec 3<>/dev/tcp/127.0.0.1/) 2>/dev/null` succeeds when the port is taken. If unset, any free port works. +2. Choose a name: `dev-` (append the branch if several of the same repo run). Letters, digits and `-` only. Kill an existing session of that exact name first: `tmux kill-session -t =dev- 2>/dev/null`. +3. Start it detached so it survives this agent session, bound to all interfaces, logging to a file: + + ```bash + tmux new-session -d -s dev- -c \ + "${WORKSHOP_DEV_HOST:+__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=$WORKSHOP_DEV_HOST } 2>&1 | tee /tmp/dev-.log" + ``` + + Use the project's own dev script and pass port and host its way, e.g. `npm run dev -- --host 0.0.0.0 --port ` (Vite), `next dev -H 0.0.0.0 -p `, `python -m http.server --bind 0.0.0.0`. A `localhost`/`127.0.0.1` bind is unreachable from outside the container. A second backend port also comes from the range. +4. Wait until it answers (`curl -s -o /dev/null http://127.0.0.1:` in a retry loop, ~30s max; if the port is taken by another start, use the next one). On failure, read `tail -50 /tmp/dev-.log` and fix the cause. +5. Report `http://:` and the session name, where `` is `$WORKSHOP_DEV_HOST`. If that is unset but `$WORKSHOP_DEV_PORTS` is set, use "the Workshop host's name or IP" and tell the user to set `DEV_HOST` so future URLs are exact. Native install (neither set): `localhost`. + +## List + +`tmux list-panes -a -F '#{session_name} #{pane_start_command}' | grep '^dev-'` — the start command shows the port. + +## Stop + +`tmux kill-session -t =dev-`. Stop only the servers the user names; "stop all" means every `dev-*` session.