agentnet

package
v0.16.355 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agentnet is what the machine agent does with the network and with the agent CLIs' environment: the env files their launches source, the proxy around them (with a local HTTP bridge for SOCKS), and the check that a provider's servers answer.

Index

Constants

View Source
const (
	ScopeAll    = agents.EnvScopeAll
	ScopeClaude = agents.Claude
	ScopeCodex  = agents.Codex
)

Scopes of an env file: every agent, or one.

View Source
const BridgeUser = "harnessly"

BridgeUser is the proxy user name the bridge expects with its token.

Variables

This section is empty.

Functions

func CheckName

func CheckName(name string) error

CheckName: a name `env.deliver` accepts (docs/hub/api.md). The rule is hubproto's, so the hub applies the same one before it relays; the error says why not.

func CheckRemove

func CheckRemove(name string) error

CheckRemove: a name `env.remove` accepts. Any well-formed name may go (a name the rules of today would refuse can only be in the file from an earlier version), except the proxy variables, which the proxy settings own.

func IsProxyName

func IsProxyName(name string) bool

IsProxyName: a variable the proxy writes, which the secrets list does not show.

func Known

func Known(provider string) bool

Known: a provider with servers to check.

func ProxyEnv

func ProxyEnv(via string) map[string]string

ProxyEnv is the variables a launch gets for the proxy address `via` (the bridge's, for a SOCKS proxy).

func Quote

func Quote(s string) string

Quote is s as one single-quoted shell word: a quote inside becomes '\”.

func ValidScope

func ValidScope(s string) bool

ValidScope is all, claude or codex.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge is a small HTTP proxy on 127.0.0.1 that sends what it is given through a SOCKS5 proxy, for CLIs that take only HTTP(S) proxies. A caller must present the bridge's token as the proxy password, so another account on the machine cannot use the person's proxy.

func StartBridge

func StartBridge(upstream ProxyURL, token string, port int) (*Bridge, error)

StartBridge listens on 127.0.0.1:port (0: any free port) for the SOCKS5 proxy upstream.

func (*Bridge) Addr

func (b *Bridge) Addr() string

Addr is "127.0.0.1:<port>".

func (*Bridge) Close

func (b *Bridge) Close()

Close stops the bridge and its connections.

func (*Bridge) Port

func (b *Bridge) Port() int

Port is the port it listens on.

func (*Bridge) ServeHTTP

func (b *Bridge) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Checker

type Checker struct {
	// Dial opens TCP connections (nil: the system's, 8 s).
	Dial dialFunc
	// LookupHost resolves a name (nil: the system's resolver).
	LookupHost func(ctx context.Context, host string) ([]string, error)
	// TLS is the client configuration (nil: the system's roots).
	TLS *tls.Config
	// Hosts and Requests replace the providers' hosts and light requests.
	Hosts    map[string][]string
	Requests map[string]string
	Now      func() time.Time
}

Checker makes provider checks. The zero value checks for real; the fields are for tests.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, provider string, proxy *ProxyURL) hubproto.ProviderCheck

Check makes the verdict on the network from this machine to a provider's servers: DNS, TCP and TLS to each host, then one light request to the API. proxy is the proxy to go through, nil for direct. No country logic and no judging of the answer beyond ok, network and rejected.

func (*Checker) CheckKey

func (c *Checker) CheckKey(ctx context.Context, provider, key string, proxy *ProxyURL) hubproto.KeyCheck

CheckKey asks the provider's models list with the key, through proxy (nil: direct): 200 and the key is accepted, 401 or 403 and it is rejected; no answer is the network's fault, and any other answer is not a verdict on the key either. The key is only ever in the request's header. An empty key is "absent" without asking.

type EnvDir

type EnvDir struct {
	Dir string
	// contains filtered or unexported fields
}

EnvDir is the agent's folder of env files, kept 0700 with 0600 files. Safe for concurrent use.

func NewEnvDir

func NewEnvDir(dir string) *EnvDir

NewEnvDir is the env files in dir.

func (*EnvDir) File

func (e *EnvDir) File(scope string) string

File is the path of a scope's file.

func (*EnvDir) Get

func (e *EnvDir) Get(scope, name string) (string, bool)

Get is a variable of a scope's file.

func (*EnvDir) Merged

func (e *EnvDir) Merged(provider string) map[string]string

Merged is the variables a launch would have from the files: the shared scope's, then the provider's over them. Only the agent's own probes use it (a key check), and the values never leave the process.

func (*EnvDir) Names

func (e *EnvDir) Names(scope string, skip func(name string) bool) []string

Names are the variables of a scope's file that skip does not hide, sorted.

func (*EnvDir) Set

func (e *EnvDir) Set(scope string, vars map[string]string) error

Set writes the variables into the scope's file, replacing ones of the same name. Names are the caller's to check (CheckName); a value may not hold a NUL.

func (*EnvDir) Unset

func (e *EnvDir) Unset(scope string, names ...string) error

Unset removes the named variables; the file goes when nothing is left.

type Proxies

type Proxies struct {
	// contains filtered or unexported fields
}

Proxies keeps the person's proxy settings in proxy.json next to the env files (0600), writes the variables into the env files the launches source, and runs the bridges of SOCKS proxies. Safe for concurrent use.

func NewProxies

func NewProxies(env *EnvDir) *Proxies

NewProxies is the proxy settings of the env files in env.

func (*Proxies) Clear

func (p *Proxies) Clear(scope string) (hubproto.ProxySummary, error)

Clear removes a scope's proxy.

func (*Proxies) Close

func (p *Proxies) Close()

Close stops the bridges (the settings stay).

func (*Proxies) Effective

func (p *Proxies) Effective(provider string) (ProxyURL, bool)

Effective is the proxy the agent of provider runs behind: its own scope's, else the shared one. False: none.

func (*Proxies) Set

func (p *Proxies) Set(scope, rawURL string) (hubproto.ProxySummary, error)

Set makes rawURL the proxy of a scope (all, claude, codex).

func (*Proxies) Start

func (p *Proxies) Start() error

Start reads proxy.json and brings the bridges back up, on their old ports when those are free. A scope whose saved address no longer reads is dropped. The env files are written again when a bridge's port changed.

func (*Proxies) Summary

func (p *Proxies) Summary() hubproto.ProxySummary

Summary is the proxies as the hub may see them.

type ProxyURL

type ProxyURL struct {
	Scheme  string // http, https, socks5
	Host    string
	Port    int
	User    string
	Pass    string
	HasAuth bool
}

ProxyURL is a proxy address the person gave: http, https or socks5 (socks5h is the same here), with a login or not.

func ParseProxy

func ParseProxy(raw string) (ProxyURL, error)

ParseProxy reads a proxy URL. The error is for the person: it says what is wrong with the address, never repeats a password.

func (ProxyURL) Entry

func (p ProxyURL) Entry(bridge string) *hubproto.ProxyEntry

Entry is the proxy as the hub may see it: no login.

func (ProxyURL) HostPort

func (p ProxyURL) HostPort() string

HostPort is "host:port", IPv6 in brackets.

func (ProxyURL) URL

func (p ProxyURL) URL() *url.URL

URL is the address with its login, for a client that takes it.

Jump to

Keyboard shortcuts

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