ai

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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
)
View Source
const (
	EngineClaude = "claude"
	EngineCodex  = "codex"
	EnginePi     = "pi"
	EngineKimi   = "kimi"
)

Engine name constants used for registration and configuration.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the process-wide registry populated by engine init() functions.

View Source
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

func AppendExtraEnv(base []string, extraEnv map[string]string) []string

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

func BuildBaseEnv(openbeeURL string) []string

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

func BuildRunEnv(baseEnv, extraEnv []string, apiKey string) []string

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 Register

func Register(name string, f Factory)

Register adds a factory to the DefaultRegistry.

func ScanJSONLines

func ScanJSONLines(r io.Reader, fn func(line string) bool)

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

func SkillHintPrefix(role Role) string

SkillHintPrefix returns the skill invocation hint prepended to the first message of a new session.

func WorkerPersona

func WorkerPersona(name, description, memory string) string

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 Process

type Process interface {
	PID() int
	Stop() error
}

Process is the handle for a running engine process.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps engine names to their factories.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) New

func (r *Registry) New(name string, cfg EngineConfig) (EngineAdapter, error)

New constructs the engine registered under name.

func (*Registry) Register

func (r *Registry) Register(name string, f Factory)

Register adds a factory under name. Panics if name is already registered.

type Role

type Role string

Role identifies the openbee agent role.

const (
	RoleBee    Role = "bee"
	RoleWorker Role = "worker"
)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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