Documentation
¶
Index ¶
- Constants
- Variables
- func AllEngines() []string
- func AppendExtraEnv(base []string, extraEnv map[string]string) []string
- func BuildBaseEnv(openbeeURL string) []string
- func BuildRunEnv(baseEnv, extraEnv []string, apiKey string) []string
- func Register(name string, f Factory)
- func ScanJSONLines(r io.Reader, fn func(line string) bool)
- func SkillHintPrefix(role Role) string
- func WorkerPersona(name, description, constraints string) string
- type CmdProcess
- type DynamicAdapter
- type EngineAdapter
- type EngineConfig
- type Factory
- type Output
- type OutputType
- type PrepareOptions
- type Process
- type Registry
- type Role
- type RunOptions
- type RunResult
Constants ¶
const ( // SystemRulesFile is the legacy rules file that Claude's Prepare hook cleans up. SystemRulesFile = ".openbee.md" // ImportLine is the legacy reference line that Claude's Prepare hook removes from CLAUDE.md. ImportLine = "@" + SystemRulesFile )
const ( EngineClaude = "claude" EngineCodex = "codex" EnginePi = "pi" EngineKimi = "kimi" )
Engine name constants used for registration and configuration.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the process-wide registry populated by engine init() functions.
var ErrUnknownEngine = fmt.Errorf("unknown engine")
ErrUnknownEngine is returned when New is called with an unregistered engine name.
Functions ¶
func AllEngines ¶ added in v0.0.26
func AllEngines() []string
AllEngines returns a snapshot of the canonical engine name list in registration order.
func AppendExtraEnv ¶ added in v0.0.26
AppendExtraEnv appends non-empty entries from extraEnv to base and returns the result re-clipped to its length, preventing concurrent Run() appends from sharing the backing array with other goroutines.
func BuildBaseEnv ¶
BuildBaseEnv constructs the base environment for engine subprocesses. It prepends the current executable's directory to PATH and appends OPENBEE_URL.
func BuildRunEnv ¶ added in v0.0.24
BuildRunEnv assembles the final env slice for a subprocess run. Entries are ordered baseEnv → extraEnv → apiKey; for duplicate keys the last value wins (standard subprocess env resolution on Linux/macOS), so extraEnv overrides baseEnv and apiKey overrides both.
func ScanJSONLines ¶
ScanJSONLines reads r line by line and calls fn for each line that starts with '{'. fn returns true to keep scanning or false to stop early.
func SkillHintPrefix ¶
SkillHintPrefix returns the skill invocation hint prepended to the first message of a new session.
func WorkerPersona ¶
WorkerPersona returns the persona-only content injected into new worker session prompts.
Types ¶
type CmdProcess ¶
type CmdProcess struct {
// contains filtered or unexported fields
}
CmdProcess implements Process for an os/exec.Cmd.
func NewCmdProcess ¶
func NewCmdProcess(cmd *exec.Cmd) *CmdProcess
NewCmdProcess wraps an exec.Cmd as a Process.
func (*CmdProcess) PID ¶
func (p *CmdProcess) PID() int
func (*CmdProcess) Stop ¶
func (p *CmdProcess) Stop() error
type DynamicAdapter ¶ added in v0.0.26
type DynamicAdapter struct {
// contains filtered or unexported fields
}
DynamicAdapter wraps multiple EngineAdapters and routes each Run call to whichever engine cfg.Get() returns at call time. The RunResult's ExtractResult closes over the engine that was actually picked, so callers processing results asynchronously are immune to later /engine switches.
func NewDynamicAdapter ¶ added in v0.0.26
func NewDynamicAdapter(engines map[string]EngineAdapter, cfg *enginecfg.Store) *DynamicAdapter
NewDynamicAdapter constructs a DynamicAdapter routing through cfg.
func (*DynamicAdapter) Prepare ¶ added in v0.0.26
func (d *DynamicAdapter) Prepare(workDir string, opts PrepareOptions) error
Prepare initialises every engine adapter for the given workDir. Most engines have a no-op Prepare; the only meaningful work (Claude's legacy file cleanup) is a single os.Remove, so a sequential loop is sufficient.
func (*DynamicAdapter) Run ¶ added in v0.0.26
func (d *DynamicAdapter) Run(ctx context.Context, workDir, prompt string, opts RunOptions, logPath string) (RunResult, error)
type EngineAdapter ¶
type EngineAdapter interface {
// Prepare is an engine-specific initialisation hook called before each Run.
// It must be idempotent. Claude uses it to clean up legacy config files;
// other engines return nil.
Prepare(workDir string, opts PrepareOptions) error
// Run executes a task and returns a RunResult carrying the process handle,
// event channel, and an engine-bound result extractor. The event channel
// is closed after the process exits.
Run(ctx context.Context, workDir, prompt string,
opts RunOptions, logPath string) (RunResult, error)
}
EngineAdapter is the complete plugin contract for an AI engine. Implementations must be safe for concurrent use.
func New ¶
func New(name string, cfg EngineConfig) (EngineAdapter, error)
New constructs an engine from the DefaultRegistry.
type EngineConfig ¶
type EngineConfig struct {
// OpenbeeURL is the openbee server base URL injected for MCP connectivity.
OpenbeeURL string
// Raw holds engine-specific configuration (parsed from config.yaml).
Raw map[string]any
}
EngineConfig holds the configuration passed to a Factory when constructing an engine.
func (EngineConfig) ExtraEnv ¶ added in v0.0.26
func (c EngineConfig) ExtraEnv() map[string]string
ExtraEnv returns Raw["env"] as a map[string]string, or nil if absent / mistyped.
func (EngineConfig) PathOrDefault ¶ added in v0.0.26
func (c EngineConfig) PathOrDefault(def string) string
PathOrDefault returns Raw["path"] when it's a non-empty string, else def.
type Factory ¶
type Factory func(cfg EngineConfig) (EngineAdapter, error)
Factory creates an EngineAdapter from the supplied config.
type Output ¶
type Output struct {
Type OutputType `json:"type"`
Content string `json:"content"`
}
Output is a single lifecycle event.
type OutputType ¶
type OutputType string
OutputType classifies a lifecycle event from a running process.
const ( OutputDone OutputType = "done" OutputError OutputType = "error" )
type PrepareOptions ¶
type PrepareOptions struct {
Role Role
}
PrepareOptions carries parameters for the engine-specific Prepare hook. Add future fields here without changing the Prepare method signature.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps engine names to their factories.
func (*Registry) New ¶
func (r *Registry) New(name string, cfg EngineConfig) (EngineAdapter, error)
New constructs the engine registered under name.
type RunOptions ¶
type RunOptions struct {
SessionID string
Resume bool
APIKey string
ExtraEnv []string // additional KEY=VALUE env vars to inject
}
RunOptions controls session behaviour for an engine invocation.
type RunResult ¶ added in v0.0.26
type RunResult struct {
Process Process
Output <-chan Output
ExtractResult func(logPath string) string
}
RunResult is the handle returned from EngineAdapter.Run. ExtractResult is bound to the engine that handled this Run, so it remains correct even if the active engine later changes.
func NewRunResult ¶ added in v0.0.26
func NewRunResult(proc Process, out <-chan Output, err error, extract func(logPath string) string) (RunResult, error)
NewRunResult wraps the (process, output, error) tuple returned by an engine invoker into a RunResult, attaching the engine's result extractor on success.