daemon

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
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

func GenerateToken() (string, error)

GenerateToken returns a cryptographically random 32-byte hex string.

func GetHookSnapshot added in v0.15.0

func GetHookSnapshot(addr, token string) (map[string]hookevents.SessionSnapshot, error)

GetHookSnapshot fetches the current per-session hook state from the daemon.

func GetLogMode added in v0.15.0

func GetLogMode(addr, token string) (string, error)

GetLogMode fetches the current traffic log mode from the daemon.

func GetTrackerDiagnose added in v0.15.0

func GetTrackerDiagnose(addr, token string) ([]tracker.TrackerStatus, error)

GetTrackerDiagnose fetches tracker credential status from the daemon.

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

func LoadOrCreateToken() (string, error)

LoadOrCreateToken reads the token from disk, or generates and persists a new one.

func ParseHookEventArgs added in v0.15.0

func ParseHookEventArgs(args []string) hookevents.Event

ParseHookEventArgs converts daemon request args into a hook event. Expected args: [event, session_id, cwd, notification_type, tool_name, error_type].

func ReadConnected added in v0.14.0

func ReadConnected(path string) []int

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

func RunRemote(addr, token string, args []string, version string) (int, error)

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 RunRemoteCapture added in v0.15.0

func RunRemoteCapture(addr, token string, args []string) ([]byte, error)

RunRemoteCapture connects to the daemon and runs args, returning stdout as bytes instead of printing to os.Stdout.

func SetLogMode added in v0.15.0

func SetLogMode(addr, token, mode string) (string, error)

SetLogMode sets the traffic log mode on the daemon. Returns the new mode.

func TokenPath

func TokenPath() string

TokenPath returns the default path for the daemon token file.

func WriteConnected added in v0.14.0

func WriteConnected(path string, pids []int) error

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

type BrowserOpener interface {
	Open(url string) error
}

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 HookEventStore added in v0.15.0

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

HookEventStore is a thread-safe ring buffer of recent hook events. It stores raw events and can derive per-session snapshots on demand. Subscribers are notified (non-blocking) whenever a new event is appended.

func NewHookEventStore added in v0.15.0

func NewHookEventStore() *HookEventStore

NewHookEventStore creates an empty store.

func (*HookEventStore) Append added in v0.15.0

func (s *HookEventStore) Append(evt hookevents.Event)

Append adds a hook event. If the buffer exceeds maxHookEvents, the oldest event is dropped. All subscribers are notified.

func (*HookEventStore) Snapshot added in v0.15.0

func (s *HookEventStore) Snapshot() map[string]hookevents.SessionSnapshot

Snapshot returns the current per-session state derived from all stored events.

func (*HookEventStore) Subscribe added in v0.15.0

func (s *HookEventStore) Subscribe() chan struct{}

Subscribe returns a channel that receives a signal whenever a new event is appended. The channel has a buffer of 1 so a single pending notification is coalesced. Call Unsubscribe to clean up.

func (*HookEventStore) Unsubscribe added in v0.15.0

func (s *HookEventStore) Unsubscribe(ch chan struct{})

Unsubscribe removes a previously registered channel and closes it.

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
	HookEvents    *HookEventStore                       // in-memory hook event buffer; nil disables hook event tracking
	IssueFetcher  func() ([]TrackerIssuesResult, error) // injected; fetches issues from configured trackers
	// contains filtered or unexported fields
}

Server listens for incoming client connections and executes CLI commands.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

ListenAndServe starts the TCP listener and blocks until ctx is cancelled.

type TrackerIssuesResult added in v0.15.0

type TrackerIssuesResult struct {
	TrackerName string          `json:"tracker_name"`
	TrackerKind string          `json:"tracker_kind"`
	Project     string          `json:"project"`
	Issues      []tracker.Issue `json:"issues"`
	Err         string          `json:"error,omitempty"`
}

TrackerIssuesResult is the wire type for a single tracker/project's issues.

func GetTrackerIssues added in v0.15.0

func GetTrackerIssues(addr, token string) ([]TrackerIssuesResult, error)

GetTrackerIssues fetches open issues from all configured tracker projects via the daemon.

Jump to

Keyboard shortcuts

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