profile

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package profile defines provider profile selection and profile resource declarations (see docs/api-reference.md §§10–11).

It answers two host questions with one import:

  • Where does the provider profile live? Native(), Dedicated(dir), CloneNative(dir, ...), and CloneFrom(src, dst, ...) build the same normalized Selection consumed by adaptor.WithProfile. Clone constructors accept CloneOption values such as LinkAuth() to share OAuth login state without copying token files.

  • What must exist inside it? Resources declares desired skills, MCP servers, sub-agents, hooks, instructions, and structured config patches. Resource types and enum families are owned here; skill.Ref and mcp.Server retain the vocabularies of their dedicated leaf packages.

Resource declarations never expose the Driver SPI or internal engine representations. adaptor.WithProfileResources converts and owns a deep copy at the option boundary. Nil resource slices are undeclared; non-nil empty MCP, sub-agent, hook, or config slices explicitly clear SDK-managed entries. The truthful materialization report stays on the Agent surface (ProfileState / SyncProfile).

Index

Constants

View Source
const (
	// ModeUnset means "use the driver default behavior" (see Default).
	ModeUnset = driver.ProfileModeUnset
	// ModeNative uses the provider's native profile/home resolution.
	ModeNative = driver.ProfileModeNative
	// ModeDedicated uses Selection.Dir as the provider home/profile directory.
	ModeDedicated = driver.ProfileModeDedicated
	// ModeClone creates or refreshes a managed profile copied from a source.
	ModeClone = driver.ProfileModeClone
)
View Source
const (
	// AuthNone leaves auth files out of the cloned profile.
	AuthNone = driver.CloneProfileAuthNone
	// AuthCopy copies auth files into the cloned profile (see CopyAuth).
	AuthCopy = driver.CloneProfileAuthCopy
	// AuthLink shares auth files with the source profile (see LinkAuth).
	AuthLink = driver.CloneProfileAuthLink
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMode

type AuthMode = driver.CloneProfileAuthMode

AuthMode controls how clone constructors seed auth files from the source profile. It is an alias for driver.CloneProfileAuthMode.

type CloneOption

type CloneOption func(*CloneOptions)

CloneOption adjusts the CloneOptions carried by CloneNative and CloneFrom.

func CopyAuth

func CopyAuth() CloneOption

CopyAuth copies auth files into the cloned profile when they are missing there (AuthMode = AuthCopy). This is suitable for static API-key style auth, but can duplicate OAuth refresh-token state for CLIs that rotate tokens in place; prefer LinkAuth for OAuth-backed CLIs.

func CopyMCP

func CopyMCP() CloneOption

CopyMCP copies the provider MCP configuration files into the cloned profile when they are missing there (CloneOptions.IncludeMCP).

func CopySettings

func CopySettings() CloneOption

CopySettings copies the provider settings files into the cloned profile when they are missing there (CloneOptions.IncludeSettings).

func CopySkills

func CopySkills() CloneOption

CopySkills copies the provider skills directories into the cloned profile when they are missing there (CloneOptions.IncludeSkills).

func LinkAuth

func LinkAuth() CloneOption

LinkAuth shares auth files with the source profile by symlink, falling back to a hardlink when symlinks are unavailable (AuthMode = AuthLink). The clone therefore reuses the machine's OAuth login state instead of duplicating token files, and it fails rather than silently copying if neither shared-file strategy works.

func WithOptions

func WithOptions(opts CloneOptions) CloneOption

WithOptions replaces the accumulated CloneOptions with a pre-built struct. CloneOption values applied after it still take effect on top.

type CloneOptions

type CloneOptions = driver.CloneProfileOptions

CloneOptions controls which parts of a source provider profile are copied by CloneNative and CloneFrom. It is an alias for driver.CloneProfileOptions; hosts normally build it through CloneOption values instead of setting fields directly.

type ConfigFileKind

type ConfigFileKind string

ConfigFileKind identifies the serialized structured config format.

const (
	ConfigFileJSON ConfigFileKind = "json"
	ConfigFileTOML ConfigFileKind = "toml"
)

type ConfigPatch

type ConfigPatch struct {
	Key        string
	Capability string
	Values     map[string]any
	Native     *NativeConfigPatch
}

ConfigPatch is one structured profile configuration update.

type Hook

type Hook struct {
	Key         string
	Event       HookEvent
	MatcherSpec HookMatcher
	Handler     HookHandler

	Timeout       time.Duration
	FailPolicy    HookFailPolicy
	StatusMessage string
	Disabled      bool

	Native   map[string]any
	Metadata map[string]string
}

Hook describes one host-declared provider hook.

type HookEvent

type HookEvent string

HookEvent is the SDK-level lifecycle event a Hook fires on.

const (
	HookEventSessionStart      HookEvent = "session_start"
	HookEventSessionEnd        HookEvent = "session_end"
	HookEventPromptSubmit      HookEvent = "prompt_submit"
	HookEventPromptExpand      HookEvent = "prompt_expand"
	HookEventPreTool           HookEvent = "pre_tool"
	HookEventPostTool          HookEvent = "post_tool"
	HookEventToolFailure       HookEvent = "tool_failure"
	HookEventPermissionRequest HookEvent = "permission_request"
	HookEventPreShell          HookEvent = "pre_shell"
	HookEventPostShell         HookEvent = "post_shell"
	HookEventPreMCP            HookEvent = "pre_mcp"
	HookEventPostMCP           HookEvent = "post_mcp"
	HookEventPreFileRead       HookEvent = "pre_file_read"
	HookEventPostFileEdit      HookEvent = "post_file_edit"
	HookEventSubagentStart     HookEvent = "subagent_start"
	HookEventSubagentStop      HookEvent = "subagent_stop"
	HookEventPreCompact        HookEvent = "pre_compact"
	HookEventPostCompact       HookEvent = "post_compact"
	HookEventStop              HookEvent = "stop"
	HookEventStopFailure       HookEvent = "stop_failure"
)

type HookFailPolicy

type HookFailPolicy string

HookFailPolicy controls how a failed hook affects the provider operation.

const (
	HookFailPolicyProviderDefault HookFailPolicy = ""
	HookFailPolicyOpen            HookFailPolicy = "open"
	HookFailPolicyClosed          HookFailPolicy = "closed"
)

type HookHandler

type HookHandler struct {
	Type    HookHandlerType
	Command string
	Args    []string
	Env     map[string]string

	Prompt string
	URL    string
	Server string
	Tool   string
	Input  map[string]any
	Agent  string
}

HookHandler describes the action a Hook runs. Command hooks are portable core; other handler types require explicit Driver support.

type HookHandlerType

type HookHandlerType string

HookHandlerType identifies a hook action.

const (
	HookHandlerCommand HookHandlerType = "command"
	HookHandlerPrompt  HookHandlerType = "prompt"
	HookHandlerHTTP    HookHandlerType = "http"
	HookHandlerMCPTool HookHandlerType = "mcp_tool"
	HookHandlerAgent   HookHandlerType = "agent"
)

type HookMatcher

type HookMatcher struct {
	Subject HookMatcherSubject
	Syntax  HookMatcherSyntax
	Pattern string
}

HookMatcher describes what a Hook filters on and which syntax the pattern uses.

type HookMatcherSubject

type HookMatcherSubject string

HookMatcherSubject identifies the value matched by a HookMatcher.

const (
	HookMatcherSubjectDefault  HookMatcherSubject = ""
	HookMatcherSubjectTool     HookMatcherSubject = "tool"
	HookMatcherSubjectCommand  HookMatcherSubject = "command"
	HookMatcherSubjectMCP      HookMatcherSubject = "mcp"
	HookMatcherSubjectPath     HookMatcherSubject = "path"
	HookMatcherSubjectPrompt   HookMatcherSubject = "prompt"
	HookMatcherSubjectSubagent HookMatcherSubject = "subagent"
	HookMatcherSubjectSource   HookMatcherSubject = "source"
)

type HookMatcherSyntax

type HookMatcherSyntax string

HookMatcherSyntax identifies how a HookMatcher pattern is interpreted.

const (
	HookMatcherSyntaxProvider HookMatcherSyntax = ""
	HookMatcherSyntaxExact    HookMatcherSyntax = "exact"
	HookMatcherSyntaxRegex    HookMatcherSyntax = "regex"
	HookMatcherSyntaxPrefix   HookMatcherSyntax = "prefix"
	HookMatcherSyntaxContains HookMatcherSyntax = "contains"
)

type InstructionMode

type InstructionMode string

InstructionMode controls whether instructions add to or replace the provider's existing instruction set.

const (
	InstructionModeAdditive InstructionMode = ""
	InstructionModeReplace  InstructionMode = "replace"
)

type InstructionScope

type InstructionScope string

InstructionScope identifies the provider profile layer for instructions.

const (
	InstructionScopeDefault InstructionScope = ""
	InstructionScopeUser    InstructionScope = "user"
	InstructionScopeProject InstructionScope = "project"
	InstructionScopeLocal   InstructionScope = "local"
	InstructionScopeRun     InstructionScope = "run"
)

type Instructions

type Instructions struct {
	ID          string
	Path        string
	Content     string
	Fingerprint string
	Scope       InstructionScope
	Mode        InstructionMode
	Native      map[string]any
}

Instructions points at host-supplied instruction material. Drivers decide whether to materialize it as a provider-native file/rule or inject it into the prompt as a fallback.

func Text

func Text(content string) *Instructions

Text builds an inline instruction bundle from literal content.

type Mode

type Mode = driver.ProfileMode

Mode describes how a driver chooses its local provider profile directory. It is an alias for driver.ProfileMode.

type NativeConfigPatch

type NativeConfigPatch struct {
	Provider string
	FileKind ConfigFileKind
	Path     string
	Section  string
	Values   map[string]any
}

NativeConfigPatch identifies a provider-native structured config patch.

type Resources

type Resources struct {
	Skills       []skill.Ref
	MCP          []mcp.Server
	Agents       []SubAgent
	Hooks        []Hook
	Instructions *Instructions
	Config       []ConfigPatch
}

Resources is the host-facing desired-state bundle for an effective provider profile. It deliberately owns the consumer vocabulary instead of aliasing the Driver SPI or the internal engine representation.

A nil MCP, Agents, Hooks, or Config slice means that resource family was not declared. A non-nil empty slice explicitly declares an empty family and clears SDK-managed entries. Skills are additive; an empty Skills slice is a no-op. Instructions is declared when non-nil.

type Selection

type Selection = driver.ProfileSelection

Selection is the normalized profile request consumed by built-in drivers. It is an alias for driver.ProfileSelection; the constructors below offer a compact, provider-independent way to build it.

func CloneFrom

func CloneFrom(src, dst string, opts ...CloneOption) Selection

CloneFrom creates or refreshes a managed profile at dst by cloning from src. It is useful for service hosts that seed disposable profiles from an operator-approved template.

func CloneNative

func CloneNative(dir string, opts ...CloneOption) Selection

CloneNative creates or refreshes a managed profile at dir by cloning the driver's default/native source profile. With no options only the managed profile skeleton is ensured; add CopySettings, CopyMCP, CopySkills, and CopyAuth/LinkAuth to seed state from the source.

func Dedicated

func Dedicated(dir string) Selection

Dedicated pins the agent to a specific profile/home directory. Use it when a host manages isolated operator profiles itself.

func Default

func Default() Selection

Default requests the driver's default profile behavior. It is the zero Selection (ModeUnset). Most hosts want Native or an isolated mode instead; Default makes the unset intent explicit.

func Native

func Native() Selection

Native uses the provider's normal native profile/home lookup (~/.claude, ~/.codex, ...). This is appropriate for local CLI-style integrations.

type SubAgent

type SubAgent struct {
	Key               string
	RuntimeName       string
	Description       string
	Instructions      string
	SourcePath        string
	SourceFingerprint string

	Model           string
	ReasoningEffort string
	ToolPolicy      *ToolPolicy
	PermissionMode  string
	SandboxMode     string
	MCPServers      []string
	Skills          []string
	Hooks           []Hook

	Native   map[string]any
	Metadata map[string]string
}

SubAgent describes one host-declared sub-agent/profile agent entry.

type ToolPolicy

type ToolPolicy struct {
	Allow []string
	Deny  []string
}

ToolPolicy captures provider-neutral tool allow/deny intent for a SubAgent. Drivers translate this intent to provider-native controls.

Jump to

Keyboard shortcuts

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