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
- func CheckName(name string) error
- func CheckRemove(name string) error
- func IsProxyName(name string) bool
- func Known(provider string) bool
- func ProxyEnv(via string) map[string]string
- func Quote(s string) string
- func ValidScope(s string) bool
- type Bridge
- type Checker
- type EnvDir
- func (e *EnvDir) File(scope string) string
- func (e *EnvDir) Get(scope, name string) (string, bool)
- func (e *EnvDir) Merged(provider string) map[string]string
- func (e *EnvDir) Names(scope string, skip func(name string) bool) []string
- func (e *EnvDir) Set(scope string, vars map[string]string) error
- func (e *EnvDir) Unset(scope string, names ...string) error
- type Proxies
- func (p *Proxies) Clear(scope string) (hubproto.ProxySummary, error)
- func (p *Proxies) Close()
- func (p *Proxies) Effective(provider string) (ProxyURL, bool)
- func (p *Proxies) Set(scope, rawURL string) (hubproto.ProxySummary, error)
- func (p *Proxies) Start() error
- func (p *Proxies) Summary() hubproto.ProxySummary
- type ProxyURL
Constants ¶
const ( ScopeAll = agents.EnvScopeAll ScopeClaude = agents.Claude ScopeCodex = agents.Codex )
Scopes of an env file: every agent, or one.
const BridgeUser = "harnessly"
BridgeUser is the proxy user name the bridge expects with its token.
Variables ¶
This section is empty.
Functions ¶
func CheckName ¶
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 ¶
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 ¶
IsProxyName: a variable the proxy writes, which the secrets list does not show.
func ProxyEnv ¶
ProxyEnv is the variables a launch gets for the proxy address `via` (the bridge's, for a SOCKS proxy).
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 ¶
StartBridge listens on 127.0.0.1:port (0: any free port) for the SOCKS5 proxy upstream.
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 (*EnvDir) Merged ¶
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.
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 ¶
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) Effective ¶
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 ¶
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 ¶
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.