Documentation
¶
Index ¶
- Variables
- func CleanupSession(session *Session)
- func DefaultCredentialsPath() string
- func DefaultRegistryDir() string
- func DefaultRegistryPath() string
- func DefaultSessionsDir() string
- func EnsureValidToken(serverURL string) (string, error)
- func IsSessionActive(s *Session) bool
- func LoadRuntimeCwd(executorID string) string
- func RunClaudeCode(opts ClaudeCodeOptions)
- func RunExecutor(ctx context.Context, opts ExecutorOpts) error
- func RunLogin(opts LoginOptions) error
- func RunTUI(ctx context.Context, opts TUIOpts) error
- func RunTaskWorker(ctx context.Context, opts TaskWorkerOptions)
- func SaveCredentials(path string, creds *Credentials) error
- func SaveRegistry(path string, reg *Registry) error
- func SaveSession(session *Session) error
- func SetRuntimeCwd(executorID, cwd string) error
- type AgentCapabilities
- type AgentInfoData
- type ClaudeCodeOptions
- type Client
- type Credentials
- type DeviceAuthResponse
- type ExecutorClient
- type ExecutorOpts
- type ExecutorSession
- type GPUInfo
- type LockedRegistryFile
- type LoginOptions
- type RegisterResponse
- type Registry
- type RegistryEntry
- type RuntimeInfo
- type Session
- type TUIOpts
- type TaskWorker
- type TaskWorkerOptions
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
var ErrNeedReLogin = errors.New("all tokens expired, please run 'agentserver' to re-authenticate")
ErrNeedReLogin indicates all tokens have expired and interactive re-auth is needed.
var RunTUIFunc func(ctx context.Context, opts TUIOpts) error
RunTUI is the entry point for the `tui` subcommand. The actual wiring lives in cmd/agentserver-agent/tui_run.go to avoid the import cycle that would arise if this package imported internal/agent/tui (which already imports internal/agent).
cmd/agentserver-agent sets RunTUIFunc at init() time.
var Version = "dev"
Version is set at build time via -ldflags.
Functions ¶
func CleanupSession ¶ added in v0.35.0
func CleanupSession(session *Session)
CleanupSession clears the PID from the session file.
func DefaultCredentialsPath ¶ added in v0.33.0
func DefaultCredentialsPath() string
DefaultCredentialsPath returns ~/.agentserver/.credentials.json.
func DefaultRegistryDir ¶ added in v0.20.0
func DefaultRegistryDir() string
DefaultRegistryDir returns the default directory for agentserver config.
func DefaultRegistryPath ¶ added in v0.20.0
func DefaultRegistryPath() string
DefaultRegistryPath returns the default path for the registry file.
func DefaultSessionsDir ¶ added in v0.35.0
func DefaultSessionsDir() string
DefaultSessionsDir returns ~/.agentserver/sessions.
func EnsureValidToken ¶ added in v0.35.0
EnsureValidToken checks for a valid OAuth access token, refreshing if needed. Returns the access token or ErrNeedReLogin if interactive auth is required.
func IsSessionActive ¶ added in v0.35.0
IsSessionActive checks if a session's process is still running.
func LoadRuntimeCwd ¶ added in v0.48.0
LoadRuntimeCwd reads only the runtime_cwd field. Returns "" if file missing or field absent.
func RunClaudeCode ¶ added in v0.27.0
func RunClaudeCode(opts ClaudeCodeOptions)
RunClaudeCode executes the headless Claude Code agent. It registers a sandbox, connects a tunnel for heartbeat, and runs a task worker that executes delegated tasks via the CCR v2 bridge API.
func RunExecutor ¶ added in v0.40.0
func RunExecutor(ctx context.Context, opts ExecutorOpts) error
RunExecutor registers with executor-registry (or reuses a saved session) and runs the tunnel + heartbeat loop, serving tool execution requests over a yamux tunnel.
func RunLogin ¶ added in v0.33.0
func RunLogin(opts LoginOptions) error
RunLogin executes the OAuth Device Flow login and agent registration.
func RunTUI ¶ added in v0.48.0
RunTUI delegates to RunTUIFunc, which is wired by the binary's init().
func RunTaskWorker ¶ added in v0.30.0
func RunTaskWorker(ctx context.Context, opts TaskWorkerOptions)
RunTaskWorker starts the task worker that polls for tasks. Blocks until ctx is cancelled.
func SaveCredentials ¶ added in v0.33.0
func SaveCredentials(path string, creds *Credentials) error
SaveCredentials writes credentials to disk with 0600 permissions.
func SaveRegistry ¶ added in v0.20.0
SaveRegistry writes the registry to disk.
func SaveSession ¶ added in v0.35.0
SaveSession writes a session file and records the current PID.
func SetRuntimeCwd ¶ added in v0.48.0
SetRuntimeCwd reads the saved session JSON, updates the RuntimeCwd field, and writes it back atomically. Other fields are preserved.
Types ¶
type AgentCapabilities ¶ added in v0.37.0
type AgentCapabilities struct {
Languages []RuntimeInfo `json:"languages,omitempty"`
Tools []RuntimeInfo `json:"tools,omitempty"`
GPU *GPUInfo `json:"gpu,omitempty"`
ProbedAt time.Time `json:"probed_at"`
}
AgentCapabilities describes what runtimes, tools, and hardware are available in the agent's environment.
func ProbeCapabilities ¶ added in v0.37.0
func ProbeCapabilities(ctx context.Context) *AgentCapabilities
ProbeCapabilities detects installed languages, tools, and GPU hardware concurrently. It always returns a non-nil result even if the context is cancelled.
type AgentInfoData ¶ added in v0.16.0
type AgentInfoData struct {
Hostname string `json:"hostname"`
OS string `json:"os"`
Platform string `json:"platform"`
PlatformVersion string `json:"platform_version"`
KernelArch string `json:"kernel_arch"`
CPUModelName string `json:"cpu_model_name"`
CPUCountLogical int `json:"cpu_count_logical"`
MemoryTotal uint64 `json:"memory_total"`
DiskTotal uint64 `json:"disk_total"`
DiskFree uint64 `json:"disk_free"`
AgentVersion string `json:"agent_version"`
OpencodeVersion string `json:"opencode_version"`
Workdir string `json:"workdir"`
HostInfo *host.InfoStat `json:"host_info,omitempty"`
CPUInfo *cpuInfoDetail `json:"cpu_info,omitempty"`
MemoryInfo *mem.VirtualMemoryStat `json:"memory_info,omitempty"`
DiskInfo *disk.UsageStat `json:"disk_info,omitempty"`
Capabilities *AgentCapabilities `json:"capabilities,omitempty"`
}
AgentInfoData is the system info payload sent from agent to server.
type ClaudeCodeOptions ¶ added in v0.27.0
type ClaudeCodeOptions struct {
Server string
Name string
SkipOpenBrowser bool
ClaudeBin string
WorkDir string
Resume string // sandbox ID to resume
Continue bool // resume most recent session
}
ClaudeCodeOptions holds all flags for the claudecode command.
type Client ¶
type Client struct {
ServerURL string
SandboxID string
TunnelToken string
Workdir string
BackendType string // "claudecode"
// contains filtered or unexported fields
}
Client is the agent tunnel client that connects to the server and maintains a persistent connection for heartbeat and control.
type Credentials ¶ added in v0.33.0
type Credentials struct {
ServerURL string `json:"serverUrl,omitempty"`
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
ExpiresAt time.Time `json:"expiresAt"`
Scopes []string `json:"scopes,omitempty"`
}
Credentials holds OAuth tokens for the authenticated user.
func LoadCredentials ¶ added in v0.33.0
func LoadCredentials(path string) (*Credentials, error)
LoadCredentials reads credentials from disk. Returns nil if the file does not exist.
type DeviceAuthResponse ¶ added in v0.33.0
type DeviceAuthResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceAuthResponse is the response from Hydra's device authorization endpoint.
func RequestDeviceCode ¶ added in v0.48.0
func RequestDeviceCode(serverURL string) (*DeviceAuthResponse, error)
RequestDeviceCode POSTs to /api/oauth2/device/auth and returns the device authorization response. Exported so the TUI AuthController can use it as a seam (injectable for tests).
type ExecutorClient ¶ added in v0.40.0
type ExecutorClient struct {
// contains filtered or unexported fields
}
ExecutorClient runs a tunnel to executor-registry and serves tool execution requests from cc-broker workers.
func NewExecutorClient ¶ added in v0.40.0
func NewExecutorClient(sess *ExecutorSession, workDir string) *ExecutorClient
NewExecutorClient constructs a new executor client bound to the given registry session and working directory.
func (*ExecutorClient) Run ¶ added in v0.40.0
func (c *ExecutorClient) Run(ctx context.Context) error
Run maintains a persistent tunnel to executor-registry and reconnects with exponential backoff on disconnection. If the registry reports the session as stale (unauthorized / not found) the saved credentials are discarded and a new executor is registered before reconnecting.
type ExecutorOpts ¶ added in v0.40.0
type ExecutorOpts struct {
ServerURL string
Name string
WorkspaceID string
SkipOpenBrowser bool
WorkDir string
}
ExecutorOpts holds configuration for the `executor` subcommand.
type ExecutorSession ¶ added in v0.40.0
type ExecutorSession struct {
ExecutorID string `json:"executor_id"`
Name string `json:"name"`
WorkspaceID string `json:"workspace_id"`
TunnelToken string `json:"tunnel_token"`
RegistryToken string `json:"registry_token"`
ServerURL string `json:"server_url"`
CreatedAt time.Time `json:"created_at"`
RuntimeCwd string `json:"runtime_cwd,omitempty"` // TUI may set via /cd
}
ExecutorSession holds the credentials for a registered executor. Persisted at ~/.agentserver/executors/{executor_id}.json so the local machine can reconnect to executor-registry across restarts.
func LoadOrRegisterExecutor ¶ added in v0.40.0
func LoadOrRegisterExecutor(opts ExecutorOpts) (*ExecutorSession, error)
LoadOrRegisterExecutor reuses a saved session for the given serverURL + workspaceID if one exists, otherwise registers a new executor with the registry and persists the result. Read errors other than "sessions dir doesn't exist" are surfaced to the caller rather than silently triggering a re-registration.
func LoadSessionByID ¶ added in v0.48.0
func LoadSessionByID(executorID string) (*ExecutorSession, error)
LoadSessionByID loads a saved ExecutorSession by id. Returns nil if absent.
type LockedRegistryFile ¶ added in v0.20.0
type LockedRegistryFile struct {
Path string
Reg *Registry
// contains filtered or unexported fields
}
LockedRegistryFile holds an exclusive lock on the registry for safe read-modify-write operations. Call Close() when done.
func LockRegistry ¶ added in v0.20.0
func LockRegistry(path string) (*LockedRegistryFile, error)
LockRegistry acquires an exclusive file lock and loads the registry. The caller must call Close() when done to release the lock and optionally save changes via Save() before Close().
func (*LockedRegistryFile) Close ¶ added in v0.20.0
func (l *LockedRegistryFile) Close()
Close releases the file lock.
func (*LockedRegistryFile) Save ¶ added in v0.20.0
func (l *LockedRegistryFile) Save() error
Save writes the registry to disk while the lock is held.
type LoginOptions ¶ added in v0.33.0
LoginOptions holds flags for the login command.
type RegisterResponse ¶ added in v0.33.0
type RegisterResponse struct {
SandboxID string `json:"sandbox_id"`
TunnelToken string `json:"tunnel_token"`
ProxyToken string `json:"proxy_token"`
WorkspaceID string `json:"workspace_id"`
ShortID string `json:"short_id"`
}
RegisterResponse is the response from the agent registration endpoint.
type Registry ¶ added in v0.20.0
type Registry struct {
Entries []*RegistryEntry `json:"entries"`
}
Registry holds all agent registrations on this machine.
func LoadRegistry ¶ added in v0.20.0
LoadRegistry reads the registry from disk. Returns an empty registry if the file does not exist.
func (*Registry) Find ¶ added in v0.20.0
func (r *Registry) Find(dir, workspaceID string) *RegistryEntry
Find returns the entry matching (dir, workspaceID), or nil if not found.
func (*Registry) FindByDir ¶ added in v0.20.0
func (r *Registry) FindByDir(dir string) []*RegistryEntry
FindByDir returns all entries for the given directory.
func (*Registry) Put ¶ added in v0.20.0
func (r *Registry) Put(entry *RegistryEntry)
Put adds or replaces an entry keyed by (Dir, WorkspaceID).
type RegistryEntry ¶ added in v0.20.0
type RegistryEntry struct {
Dir string `json:"dir"`
Server string `json:"server"`
SandboxID string `json:"sandbox_id"`
TunnelToken string `json:"tunnel_token"`
WorkspaceID string `json:"workspace_id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
}
RegistryEntry represents a single agent registration keyed by (Dir, WorkspaceID).
type RuntimeInfo ¶ added in v0.37.0
type RuntimeInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Path string `json:"path,omitempty"`
}
RuntimeInfo describes a single detected runtime or tool.
type Session ¶ added in v0.35.0
type Session struct {
SandboxID string `json:"sandboxId"`
TunnelToken string `json:"tunnelToken"`
ProxyToken string `json:"proxyToken"`
WorkspaceID string `json:"workspaceId"`
Name string `json:"name"`
Type string `json:"type"` // "opencode" or "claudecode"
ServerURL string `json:"serverUrl"`
Dir string `json:"dir"`
CreatedAt time.Time `json:"createdAt"`
PID int `json:"pid,omitempty"`
}
Session represents a sandbox session created by a single agent process. Stored in ~/.agentserver/sessions/{sandbox-id}.json.
func FindLatestSession ¶ added in v0.35.0
FindLatestSession finds the most recent inactive session for the given directory and type. If dir is empty, matches any directory. If sessionType is empty, matches any type.
func ListSessions ¶ added in v0.35.0
ListSessions reads all session files.
func LoadSession ¶ added in v0.35.0
LoadSession reads a session by sandbox ID.
type TaskWorker ¶ added in v0.30.0
type TaskWorker struct {
// contains filtered or unexported fields
}
TaskWorker receives and executes delegated tasks using the Go Agent SDK.
func NewTaskWorker ¶ added in v0.30.0
func NewTaskWorker(opts TaskWorkerOptions) *TaskWorker
func (*TaskWorker) ExecuteTask ¶ added in v0.30.0
func (w *TaskWorker) ExecuteTask(ctx context.Context, taskID, sessionID, prompt, systemContext string, maxTurns int, maxBudgetUSD float64) (*agentsdk.ResultMessage, error)
ExecuteTask runs a single task: connects bridge, executes via Agent SDK.
type TaskWorkerOptions ¶ added in v0.30.0
type TaskWorkerOptions struct {
ServerURL string // agentserver base URL (e.g. https://agentserver.example.com)
ProxyToken string // sandbox proxy_token for auth
SandboxID string // this agent's sandbox ID
Workdir string // working directory for claude CLI
CLIPath string // path to claude binary (default: "claude")
}
TaskWorkerOptions configures the task worker.
type TokenResponse ¶ added in v0.33.0
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
}
TokenResponse is the response from the token endpoint.
func PollForToken ¶ added in v0.48.0
func PollForToken(serverURL string, deviceResp *DeviceAuthResponse) (*TokenResponse, error)
PollForToken polls the token endpoint until the user authenticates, denies, or the device code expires. Exported so the TUI AuthController can use it as a seam (injectable for tests).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package executortools implements the tool set served by the local executor over the executor-registry tunnel.
|
Package executortools implements the tool set served by the local executor over the executor-registry tunnel. |
|
internal/agent/tui/attach_picker.go
|
internal/agent/tui/attach_picker.go |