Documentation
¶
Overview ¶
Package daemon serves local Glue sessions over the ADR-0010 HTTP+SSE protocol.
Index ¶
- func DefaultMetadataPath() string
- func RandomToken() (string, error)
- func ResolveToken(flagValue string) (token, source string, err error)
- func ServeLocal(ctx context.Context, cfg LocalConfig, handler http.Handler, stdout io.Writer) error
- func WriteMetadata(path string, meta Metadata) error
- type DiagnosticError
- type DiagnosticInfo
- type DiagnosticResponse
- type EventEnvelope
- type Host
- type LocalConfig
- type MCPPromptCatalogArgument
- type MCPPromptCatalogEntry
- type MCPPromptCatalogHost
- type MCPPromptMessage
- type MCPPromptRenderRequest
- type MCPPromptRenderResponse
- type MCPPromptRendererHost
- type MCPReadResourceRequest
- type MCPResourceCatalogEntry
- type MCPResourceCatalogHost
- type MCPResourceContent
- type MCPResourceReadResponse
- type MCPResourceReaderHost
- type MemoryCatalogHost
- type MemoryCatalogRequest
- type MemoryCatalogResponse
- type MemoryEntry
- type MemoryForgetHost
- type MemoryForgetRequest
- type MemoryForgetResponse
- type Metadata
- type Options
- type PermissionCatalogResponse
- type PermissionContext
- type PermissionForgetResponse
- type PermissionGrant
- type PermissionPolicy
- type PermissionPolicyAction
- type PermissionPolicyDecision
- type PermissionPolicyFunc
- type PermissionStore
- type RecallHit
- type RecallHost
- type RecallRequest
- type RecallResponse
- type RoleCatalogEntry
- type RoleCatalogHost
- type Server
- type SkillCatalogEntry
- type SkillCatalogHost
- type ToolCatalogHost
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMetadataPath ¶
func DefaultMetadataPath() string
DefaultMetadataPath returns the shared local daemon metadata path.
func RandomToken ¶
RandomToken returns a 256-bit random bearer token encoded as hex.
func ResolveToken ¶
ResolveToken returns an explicit token, $GLUE_DAEMON_TOKEN, or a new random token, along with a human-readable source string.
func ServeLocal ¶
ServeLocal starts handler on a local TCP listener, writes optional connection metadata, and shuts down gracefully when ctx is canceled.
func WriteMetadata ¶
WriteMetadata writes local daemon connection metadata with owner-only permissions.
Types ¶
type DiagnosticError ¶
type DiagnosticError struct {
Time time.Time `json:"time"`
RunID string `json:"run_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
ClientID string `json:"client_id,omitempty"`
Error string `json:"error"`
}
DiagnosticError is one recent daemon runtime error, redacted for operational display.
type DiagnosticInfo ¶
type DiagnosticInfo struct {
Name string `json:"name,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
ListenAddr string `json:"listen_addr,omitempty"`
MetadataPath string `json:"metadata_path,omitempty"`
TokenSource string `json:"token_source,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
StoreType string `json:"store_type,omitempty"`
StorePath string `json:"store_path,omitempty"`
SettingsPath string `json:"settings_path,omitempty"`
IdentityPath string `json:"identity_path,omitempty"`
CodingEnabled bool `json:"coding_enabled"`
CodingWorkDir string `json:"coding_work_dir,omitempty"`
PermissionRememberPath string `json:"permission_remember_path,omitempty"`
}
DiagnosticInfo describes non-secret runtime configuration that daemon clients can use for local operations troubleshooting.
type DiagnosticResponse ¶
type DiagnosticResponse struct {
OK bool `json:"ok"`
Version int `json:"version"`
ActiveRuns int `json:"active_runs"`
ToolsCount int `json:"tools_count"`
Capabilities []string `json:"capabilities"`
Runtime DiagnosticInfo `json:"runtime"`
RecentErrors []DiagnosticError `json:"recent_errors,omitempty"`
}
DiagnosticResponse is the authenticated daemon diagnostics payload.
type EventEnvelope ¶
type EventEnvelope struct {
Version int `json:"version"`
ID string `json:"id"`
Seq int64 `json:"seq"`
RunID string `json:"run_id"`
SessionID string `json:"session_id"`
Time time.Time `json:"time"`
Type string `json:"type"`
Payload any `json:"payload,omitempty"`
}
EventEnvelope is the JSON payload sent in each SSE data frame.
type Host ¶
type Host interface {
Session(ctx context.Context, id string, options ...glue.SessionOption) (*glue.Session, error)
}
Host supplies sessions to a daemon Server.
type LocalConfig ¶
type LocalConfig struct {
Name string
ListenAddr string
Token string
TokenSource string
MetadataPath string
ShutdownTimeout time.Duration
}
LocalConfig configures ServeLocal.
type MCPPromptCatalogArgument ¶
type MCPPromptCatalogArgument struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
MCPPromptCatalogArgument describes one argument accepted by an MCP prompt.
type MCPPromptCatalogEntry ¶
type MCPPromptCatalogEntry struct {
Server string `json:"server"`
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Arguments []MCPPromptCatalogArgument `json:"arguments,omitempty"`
}
MCPPromptCatalogEntry describes one MCP prompt advertised by a host.
type MCPPromptCatalogHost ¶
type MCPPromptCatalogHost interface {
MCPPromptCatalog(context.Context) ([]MCPPromptCatalogEntry, error)
}
MCPPromptCatalogHost is optionally implemented by hosts that can expose MCP prompt metadata without starting a run.
type MCPPromptMessage ¶
type MCPPromptMessage struct {
Role string `json:"role"`
Content json.RawMessage `json:"content"`
}
MCPPromptMessage is one rendered prompt message.
type MCPPromptRenderRequest ¶
type MCPPromptRenderRequest struct {
Server string `json:"server"`
Name string `json:"name"`
Arguments map[string]string `json:"arguments,omitempty"`
}
MCPPromptRenderRequest selects one prompt from one configured server.
type MCPPromptRenderResponse ¶
type MCPPromptRenderResponse struct {
Server string `json:"server"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Messages []MCPPromptMessage `json:"messages"`
}
MCPPromptRenderResponse contains the messages returned by an MCP prompts/get request.
type MCPPromptRendererHost ¶
type MCPPromptRendererHost interface {
MCPRenderPrompt(context.Context, MCPPromptRenderRequest) (MCPPromptRenderResponse, error)
}
MCPPromptRendererHost is optionally implemented by hosts that can render one MCP prompt without starting a run.
type MCPReadResourceRequest ¶
MCPReadResourceRequest selects one resource URI from one configured server.
type MCPResourceCatalogEntry ¶
type MCPResourceCatalogEntry struct {
Server string `json:"server"`
URI string `json:"uri"`
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
Size *int64 `json:"size,omitempty"`
}
MCPResourceCatalogEntry describes one MCP resource advertised by a host.
type MCPResourceCatalogHost ¶
type MCPResourceCatalogHost interface {
MCPResourceCatalog(context.Context) ([]MCPResourceCatalogEntry, error)
}
MCPResourceCatalogHost is optionally implemented by hosts that can expose MCP resource metadata without starting a run.
type MCPResourceContent ¶
type MCPResourceContent struct {
URI string `json:"uri"`
MIMEType string `json:"mime_type,omitempty"`
Text *string `json:"text,omitempty"`
Blob *string `json:"blob,omitempty"`
Meta map[string]any `json:"_meta,omitempty"`
}
MCPResourceContent is one text or blob content item returned from a resource.
type MCPResourceReadResponse ¶
type MCPResourceReadResponse struct {
Server string `json:"server"`
URI string `json:"uri"`
Contents []MCPResourceContent `json:"contents"`
}
MCPResourceReadResponse contains the contents returned by an MCP resources/read request.
type MCPResourceReaderHost ¶
type MCPResourceReaderHost interface {
MCPReadResource(context.Context, MCPReadResourceRequest) (MCPResourceReadResponse, error)
}
MCPResourceReaderHost is optionally implemented by hosts that can read one MCP resource without starting a run.
type MemoryCatalogHost ¶
type MemoryCatalogHost interface {
MemoryCatalog(context.Context, MemoryCatalogRequest) (MemoryCatalogResponse, error)
}
MemoryCatalogHost is optionally implemented by hosts that can expose curated memory records without starting a run.
type MemoryCatalogRequest ¶
type MemoryCatalogRequest struct {
Limit int
}
MemoryCatalogRequest configures a memory catalog request.
type MemoryCatalogResponse ¶
type MemoryCatalogResponse struct {
Memories []MemoryEntry `json:"memories"`
}
MemoryCatalogResponse contains curated host memories.
type MemoryEntry ¶
type MemoryEntry struct {
ID string `json:"id"`
Content string `json:"content"`
Tags []string `json:"tags,omitempty"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
MemoryEntry describes one curated host memory.
type MemoryForgetHost ¶
type MemoryForgetHost interface {
MemoryForget(context.Context, MemoryForgetRequest) (MemoryForgetResponse, error)
}
MemoryForgetHost is optionally implemented by hosts that can delete one curated memory record without starting a run.
type MemoryForgetRequest ¶
type MemoryForgetRequest struct {
ID string `json:"id"`
}
MemoryForgetRequest selects one curated memory by stable id.
type MemoryForgetResponse ¶
type MemoryForgetResponse struct {
Memory MemoryEntry `json:"memory"`
}
MemoryForgetResponse contains the deleted memory record.
type Metadata ¶
type Metadata struct {
Version int `json:"version"`
BaseURL string `json:"base_url"`
Token string `json:"token"`
PID int `json:"pid"`
}
Metadata is the local connection file shape written by local daemon launchers and consumed by daemon clients.
func ReadMetadata ¶
ReadMetadata reads and validates local daemon connection metadata.
type Options ¶
type Options struct {
// Host is required. A *glue.Agent satisfies this interface.
Host Host
// Token is required for every route except /v1/health.
Token string
// PermissionPolicy, when non-nil, can allow, deny, or defer
// side-effecting tool permission requests before the daemon emits a
// permission_request event. The daemon package remains channel-blind:
// hosts that need channel/client policy decide from the supplied context.
PermissionPolicy PermissionPolicy
// PermissionStore, when non-nil, persists remembered permission grants
// across daemon restarts.
PermissionStore PermissionStore
// Diagnostics carries non-secret host/runtime details for
// authenticated ops tooling.
Diagnostics DiagnosticInfo
// Now supplies event timestamps. Nil uses time.Now.
Now func() time.Time
// NewID returns ids for runs and events. Nil uses crypto/rand.
NewID func(prefix string) string
// PermissionTimeout caps how long a side-effecting tool waits for an
// HTTP decision. Zero uses a conservative default.
PermissionTimeout time.Duration
}
Options configures New.
type PermissionCatalogResponse ¶
type PermissionCatalogResponse struct {
Permissions []PermissionGrant `json:"permissions"`
}
PermissionCatalogResponse contains remembered daemon permissions.
type PermissionContext ¶
PermissionContext describes the daemon run that owns a permission request.
type PermissionForgetResponse ¶
type PermissionForgetResponse struct {
Permission PermissionGrant `json:"permission"`
}
PermissionForgetResponse contains the deleted permission grant.
type PermissionGrant ¶
type PermissionGrant struct {
ID string `json:"id"`
Scope string `json:"scope"`
Owner string `json:"owner"`
ClientID string `json:"client_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
Tool string `json:"tool"`
Action string `json:"action"`
Target string `json:"target,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
PermissionGrant is one remembered daemon permission decision.
type PermissionPolicy ¶
type PermissionPolicy interface {
DecidePermission(context.Context, PermissionContext, glue.PermissionRequest) (PermissionPolicyDecision, error)
}
PermissionPolicy optionally decides side-effecting tool permission requests before the daemon asks the run owner over HTTP.
type PermissionPolicyAction ¶
type PermissionPolicyAction int
PermissionPolicyAction is the host policy outcome for one permission request.
const ( // PermissionPolicyPrompt keeps the existing daemon behavior: use cached // remembered decisions or ask the owning client over HTTP. PermissionPolicyPrompt PermissionPolicyAction = iota // PermissionPolicyAllow allows the side effect without asking the client. PermissionPolicyAllow // PermissionPolicyDeny denies the side effect without asking the client. PermissionPolicyDeny )
type PermissionPolicyDecision ¶
type PermissionPolicyDecision struct {
Action PermissionPolicyAction
Reason string
RememberFor glue.RememberScope
}
PermissionPolicyDecision is returned by PermissionPolicy.
type PermissionPolicyFunc ¶
type PermissionPolicyFunc func(context.Context, PermissionContext, glue.PermissionRequest) (PermissionPolicyDecision, error)
PermissionPolicyFunc adapts a function into a PermissionPolicy.
func (PermissionPolicyFunc) DecidePermission ¶
func (f PermissionPolicyFunc) DecidePermission(ctx context.Context, info PermissionContext, req glue.PermissionRequest) (PermissionPolicyDecision, error)
DecidePermission implements PermissionPolicy.
type PermissionStore ¶
type PermissionStore interface {
LoadPermissionGrants() ([]PermissionGrant, error)
SavePermissionGrants([]PermissionGrant) error
}
PermissionStore persists remembered daemon permission grants.
func NewFilePermissionStore ¶
func NewFilePermissionStore(path string) PermissionStore
NewFilePermissionStore returns a JSON-file-backed permission store. An empty path returns nil so callers can keep process-local permission remembers.
type RecallHit ¶
type RecallHit struct {
SessionID string `json:"session_id"`
Index int `json:"index"`
Role glue.MessageRole `json:"role,omitempty"`
Snippet string `json:"snippet"`
Score float64 `json:"score"`
Timestamp time.Time `json:"timestamp,omitempty"`
}
RecallHit is one stored session search result returned by a recall-capable daemon host.
type RecallHost ¶
type RecallHost interface {
RecallSearch(context.Context, RecallRequest) (RecallResponse, error)
}
RecallHost is optionally implemented by hosts that can search stored session history without starting a run.
type RecallRequest ¶
type RecallRequest struct {
Query string `json:"query"`
Limit int `json:"limit,omitempty"`
MemoriesOnly bool `json:"memories_only,omitempty"`
}
RecallRequest searches stored session history.
type RecallResponse ¶
type RecallResponse struct {
Hits []RecallHit `json:"hits"`
}
RecallResponse contains stored session search hits.
type RoleCatalogEntry ¶
type RoleCatalogEntry struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Model string `json:"model,omitempty"`
}
RoleCatalogEntry describes one reusable role advertised by a host.
type RoleCatalogHost ¶
type RoleCatalogHost interface {
RoleCatalog(context.Context) ([]RoleCatalogEntry, error)
}
RoleCatalogHost is optionally implemented by hosts that can expose reusable roles without starting a run.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an http.Handler for the local daemon protocol.
type SkillCatalogEntry ¶
type SkillCatalogEntry struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
SkillCatalogEntry describes one reusable skill advertised by a host.
type SkillCatalogHost ¶
type SkillCatalogHost interface {
SkillCatalog(context.Context) ([]SkillCatalogEntry, error)
}
SkillCatalogHost is optionally implemented by hosts that can expose reusable skills without starting a run.
type ToolCatalogHost ¶
ToolCatalogHost is optionally implemented by hosts that can expose the provider-visible tool surface without starting a run.