Skip to content

✨ Add the port group and serve current --share - #29

Merged
bdsoha merged 7 commits into
mainfrom
feature/public-ports
Nov 18, 2026
Merged

bdsoha merged 7 commits into
mainfrom
feature/public-ports

Conversation

@bdsoha

@bdsoha bdsoha commented Nov 18, 2026

Copy link
Copy Markdown
Member

Description

Public ports, the ws-cli half of story 6.24. ws-server keeps the list of public ports in memory. A shared port answers on <port>.<proxy-domain> without the workspace sign-in. ws-cli holds a share for as long as it runs.

  • ws-cli port share <port> runs in the foreground. It holds the share open on ws-server's session socket (POST /ports/share, a stream of newline-delimited JSON events) and prints the public URLs. Ctrl+C, a kill, or port unshare from any terminal ends the share. When someone else ends it, the holder prints who did and exits 0.
  • ws-cli port unshare <port> ends any share, including one held by another terminal or by the editor's Ports view.
  • ws-cli port list reads the listening ports from /proc/net/tcp{,6}. For each port it shows whether it is public or private, its URLs, and its state in the Ports tab. It is the only MCP tool in the group (port_list, read).
  • ws-cli port clear closes the forwarded ports in the Ports tab whose process has exited. It uses the new portClear pipe verb.
  • ws-cli serve current --share serves the folder and shares its port in one process. While shared, it answers 404 for dotfiles and dot-segments, for symlinks that leave the root, and for a folder without an index.html, so no directory is ever listed. It stops serving when the share ends.
  • net.SessionCall and SessionStream call ws-server's session socket. The stream has no 3 s timeout. An old ws-server's 404 {"error":"not found"} reads as "needs a newer workspace image".
  • New commands are since: next. commands.yaml is regenerated.

Related: kloudkit/ws-server feature/public-ports (the socket routes, the gate, and the portList/portClear verbs), and kloudkit/workspace feature/public-ports (WS_SERVER_PROXY_ALLOW_PUBLIC).

What type of PR is this? (check all that apply)

  • 🐛 Bug Fix
  • ✨ New Feature
  • 🧼 Refactor (non-breaking change)
  • 📄 Help Text or CLI Docs Update
  • 🧪 Test Update or Coverage Improvement
  • 🎨 Style (formatting, naming, etc.)
  • 🏗 Build or Dependency
  • 🔄 Revert

How to test this PR

  1. go vet ./... and go test ./... pass. Unit tests cover:
    • the /proc/net parser;
    • share, release and unshare-elsewhere;
    • each refusal: switch off, no proxy domain, ws-server's own port;
    • the old-image 404;
    • the confined file server;
    • serve current --share ending when the share ends.
  2. End to end needs the ws-server branch. Run it with WS_SERVER_PROXY_ALLOW_PUBLIC=true, WS_SERVER_PROXY_DOMAIN and a password, then:
    • Run ws-cli port share 8000. 8000.<domain> loads anonymously, and /proxy/8000/ still redirects to login.
    • ws-cli port list shows 8000 as public with its URL.
    • ws-cli port unshare 8000 from another terminal makes the holder print who ended the share and exit. The host redirects to login again.
  3. Without the ws-server branch, every port command except clear reports that it needs a newer workspace image.

Screenshots or Output (if applicable)

Not attached. Step 2 ran against a local ws-server built from its branch with an editor stub. It has not run in a workspace image yet.

bdsoha and others added 7 commits November 18, 2026 13:46
port share holds a public share on ws-server's session socket while it
runs and prints the URLs; Ctrl+C, a kill or port unshare from any
terminal ends it. port list reads the listeners from /proc/net/tcp{,6}
with each port's visibility, URLs and Ports-tab state, and is the only
MCP tool (port_list). port clear closes the editor's unused ports. An
old ws-server's 404 reads as needing a newer workspace image.
Serves the folder and shares its port in one process. While shared the
site answers 404 for dotfiles, for links leaving the folder and for a
folder without an index.html, and it stops when the share ends.
- The session socket client shares the editor client's error mapping
  (`peer.requestError`, `errorMessage`) instead of its own copies.
- `cli.SignalContext` replaces the two signal contexts in `port share`
  and `serve mcp`.
- `port.Hold` reads the event stream in a plain loop and stops by
  closing the body when its context ends. One `Event` type replaces
  `Shared`, `Ended` and `event`.
- `serve current --share` serves until its share ends, with no hand-off
  between goroutines.
- `server.Confined` serves through `os.Root`, which refuses symlinks
  that leave the folder, as well as absolute ones.
- `cobra.ExactArgs` replaces the custom argument check, and the unused
  Ports-tab fields are gone.
- Tests use `testutil.ServeSession`, and cases already covered in the
  other package are dropped.
Moves the seven imports from v3 to v4; v3 stays only as an indirect dependency. commands.yaml and the golden outputs come out unchanged.
Hold reports any end before the shared event as an error and any end
after it as the workspace server ending the share. port list shows the
listeners with visibility unknown when ws-server cannot answer, and lists
forwarded Ports-tab entries that stopped listening.
@bdsoha
bdsoha merged commit 290e754 into main Nov 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant