feat: functionality to open a sandbox workspace in vs code

This commit is contained in:
2026-10-22 18:59:15 +02:00
parent 230927d8db
commit 1ac5193b0e
12 changed files with 426 additions and 18 deletions
+12 -6
View File
@@ -1,8 +1,10 @@
// `wsbx exec` server: host -> vfkit unix socket -> vsock -> here.
//
// Protocol: the host sends one JSON request line, then frames go both ways: kind byte, u32 BE length, payload.
// host -> guest: 'd' stdin data, 'e' stdin EOF, 'w' window size (rows, cols: u16 BE)
// guest -> host: 'o' stdout, 'r' stderr, 'k' keepalive (ignored), 'x' exit status (u32 BE), always last
//
// host -> guest: 'd' stdin data, 'e' stdin EOF, 'w' window size (rows, cols: u16 BE)
// guest -> host: 'o' stdout, 'r' stderr, 'k' keepalive (ignored), 'x' exit status (u32 BE), always last
//
// With Tty the command gets a pty (stdout carries everything); otherwise plain pipes.
// With Connect (`wsbx forward`) there's no command: 'd'/'e' go to the guest's localhost:Connect, its output
// comes back as 'o', and 'x' marks its EOF (status 0) or a failed dial (1, after an 'r' message).
@@ -174,11 +176,15 @@ func session(c *os.File) {
case <-output:
case <-time.After(500 * time.Millisecond): // a background job still holds the pty
}
code := uint32(cmd.ProcessState.ExitCode())
if ws, ok := cmd.ProcessState.Sys().(syscall.WaitStatus); ok && ws.Signaled() {
code = 128 + uint32(ws.Signal())
send('x', binary.BigEndian.AppendUint32(nil, exitCode(cmd.ProcessState)))
}
// exitCode like a shell's $?: 128+N for a signal.
func exitCode(ps *os.ProcessState) uint32 {
if ws, ok := ps.Sys().(syscall.WaitStatus); ok && ws.Signaled() {
return 128 + uint32(ws.Signal())
}
send('x', binary.BigEndian.AppendUint32(nil, code))
return uint32(ps.ExitCode())
}
// forward pipes a session to the guest's localhost:port until both sides sent EOF or the host is gone.