Documentation
¶
Overview ¶
Package detectharness detects AI harnesses and safely manages stdio MCP server registrations across their native configuration formats.
Configuration can be managed in two scopes: the zero-value global scope (system/user configuration) and a project scope that targets a directory-local configuration for harnesses that support per-project MCP overrides. Use Scope and ProjectScopeDir to select a scope.
Index ¶
- func IsSupported(id ID) bool
- func RenderConfig(id ID, server StdioServer) (string, error)
- func RenderConfigScoped(id ID, server StdioServer, scope Scope) (string, error)
- type ApplyState
- type Change
- type ChangeState
- type ConflictPolicy
- type DesiredState
- type DetectOptions
- type Detection
- type DetectionState
- type Harness
- type ID
- type Installer
- func (i *Installer) Apply(ctx context.Context, plan *Plan) []Result
- func (i *Installer) Detect(ctx context.Context) []Detection
- func (i *Installer) DetectScoped(ctx context.Context, scope Scope) ([]Detection, error)
- func (i *Installer) Ensure(ctx context.Context, ids []ID, desired DesiredState, options PlanOptions) []Result
- func (i *Installer) Plan(ctx context.Context, ids []ID, desired DesiredState, options PlanOptions) *Plan
- type Option
- type Plan
- type PlanOptions
- type ProjectScope
- type Result
- type Scope
- type ScopeMode
- type StdioServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSupported ¶
IsSupported reports whether id identifies a built-in harness. Deprecated aliases (for example "roo-code") are accepted and resolve to their canonical harness.
func RenderConfig ¶
func RenderConfig(id ID, server StdioServer) (string, error)
RenderConfig generates a complete global configuration containing only server for one harness. It does not inspect or mutate the filesystem.
func RenderConfigScoped ¶ added in v0.2.0
func RenderConfigScoped(id ID, server StdioServer, scope Scope) (string, error)
RenderConfigScoped generates a complete configuration containing only server for one harness in the requested scope. For project scope it targets the harness's directory-local file; the directory itself is not inspected or created. An unsupported project scope returns an error.
Types ¶
type ApplyState ¶
type ApplyState string
ApplyState is the outcome of applying one planned change.
const ( Applied ApplyState = "applied" ApplyNoop ApplyState = "noop" ApplySkipped ApplyState = "skipped" ApplyConflict ApplyState = "conflict" ApplyFailed ApplyState = "failed" )
type Change ¶
type Change struct {
HarnessID ID `json:"harnessId"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
Desired DesiredState `json:"desired"`
State ChangeState `json:"state"`
Action string `json:"action,omitempty"`
Reason string `json:"reason,omitempty"`
Scope ScopeMode `json:"scope,omitempty"`
ScopeDir string `json:"scopeDir,omitempty"`
Before string `json:"-"`
After string `json:"-"`
}
Change is a serializable description of one planned harness change.
type ChangeState ¶
type ChangeState string
ChangeState is the outcome of planning one harness.
const ( ChangeReady ChangeState = "ready" ChangeNoop ChangeState = "noop" ChangeConflict ChangeState = "conflict" )
type ConflictPolicy ¶
type ConflictPolicy string
ConflictPolicy controls same-name entries that do not exactly match Server.
const ( ConflictError ConflictPolicy = "error" ConflictReplace ConflictPolicy = "replace" )
type DesiredState ¶
type DesiredState string
DesiredState describes the registration state a plan should establish.
const ( Present DesiredState = "present" Absent DesiredState = "absent" )
type DetectOptions ¶
type DetectOptions struct {
Platform string
HomeDir string
Env map[string]string
// Scope selects global (zero value) or project-scoped detection.
Scope Scope
}
DetectOptions overrides the host environment. It is primarily useful for tests and sandboxes.
type Detection ¶
type Detection struct {
Harness
State DetectionState `json:"state"`
Evidence []string `json:"evidence,omitempty"`
Reason string `json:"reason,omitempty"`
ConfigPath string `json:"configPath,omitempty"`
ConfigError string `json:"configError,omitempty"`
Scope ScopeMode `json:"scope,omitempty"`
ScopeDir string `json:"scopeDir,omitempty"`
}
Detection is the result of probing one harness.
func DetectHarnesses ¶
func DetectHarnesses(ctx context.Context, options DetectOptions) ([]Detection, error)
DetectHarnesses probes all built-in harnesses without requiring an MCP server definition. Zero-valued options use the current host environment.
type DetectionState ¶
type DetectionState string
DetectionState distinguishes absence from an environment that could not be inspected.
const ( Detected DetectionState = "present" NotDetected DetectionState = "absent" )
type Harness ¶
type Harness struct {
ID ID `json:"id"`
Name string `json:"name"`
ReloadHint string `json:"reloadHint"`
// Project describes project-scoped (directory-local) configuration support.
// It is nil for harnesses that only support a global configuration.
Project *ProjectScope `json:"project,omitempty"`
}
Harness describes a supported AI harness without probing the local machine.
type ID ¶
type ID string
ID is the stable identifier of a supported AI harness.
const ( ClaudeDesktop ID = "claude-desktop" ClaudeCode ID = "claude-code" Cursor ID = "cursor" Codex ID = "codex" GeminiCLI ID = "gemini-cli" Windsurf ID = "windsurf" Zed ID = "zed" Cline ID = "cline" RooCode ID = "roo-code" // Deprecated: canonical id is ZooCode; kept as an alias for backward compatibility. ZooCode ID = "zoo-code" AmazonQ ID = "amazon-q" Continue ID = "continue" OpenCode ID = "opencode" VSCode ID = "vscode" )
func CanonicalID ¶ added in v0.2.0
CanonicalID resolves deprecated harness ids (for example "roo-code") to their canonical replacement. It is exported so protocol-level callers can deduplicate ids consistently with the registry.
type Installer ¶
type Installer struct {
// contains filtered or unexported fields
}
Installer detects harnesses and manages one MCP server registration.
func New ¶
func New(server StdioServer, options ...Option) (*Installer, error)
New validates server once and returns a reusable installer.
func (*Installer) DetectScoped ¶ added in v0.3.0
DetectScoped probes every supported harness in the requested scope using the installer's own environment. The zero-value scope behaves like Detect; a project scope reports whether each harness's directory-local configuration is present. An invalid scope is an error.
func (*Installer) Ensure ¶
func (i *Installer) Ensure(ctx context.Context, ids []ID, desired DesiredState, options PlanOptions) []Result
Ensure plans and applies a selection in one call. Use Plan and Apply separately when showing a preview or requiring user confirmation.
func (*Installer) Plan ¶
func (i *Installer) Plan(ctx context.Context, ids []ID, desired DesiredState, options PlanOptions) *Plan
Plan inspects selected harnesses and computes changes without writing files. It never returns nil: invalid input produces one unavailable change per selected harness whose Reason explains the rejection, so callers can render every outcome uniformly.
Harnesses that merge additional configuration layers (for example OpenCode's config.json or $OPENCODE_CONFIG) are inspected for same-name entries that would shadow or outlive the managed entry. Under ConflictError such an entry is reported as a conflict; under ConflictReplace the change proceeds and Reason carries a warning naming the other layer.
type Option ¶
type Option func(*installerOptions) error
Option customizes an Installer.
func WithEnvironment ¶
func WithEnvironment(options DetectOptions) Option
WithEnvironment overrides platform, home, and environment resolution.
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
Plan is an immutable set of configuration changes. Its internal snapshots are retained so Apply can reject files changed after planning.
type PlanOptions ¶
type PlanOptions struct {
ConflictPolicy ConflictPolicy
// Scope selects global (zero value) or project-scoped planning.
Scope Scope
}
PlanOptions controls planning without performing writes.
type ProjectScope ¶ added in v0.2.0
type ProjectScope struct {
// Path is the canonical project file location relative to the project
// directory (for example ".mcp.json").
Path string `json:"path"`
// ReloadHint describes how a user picks up project-scope changes.
ReloadHint string `json:"reloadHint"`
// Lifecycle summarizes creation, merge, and preemptive-create behavior.
Lifecycle string `json:"lifecycle"`
Shareable bool `json:"shareable"`
// TrustGate indicates the harness gates project servers behind a trust or
// approval dialog before they are loaded.
TrustGate bool `json:"trustGate"`
}
ProjectScope describes how a harness supports directory-local MCP configuration. It is informational metadata for library consumers building install UX; detect-harness never creates files unless asked to plan/apply.
type Result ¶
type Result struct {
HarnessID ID `json:"harnessId"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
Desired DesiredState `json:"desired"`
State ApplyState `json:"state"`
Action string `json:"action,omitempty"`
Reason string `json:"reason,omitempty"`
Scope ScopeMode `json:"scope,omitempty"`
ScopeDir string `json:"scopeDir,omitempty"`
}
Result reports the outcome for one harness without hiding partial success.
type Scope ¶ added in v0.2.0
type Scope struct {
Mode ScopeMode `json:"mode,omitempty"`
// Dir is the project directory. It is required when Mode is ScopeProject and
// ignored otherwise. Relative paths are resolved against the process work
// directory. Absolute paths are recommended.
Dir string `json:"dir,omitempty"`
}
Scope selects where configuration is detected and applied. The zero value is global scope.
func ProjectScopeDir ¶ added in v0.2.0
ProjectScopeDir returns a scope that targets directory-local configuration in dir.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
detect-harness
command
|
|
|
Package protocol defines the stable JSON contract used by the companion binary and language wrappers.
|
Package protocol defines the stable JSON contract used by the companion binary and language wrappers. |