sharedwire

package
v0.2.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sharedwire is the relay side of the shared runner: how a session a client started reaches the one runner that serves every session on this machine, and how the session's messages pass between them.

It uses only the standard library, so the relay built from it (./relay) stays a few megabytes: a client keeps one relay per session for as long as the session is open, and some clients keep dozens.

Index

Constants

This section is empty.

Variables

View Source
var Dir = func() (string, error) {
	base, err := os.UserCacheDir()
	if err != nil {
		return "", err
	}
	return filepath.Join(base, "tap-runtime", "shared"), nil
}

Dir is where the runner keeps its socket, lock and log: private to this user. A variable so a test can move it.

View Source
var ErrNoShared = errors.New("no shared runner")

ErrNoShared is returned, wrapped, when no runner can be reached.

View Source
var Logf = func(format string, a ...any) { fmt.Fprintf(os.Stderr, "tap  "+format+"\n", a...) }

Logf writes a line of the relay's own log, to standard error.

Functions

func Detach

func Detach(cmd *exec.Cmd)

Detach starts cmd in a session of its own, so it outlives the agent session that started it and no signal to that session reaches it.

func Dial

func Dial(p Paths, runner string) (net.Conn, error)

Dial reaches the runner, starting runner (the tap program) as one when none answers.

func LockFile

func LockFile(f *os.File) error

LockFile waits for an exclusive lock on f. The lock is released when f is closed or the process ends, so a crashed holder never keeps it.

func Relay

func Relay(in io.Reader, out io.Writer, p Paths, runner string, h Hello) error

Relay passes one client session, read from in and answered on out, to the runner. It returns ErrNoShared, wrapped and having read nothing from in, when no runner can be reached.

func SendHello

func SendHello(c net.Conn, r *bufio.Reader, h Hello) error

SendHello opens a session on the runner.

func StartRunner

func StartRunner(p Paths, runner string) error

StartRunner starts runner shared-runner, detached from this session. Several relays may start one at once; all but the first find the runner's lock taken and stop.

func TryLockFile

func TryLockFile(f *os.File) error

TryLockFile takes an exclusive lock on f, or fails at once if another process holds it.

Types

type Answer

type Answer struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

Answer is the runner's reply to a Hello.

type Hello

type Hello struct {
	Key  string   `json:"key"`
	Dir  string   `json:"dir"`
	Env  []string `json:"env"`
	Args []string `json:"args"`
	// Parent is the process that started the session (the agent, or a
	// wrapper it ran): what an agent was started with, such as Gemini CLI's
	// yolo mode, is read from its command line.
	Parent int `json:"parent,omitempty"`
}

Hello is the first line a relay sends: who the session is.

type Paths

type Paths struct{ Dir, Sock, Lock, Log string }

Paths are the files of the runner for one key.

func PathsFor

func PathsFor(key string) (Paths, error)

PathsFor names the runner's files for key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL