Documentation
¶
Overview ¶
Package probe provides agent discovery and capability caching.
It probes installed ACP agents to discover their models/modes; the cache is warmed up at server startup and refreshed lazily on subsequent requests.
Index ¶
- Variables
- func ACPAgentEnvKey(commandOrKey string) string
- func ACPAgentEnvKeyPriority(savedKey string) (string, int)
- func ACPAgentEnvLookupKeys(commandOrKey string) []string
- func CacheACPConfigState(command string, target model.ACPConfigTarget, modelID string, modeID string, ...)
- func CachedAgentValidation(agentID, revision string, envVersion int64) (model.ACPProbeCacheEntry, bool)
- func HeadlessBin(command string) (string, bool)
- func InitAllowedAgentCommands()
- func PickDefaultModeID(modes []model.ACPSessionMode) string
- func PreviewSetConfig(ctx context.Context, command string, sel PreviewSelection, asyncDone func()) (*model.ACPConfigState, error)
- func StoreValidation(entry model.ACPProbeCacheEntry)
- func ValidateAgent(ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64) error
- func ValidateBinding(ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, ...) (model.ACPProbeCacheEntry, error)
- func ValidateBindingCandidate(ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, ...) (model.ACPProbeCacheEntry, error)
- type ACPAgentDef
- type AgentEnvProvider
- type CacheService
- func (s *CacheService) InstallBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
- func (s *CacheService) InvalidateAgent(agentID string)
- func (s *CacheService) InvalidateAgentAndPersist(ctx context.Context, agentID string) error
- func (s *CacheService) InvalidateBinding(agentID, revision string)
- func (s *CacheService) InvalidateBindingsAndPersist(ctx context.Context, bindings []model.AgentRuntimeBinding) error
- func (s *CacheService) LoadPersisted(ctx context.Context) (*model.ACPProbeCacheSnapshot, error)
- func (s *CacheService) PersistNow(ctx context.Context) error
- func (s *CacheService) PersistPending() bool
- func (s *CacheService) RefreshAsync(ctx context.Context)
- func (s *CacheService) UninstallBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
- func (s *CacheService) UpgradeBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
- func (s *CacheService) ValidateBindingAsync(ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, ...)
- func (s *CacheService) Warmup(ctx context.Context) error
- type PreviewSelection
- type PreviewTarget
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownAgentID = errors.New("unknown built-in agent id") ErrAgentDeprecated = errors.New("built-in agent is deprecated") ErrManualInstallOnly = errors.New("built-in agent only supports manual installation") ErrAgentNotInstalled = errors.New("built-in agent is not installed") ErrNotUninstallable = errors.New("built-in agent does not support automatic uninstall") )
Sentinel errors of the built-in install flow; the HTTP layer maps them with errors.Is. Messages are wrapped with full context before reaching users.
var KnownACPAgents = catalog.BuiltinSnapshot()
KnownACPAgents is the compatibility view used by existing probe, install and usage call sites. The authoritative append-only declaration is in catalog.
Functions ¶
func ACPAgentEnvKey ¶
ACPAgentEnvKey returns the stable AgentID used by current settings. Legacy EnvKey/Bin/command aliases remain lookup-only migration identifiers.
func ACPAgentEnvKeyPriority ¶
ACPAgentEnvKeyPriority reports the stable env key and precedence for a saved settings key. Higher priority wins when normalizing duplicates.
func ACPAgentEnvLookupKeys ¶
ACPAgentEnvLookupKeys returns the current and historical settings keys that may hold env vars for this agent. New writes should use ACPAgentEnvKey; reads use this list to migrate older command-keyed settings.
func CacheACPConfigState ¶
func CacheACPConfigState( command string, target model.ACPConfigTarget, modelID string, modeID string, thoughtLevelID string, state *model.ACPConfigState, )
CacheACPConfigState mirrors a successful live-session selector change into the probe cache so later /agent/list requests return the most recently used values. Model/thought updates are scoped to their model key; mode updates do not touch either model-linked field.
func CachedAgentValidation ¶
func CachedAgentValidation(agentID, revision string, envVersion int64) (model.ACPProbeCacheEntry, bool)
func HeadlessBin ¶
HeadlessBin maps an ACP agent's *serve* command (the string stored in AgentInfo.Type, e.g. "qoderclicn --acp" or "claude-agent-acp") to the binary used to run that same tool in *headless one-shot* mode (e.g. "qoderclicn", "claude").
This distinction matters: an ACP serve command speaks JSON-RPC over stdio and cannot be invoked as `<cmd> -p <prompt>`; doing so just boots the ACP server and exits non-zero. One-shot text flows (title / IM reply) must instead run the agent's plain CLI in print mode, which is exactly what KnownACPAgents already records as Bin. The second return value reports whether command was a recognised ACP agent.
func InitAllowedAgentCommands ¶
func InitAllowedAgentCommands()
InitAllowedAgentCommands registers only the current runtime revision of each installed, active built-in Agent. Historical revisions are retained in the catalog and registered on demand when a session or GraphRun uses them.
Made explicit (rather than an init()) so startup ordering is visible in the entrypoint and tests do not depend on import ordering.
func PickDefaultModeID ¶
func PickDefaultModeID(modes []model.ACPSessionMode) string
PickDefaultModeID selects a default mode from the available modes list, preferring modes with "all", "full", or "bypass" in their ID.
func PreviewSetConfig ¶
func PreviewSetConfig( ctx context.Context, command string, sel PreviewSelection, asyncDone func(), ) (*model.ACPConfigState, error)
PreviewSetConfig applies a session-less selector change against the probe cache. Cached state is returned immediately and refreshed asynchronously; only an uncached agent/model pair performs a synchronous ACP probe. Because each target updates only its own cached selection, refreshing a model-linked thought-level list can never reset the cached mode.
func StoreValidation ¶
func StoreValidation(entry model.ACPProbeCacheEntry)
func ValidateAgent ¶
ValidateAgent forces a live ACP validation for the given agent command and updates the in-memory selector cache on success. Unlike the background refresh fan-out it never consults the failure backoff — explicit validation always probes. The probe itself is bounded by acpProbeTimeout.
func ValidateBinding ¶
func ValidateBinding( ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, env []pkgacp.EnvVar, ) (model.ACPProbeCacheEntry, error)
func ValidateBindingCandidate ¶
func ValidateBindingCandidate( ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, env []pkgacp.EnvVar, ) (model.ACPProbeCacheEntry, error)
Types ¶
type ACPAgentDef ¶
type ACPAgentDef = catalog.BuiltinAgent
func FindACPAgentByID ¶
func FindACPAgentByID(agentID string) (ACPAgentDef, bool)
FindACPAgentByID returns the catalog entry with the given AgentID.
func InstalledACPAgents ¶
func InstalledACPAgents() []ACPAgentDef
InstalledACPAgents returns the subset of KnownACPAgents whose plain CLI Bin and ACP startup program are both executable by the backend process. Deprecated entries never participate.
type AgentEnvProvider ¶
AgentEnvProvider returns the enabled ACP environment variables configured for an agent (a stable AgentID, an install command or a bin name), keyed by variable name. Install flows hand the result to every preset step.
type CacheService ¶
type CacheService struct {
// contains filtered or unexported fields
}
CacheService owns the persisted ACP selector snapshot and coordinates it with the process-wide live probe cache.
func NewCacheService ¶
func NewCacheService(agentEnv AgentEnvProvider) (*CacheService, error)
NewCacheService builds the probe cache service. agentEnv supplies each agent's configured ACP environment for install flows; pass nil to install with the backend process environment only.
func (*CacheService) InstallBuiltinAgent ¶
func (s *CacheService) InstallBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
InstallBuiltinAgent runs the preset install flow declared by the catalog entry for agentID: execute the preset steps (skipped when already installed), re-run the unified installation check, then — only when installed — run a full ACP validation. The returned result carries every step's complete output, the recheck outcome, and the validation outcome; a failing install or validation is reported inside the result, not as an error. Errors are reserved for requests that cannot start an install at all (unknown/deprecated/manual-only agent, another install in flight).
func (*CacheService) InvalidateAgent ¶
func (s *CacheService) InvalidateAgent(agentID string)
func (*CacheService) InvalidateAgentAndPersist ¶
func (s *CacheService) InvalidateAgentAndPersist(ctx context.Context, agentID string) error
func (*CacheService) InvalidateBinding ¶
func (s *CacheService) InvalidateBinding(agentID, revision string)
func (*CacheService) InvalidateBindingsAndPersist ¶
func (s *CacheService) InvalidateBindingsAndPersist( ctx context.Context, bindings []model.AgentRuntimeBinding, ) error
func (*CacheService) LoadPersisted ¶
func (s *CacheService) LoadPersisted(ctx context.Context) (*model.ACPProbeCacheSnapshot, error)
LoadPersisted reads the disk snapshot for the current request. Missing in-memory entries are seeded from it so a later live refresh merges rather than discards the last known-good value when an agent is temporarily down.
func (*CacheService) PersistNow ¶
func (s *CacheService) PersistNow(ctx context.Context) error
PersistNow forces the current in-memory selector cache to disk, bypassing the disk-write throttle. Used after an explicit install+validation so the freshly probed result survives a restart.
func (*CacheService) PersistPending ¶
func (s *CacheService) PersistPending() bool
func (*CacheService) RefreshAsync ¶
func (s *CacheService) RefreshAsync(ctx context.Context)
RefreshAsync attempts a live refresh on every request. Concurrent requests coalesce behind acpRefreshing; once the current refresh finishes, the next request starts another one.
func (*CacheService) UninstallBuiltinAgent ¶
func (s *CacheService) UninstallBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
UninstallBuiltinAgent runs the platform-specific automatic uninstall flow for agentID, then re-runs the unified installation check. The returned result carries every step's complete output and the recheck outcome — a successful uninstall leaves Installed false. Unlike install, no ACP validation runs afterward. Errors are reserved for requests that cannot start an uninstall at all (unknown agent, not uninstallable, another install/uninstall in flight).
func (*CacheService) UpgradeBuiltinAgent ¶
func (s *CacheService) UpgradeBuiltinAgent(ctx context.Context, agentID string) (*model.AgentInstallResult, error)
UpgradeBuiltinAgent re-runs the catalog-declared install steps for an installed built-in Agent, then rechecks and validates the resulting ACP runtime. The client still supplies only AgentID; commands remain entirely controlled by the built-in catalog.
func (*CacheService) ValidateBindingAsync ¶
func (s *CacheService) ValidateBindingAsync( ctx context.Context, binding model.AgentRuntimeBinding, envVersion int64, done func(), )
func (*CacheService) Warmup ¶
func (s *CacheService) Warmup(ctx context.Context) error
Warmup initializes the live cache from disk and always refreshes in the background. An empty or schema-reset snapshot must not delay HTTP readiness; callers see pending_validation until the first refresh finishes.
type PreviewSelection ¶
type PreviewSelection struct {
Target PreviewTarget
Model string
Mode string
ThoughtLevel string
}
PreviewSelection carries the full current selection for a Home config switch. Target is the selector the user just changed; Model / Mode / ThoughtLevel hold the current values of all three so the throwaway session can be replayed into the same state before the refreshed lists are read back. Empty values are skipped.
type PreviewTarget ¶
type PreviewTarget string
PreviewTarget names which selector a Home (session-less) config switch changes.
const ( PreviewTargetModel PreviewTarget = "model" PreviewTargetMode PreviewTarget = "mode" PreviewTargetThoughtLevel PreviewTarget = "thoughtLevel" )