Dashboard › opencode › Distillation
11680f37-d0d0-4561-9649-f807ce4eaf76["lore_tm_v1_YlAwyANki9RRXwa5svUJ6cnjx8Rs_Xe-IRxuGl8OB8s","lore_tm_v1_UBS3RanGKI5H471l0HuSQDvvhEhHiIOVslqvSGGlfpQ","lore_tm_v1_N99OVqRIweLIhxadKftaH7_PjWF_Cx84QgpjcmS-bjo","lore_tm_v1_YN7cNeg3i5N_0m1wrPsjysNV-xrFvnpZc4BR93BMdqc","lore_tm_v1_eSuqX_y6HLM3zRwOmw2xvhAdOURon3gyTro7GXXPD3k","lore_tm_v1_Pxe4FkQbNj6JBEM5c8004DPJ162NBkjg6Z4uEkCX4_o"]
Date: Sep 8, 2026
/home/byk/.local/share/opencode-v2-pilot/supervisor/internal/supervisor/auth.go (108 lines). authenticate() obtains both SO_PEERCRED and SO_PEERPIDFD, validates the peer PID/UID/GID, queries manager.ClientState(ctx), and requires the peer PID to equal the service MainPID while ActiveState=="active", SubState=="running", ControlGroup==expectedClientCgroup, and InvocationID is exactly 16 bytes./home/byk/.local/share/opencode-v2-pilot/supervisor/internal/supervisor/auth.go:42-56 implements (*authenticatedPeer).Recheck: confirms pidfd liveness with unix.PidfdSendSignal(..., 0, ...), requeries and revalidates client service identity, and rejects admission if the service InvocationID changed./home/byk/.local/share/opencode-v2-pilot/supervisor/internal/supervisor/auth.go:59-107 closes the pidfd idempotently by setting it to -1; retrieves socket identity through SyscallConn.Control, unix.GetsockoptUcred(...SO_PEERCRED), and unix.GetsockoptInt(...SO_PEERPIDFD); rejects an invalid negative pidfd; and applies close-on-exec with unix.CloseOnExec(pidfd)./home/byk/.local/share/opencode-v2-pilot/supervisor/internal/protocol/frame.go (225 lines). Protocol constants are HeaderSize=12, MaxFrameSize=70 * 1024, MaxIOPayloadSize=32 * 1024, Version=1, frame types TypeStart=1, TypeInput=2, TypeOutput=3, TypeExit=4, TypeError=5, TypeStarted=6, TypeStop=7, TypeStopped=8, MaxArgs=128, MaxCommandSize=4096, MaxArgSize=16384, MaxArgsSize=65536, and MaxRuntimeSec=3600; magic bytes are OPTY./home/byk/.local/share/opencode-v2-pilot/supervisor/internal/protocol/frame.go defines START payloads in big-endian order as device uint64, inode uint64, runtime uint32, command length uint16, argument count uint16, command bytes, then repeated argument-length uint16 plus argument bytes. EncodeStart() and DecodeStart() enforce nonempty UTF-8/NUL-free commands, UTF-8/NUL-free arguments, per-field and aggregate size limits, argument-count and runtime limits, exact payload consumption, and MaxFrameSize./home/byk/.local/share/opencode-v2-pilot/supervisor/internal/protocol/frame.go:53-81,172-225 supports stream framing with ReadFrame()/WriteFrame() and packet framing with MarshalFrame()/ParsePacket(). parseHeader() requires exact 12-byte headers, magic OPTY, version 1, reserved bytes 6-7 equal zero, known frame types 1-8, and payload length no greater than 70 KiB; writeAll() returns io.ErrShortWrite on zero progress./home/byk/.local/share/opencode-v2-pilot/supervisor/cmd/launcher/main.go (145 lines). Normal launcher mode validates encoded arguments, performs syscall.Fchdir(2), replaces fd 2 with fd 1 via syscall.Dup2(1, 2), installs a fixed environment, stores dot-joined encoded argv in OPENCODE_PTY_ARGV, binds /proc/self/exe to inheritable fd 3, and execs /usr/bin/script./home/byk/.local/share/opencode-v2-pilot/supervisor/cmd/launcher/main.go uses script argv {"script", "-q", "-e", "-f", "-c", "/bin/sh -i -c 'exec /proc/self/fd/3 --exec'", "/dev/null"}. In --exec mode it decodes OPENCODE_PTY_ARGV, resets the environment, closes launcher fd 3, and directly syscall.Execs the requested command./home/byk/.local/share/opencode-v2-pilot/supervisor/cmd/launcher/main.go:88-140 requires 1 through protocol.MaxArgs+1 canonical unpadded base64url tokens prefixed by a; limits command bytes to protocol.MaxCommandSize, each argument to protocol.MaxArgSize, aggregate argument bytes to protocol.MaxArgsSize, and rejects NULs or an empty command. The fixed environment is HOME=/home/byk, LANG=C.UTF-8, LOGNAME=byk, PATH=/usr/local/bin:/usr/bin:/bin, SHELL=/bin/sh, TERM=xterm-256color, and USER=byk./home/byk/.local/share/opencode-v2-pilot/supervisor/cmd/client/main.go (107 lines). The helper expects inherited connected socket fd 3 and cwd fd 4, marks both close-on-exec, verifies fd 3 has a peer and fd 4 is a directory, derives cwd device/inode with unix.Fstat, decodes runtime plus command/arguments, encodes a TypeStart frame, and sends the frame with exactly the cwd descriptor via unix.SendmsgN(..., unix.UnixRights(cwd), ..., unix.MSG_NOSIGNAL), finishing any partial packet with unix.Write./home/byk/.local/share/opencode-v2-pilot/supervisor/cmd/client/main.go:71-107 requires 2 through protocol.MaxArgs+2 metadata values, parses runtime as base-10 uint32 no greater than protocol.MaxRuntimeSec, and applies the same a-prefixed canonical raw-base64url grammar, command/argument size limits, NUL rejection, and aggregate argument limit as the launcher before constructing protocol.Start{Device, Inode, RuntimeSec, Command, Args}./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts (319 lines). Transport constants mirror the Go protocol: MAGIC="OPTY", VERSION=1, HEADER_SIZE=12, MAX_FRAME_SIZE=70 * 1024, MAX_IO_PAYLOAD_SIZE=32 * 1024, and frame types input 2 through stopped 8. Runtime defaults are socket /run/opencode-pty/supervisor.sock, helper /usr/local/libexec/opencode-pty-client, helper timeout 5,000 ms, stop timeout 25,000 ms, helper stderr cap 2,000 bytes, pending-output cap MAX_BUFFER_SIZE=1_000_000, and unit-name regex /^opencode-pty-[0-9a-f]{32}\.service$/./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts:53-62 makes assertSupervisorAvailable() verify the helper is a root-owned regular executable with no group/world write bits unless verifyRootHelper===false, then connects to the Unix socket and verifies Node exposes a valid connected socket descriptor./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts:64-198 opens a supervisor connection, spawns the helper with runtime plus a${Buffer.from(...).toString("base64url")} command/arguments, and passes stdio ["pipe", "pipe", "pipe", connectedSocketFD(socket), binding.fd]. It waits for helper success and a valid TYPE_STARTED acknowledgement under the helper timeout, destroying the socket on failure./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts:98-171 incrementally parses supervisor frames, validates magic/version/reserved bytes and the 70-KiB frame limit, requires nonempty output frames no larger than 32 KiB, buffers pre-listener output while trimming oldest bytes to 1,000,000 total, validates started/error/result strings as UTF-8, and rejects duplicate/empty/invalid unit names or unexpected frame types./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts decodes TYPE_EXIT as one-byte execMainCode, four-byte big-endian execMainStatus, four-byte big-endian result length, and UTF-8 result. A valid TYPE_STOPPED is accepted only after local stopping began and resolves as {execMainCode: 2, execMainStatus: 15, result: "stopped"}; an unstructured socket close rejects with PTY supervisor connection closed before a structured exit./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts:199-232 returns a SupervisorTransport whose write() splits input into chunks no larger than 32 KiB and applies the helper timeout to each socket write; close() sends one empty TYPE_STOP if still active, waits for structured exit and socket closure, and enforces the configurable stop timeout (default 25,000 ms)./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts:235-319 obtains the connected socket fd through Nodeβs private socket._handle.fd, verifies it is a nonnegative integer referencing a socket via fstatSync(fd).isSocket(), uses a five-second Unix-connect timeout, writes 12-byte big-endian protocol headers, kills timed-out helpers with SIGKILL, captures helper stderr only while total received size remains at or below 2,000 bytes, and reports helper signals or nonzero exit codes.ptySlice = "opencode-pty.slice" and perSessionMemoryHigh = 384 * 1024 * 1024; its transient-unit properties visibly include Group="byk", OOMPolicy="kill", ProtectControlGroups=true, SystemCallArchitectures=[]string{"native"}, and RuntimeMaxUSec=uint64(runtime)*uint64(time.Second/time.Microsecond).