Documentation
¶
Index ¶
- Constants
- func ConnectedPath() string
- func GenerateToken() (string, error)
- func InfoPath() string
- func LoadOrCreateToken() (string, error)
- func ReadConnected(path string) []int
- func RemoveConnected(path string)
- func RemoveInfo()
- func RunRemote(addr, token string, args []string, version string) (int, error)
- func TokenPath() string
- func WriteConnected(path string, pids []int) error
- func WriteInfo(info DaemonInfo) error
- type BrowserOpener
- type ConnectedTracker
- type DaemonInfo
- type Request
- type Response
- type Server
Constants ¶
const ( // DefaultPort is the well-known daemon listening port. DefaultPort = 19285 // DefaultChromePort is the well-known Chrome proxy port. DefaultChromePort = 19286 // DefaultProxyPort is the well-known HTTPS proxy port. DefaultProxyPort = 19287 // DockerHost is the hostname Docker provides for reaching the host machine // from inside a container. Enabled by --add-host=host.docker.internal:host-gateway. DockerHost = "host.docker.internal" )
Variables ¶
This section is empty.
Functions ¶
func ConnectedPath ¶ added in v0.14.0
func ConnectedPath() string
ConnectedPath returns the default path for the connected PIDs file.
func GenerateToken ¶
GenerateToken returns a cryptographically random 32-byte hex string.
func InfoPath ¶ added in v0.14.0
func InfoPath() string
InfoPath returns the default path for the daemon info file (~/.human/daemon.json).
func LoadOrCreateToken ¶
LoadOrCreateToken reads the token from disk, or generates and persists a new one.
func ReadConnected ¶ added in v0.14.0
ReadConnected reads connected PIDs from path. Returns nil on any error.
func RemoveConnected ¶ added in v0.14.0
func RemoveConnected(path string)
RemoveConnected removes the connected PIDs file (best-effort).
func RemoveInfo ¶ added in v0.14.0
func RemoveInfo()
RemoveInfo removes the daemon info file (best-effort).
func RunRemote ¶
RunRemote connects to the daemon at addr, sends the CLI args, and returns the exit code. Stdout and stderr are written to os.Stdout and os.Stderr.
func TokenPath ¶
func TokenPath() string
TokenPath returns the default path for the daemon token file.
func WriteConnected ¶ added in v0.14.0
WriteConnected atomically writes the connected PIDs to path.
func WriteInfo ¶ added in v0.14.0
func WriteInfo(info DaemonInfo) error
WriteInfo writes the daemon info as JSON to InfoPath with restricted permissions.
Types ¶
type BrowserOpener ¶ added in v0.7.0
BrowserOpener opens a URL in the browser. Extracted for testability.
type ConnectedTracker ¶ added in v0.14.0
type ConnectedTracker struct {
// contains filtered or unexported fields
}
ConnectedTracker maintains a thread-safe set of recently-seen client PIDs. Each PID has a last-seen timestamp; Prune removes entries older than a TTL.
func NewConnectedTracker ¶ added in v0.14.0
func NewConnectedTracker() *ConnectedTracker
NewConnectedTracker creates an empty tracker.
func (*ConnectedTracker) PIDs ¶ added in v0.14.0
func (t *ConnectedTracker) PIDs() []int
PIDs returns a sorted snapshot of currently tracked PIDs.
func (*ConnectedTracker) Prune ¶ added in v0.14.0
func (t *ConnectedTracker) Prune(ttl time.Duration)
Prune removes PIDs not seen within ttl.
func (*ConnectedTracker) Touch ¶ added in v0.14.0
func (t *ConnectedTracker) Touch(pid int)
Touch records or refreshes a PID with the current time.
type DaemonInfo ¶ added in v0.14.0
type DaemonInfo struct {
Addr string `json:"addr"`
ChromeAddr string `json:"chrome_addr,omitempty"`
ProxyAddr string `json:"proxy_addr,omitempty"`
Token string `json:"token"`
PID int `json:"pid"`
}
DaemonInfo holds the runtime details of a running daemon instance.
func ReadInfo ¶ added in v0.14.0
func ReadInfo() (DaemonInfo, error)
ReadInfo reads and unmarshals the daemon info from InfoPath.
func (DaemonInfo) IsAlive ¶ added in v0.14.0
func (d DaemonInfo) IsAlive() bool
IsAlive checks whether the daemon process identified by PID is still running.
func (DaemonInfo) IsReachable ¶ added in v0.14.0
func (d DaemonInfo) IsReachable() bool
IsReachable checks whether the daemon is accepting TCP connections at its advertised address. This works across process namespaces (e.g. host ↔ devcontainer) where PID-based checks fail.
type Request ¶
type Request struct {
Version string `json:"version"`
Token string `json:"token"`
Args []string `json:"args"`
Env map[string]string `json:"env,omitempty"`
ClientPID int `json:"client_pid,omitempty"` // parent PID (Claude process) for connection tracking
}
Request is sent from the client to the daemon (one JSON line per connection).
type Response ¶
type Response struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
AwaitCallback bool `json:"await_callback,omitempty"`
Callback string `json:"callback,omitempty"`
}
Response is sent from the daemon back to the client (one or more JSON lines per connection).
type Server ¶
type Server struct {
Addr string
Token string
SafeMode bool
CmdFactory func() *cobra.Command
Opener BrowserOpener // used for OAuth relay; defaults to browser.DefaultOpener
Logger zerolog.Logger
ConnectedPIDs *ConnectedTracker // tracks client PIDs that have pinged; nil disables tracking
}
Server listens for incoming client connections and executes CLI commands.