runner

package
v0.0.0-nightly.20260805 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LLMHealthNotConfigured = "not_configured"
	LLMHealthConfigured    = "configured"
	LLMHealthReady         = "ready"
	LLMHealthFailed        = "failed"
)
View Source
const (
	CommandPresentationPlain        = "plain"
	CommandPresentationPreformatted = "preformatted"
)
View Source
const DefaultSessionPendingLimit = 64
View Source
const MainREPLName = "main-repl"

Variables

View Source
var IOAClientCommandFunc func(ctx context.Context, mode cfg.RunMode, option *cfg.Option, args cfg.IOAClientArgs, logger telemetry.Logger) error

IOAClientCommandFunc dispatches IOA client CLI commands (spaces, messages, etc.). Set via init() from cmd/aiscan setup.

View Source
var IOAServeFunc func(ctx context.Context, option *cfg.Option, logger telemetry.Logger) error

IOAServeFunc starts the IOA HTTP server. Set via init() from cmd/aiscan setup.

View Source
var ScannerInitFunc func(ctx context.Context, a *App, rc ApplicationConfig, logger telemetry.Logger)

ScannerInitFunc initializes scanner engines and registers scanner commands. Set via init() from the package imported by cmd/aiscan.

View Source
var ScannerWithAgentFunc func(ctx context.Context, option *cfg.Option, application *App, scannerArgs []string, logger telemetry.Logger) error

ScannerWithAgentFunc runs a scanner command with AI agent assistance. Set via init() from the package imported by cmd/aiscan.

Functions

func AgentStatus

func AgentStatus(option *cfg.Option, app *App) *aop.AgentStatus

AgentStatus reports the node's provider/model/IOA binding for pool views.

func ApplyResolvedProviderOptions

func ApplyResolvedProviderOptions(option *cfg.Option, providerConfig agent.ProviderConfig)

func BuildSystemPrompt

func BuildSystemPrompt(cfg *PromptConfig, agentCfg *agent.Config) string

BuildSystemPrompt assembles the system prompt from config.

func CollectDeepBrowserArtifacts

func CollectDeepBrowserArtifacts(ctx context.Context, reg *commands.CommandRegistry, targetURL string, logger telemetry.Logger) (string, error)

func CommandCatalog

func CommandCatalog(app *App) []*types.CommandSpec

CommandCatalog is a node's user-facing composer catalog: "/verb" runtime and skill commands plus every "!verb" registered in the node's command registry. The web splits the two prefixes into their respective popups, while both stay sourced from the same node-level catalog used by the TUI.

func DefaultRuntimeInfo

func DefaultRuntimeInfo() *aop.AgentRuntimeInfo

DefaultRuntimeInfo returns OS process metadata for AOP node registration.

func ExecuteToolRequest

func ExecuteToolRequest(ctx context.Context, operationID string, request *toolpb.Call, executor ToolExecutor, progressBus *eventbus.Bus[*toolpb.Progress]) (*aop.Event, error)

ExecuteToolRequest runs one canonical AOP tool call against the executor and wraps the outcome as a ToolResult event correlated to operationID.

func FallbackProviderConfigs

func FallbackProviderConfigs(option *cfg.Option) []agent.ProviderConfig

func FallbackProviderConfigsFromProto

func FallbackProviderConfigsFromProto(llm *types.LLMConfig) []agent.ProviderConfig

FallbackProviderConfigsFromProto returns every non-active profile in order.

func HasScannerFlag

func HasScannerFlag(args []string, long string) bool

func ProviderConfig

func ProviderConfig(option *cfg.Option) agent.ProviderConfig

func ProviderConfigFromProto

func ProviderConfigFromProto(llm *types.LLMConfig) agent.ProviderConfig

ProviderConfigFromProto resolves the active LLM profile directly from the canonical config proto. This is the only provider-config path used when a DistributeConfig is already in hand (remote agents, hub reload).

func RegistryCommandCatalog

func RegistryCommandCatalog(registry *commands.CommandRegistry, store *skills.Store) []*types.CommandSpec

RegistryCommandCatalog projects the Bash-internal command registry without adding chat runtime or skill commands. Tool-only nodes use this catalog too.

func ReloadRuntimeConfig

func ReloadRuntimeConfig(distribute *types.DistributeConfig, rt *AgentRuntime, app *App, option *cfg.Option, logger telemetry.Logger) (agent.Provider, string, error)

ReloadRuntimeConfig hot-swaps the LLM provider from a pushed protobuf config. A build failure leaves the current provider in place and is reported through the returned error.

func ResolveIOANodeName

func ResolveIOANodeName(option *cfg.Option) string

func ResolveRuntimeConfig

func ResolveRuntimeConfig(option *cfg.Option) (string, error)

ResolveRuntimeConfig resolves the process configuration and applies process state such as the data directory.

func ResolveRuntimeConfigCandidate

func ResolveRuntimeConfigCandidate(option *cfg.Option) (string, error)

ResolveRuntimeConfigCandidate resolves a staged Web configuration without mutating process-wide state before the candidate is committed.

func RunAgentMode

func RunAgentMode(ctx context.Context, option *cfg.Option, logger telemetry.Logger, setInterrupt ...func(func() bool)) error

func RunDirectScannerMode

func RunDirectScannerMode(ctx context.Context, option *cfg.Option, rest []string, logger telemetry.Logger) (runErr error)

func RunIOAClientCommand

func RunIOAClientCommand(ctx context.Context, mode cfg.RunMode, option *cfg.Option, args cfg.IOAClientArgs, logger telemetry.Logger) error

func RunIOAServe

func RunIOAServe(ctx context.Context, option *cfg.Option, logger telemetry.Logger) error

func RunStdio

func RunStdio(ctx context.Context, option *cfg.Option, logger telemetry.Logger, input io.Reader, output io.Writer) error

RunStdio carries AOP Envelope messages as protobuf JSONL.

func RuntimeCommandSpecs

func RuntimeCommandSpecs() []*types.CommandSpec

func ShouldStreamScannerOutput

func ShouldStreamScannerOutput(rest []string) bool

func SystemPromptFunc

func SystemPromptFunc(cfg *PromptConfig) agent.SystemPromptFunc

SystemPromptFunc returns an agent.SystemPromptFunc that builds the system prompt dynamically on each turn.

Types

type AgentRuntime

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

func NewAgentRuntime

func NewAgentRuntime(ctx context.Context, option *cfg.Option, logger telemetry.Logger, rc *RuntimeConfig) (*AgentRuntime, error)

func (*AgentRuntime) AttachLocalREPL

func (rt *AgentRuntime) AttachLocalREPL(ctx context.Context) error

AttachLocalREPL runs the ephemeral console directly on the process terminal.

Readline control sequences cannot pass through the runtime PTY output buffer: attach replays buffered bytes, which can re-execute stale cursor state and corrupt native scrollback. Persistent remote REPLs continue to use the PTY; the ephemeral local console binds directly to the process terminal.

func (*AgentRuntime) CancelAOPTurn

func (rt *AgentRuntime) CancelAOPTurn(req *aop.CancelTurnRequest) *aop.CancelTurnResponse

func (*AgentRuntime) CancelRun

func (rt *AgentRuntime) CancelRun(turnID string) error

func (*AgentRuntime) CancelSessionRun

func (rt *AgentRuntime) CancelSessionRun(sessionID, turnID string) error

func (*AgentRuntime) Close

func (rt *AgentRuntime) Close()

func (*AgentRuntime) CloseAOPSession

func (*AgentRuntime) CloseSession

func (rt *AgentRuntime) CloseSession(ctx context.Context, sessionID string, reason SessionCloseReason) error

func (*AgentRuntime) CommandSession

func (rt *AgentRuntime) CommandSession(ctx context.Context, sessionID, line string) (*types.CommandResult, error)

func (*AgentRuntime) EmitEvent

func (rt *AgentRuntime) EmitEvent(event *aop.Event)

EmitEvent publishes an already-formed runtime event through the App-owned AOP bus, applying the same timestamp and sequence stamping as agent events.

func (*AgentRuntime) EnsureSession

func (rt *AgentRuntime) EnsureSession(options SessionOptions) (*Session, error)

EnsureSession returns an existing Runtime-owned Session or opens it with the Runtime lifetime. It is idempotent so a transport reconnect can safely announce the same logical Session again.

func (*AgentRuntime) HandleEnvelope

func (rt *AgentRuntime) HandleEnvelope(ctx context.Context, envelope *aop.Envelope, send func(*aop.Envelope)) bool

HandleEnvelope is the protobuf control loop shared by stdio and other direct AgentRuntime hosts. The wire envelope is common; semantics remain in their AOP or AIScan namespace ProtocolMessage.

func (*AgentRuntime) OpenAOPSession

func (rt *AgentRuntime) OpenAOPSession(req *aop.OpenSessionRequest) *aop.OpenSessionResponse

func (*AgentRuntime) OpenSession

func (rt *AgentRuntime) OpenSession(ctx context.Context, options SessionOptions) (*Session, error)

func (*AgentRuntime) ReloadProvider

func (rt *AgentRuntime) ReloadProvider(option *cfg.Option) (agent.Provider, string, error)

ReloadProvider rebuilds the LLM provider from option and hot-swaps it into the running runtime application and session template. It returns the live provider template every new chat agent is cloned from). It returns the live provider and resolved model so callers can propagate the swap to already-running agents. On a build failure the runtime is left untouched and the error is returned, so a bad config push never knocks out a working provider.

func (*AgentRuntime) RunAOPTurn

func (rt *AgentRuntime) RunAOPTurn(ctx context.Context, req *aop.RunTurnRequest) *aop.RunTurnResponse

func (*AgentRuntime) RunSession

func (rt *AgentRuntime) RunSession(ctx context.Context, sessionID string, input RunInput) (*Run, error)

func (*AgentRuntime) ServeEnvelopeStream

func (rt *AgentRuntime) ServeEnvelopeStream(ctx context.Context, stream aop.EnvelopeStream) error

ServeEnvelopeStream is the framing-independent runtime loop. WebSocket and stdio decide only how an Envelope is read and written; protobuf dispatch and reply correlation stay here.

func (*AgentRuntime) SetLogger

func (rt *AgentRuntime) SetLogger(logger telemetry.Logger)

func (*AgentRuntime) SetProvider

func (rt *AgentRuntime) SetProvider(provider agent.Provider, providerConfig agent.ProviderConfig)

SetProvider atomically updates the runtime template and every existing conversation session. Runs already in flight keep their provider snapshot.

func (*AgentRuntime) Subscribe

func (rt *AgentRuntime) Subscribe(fn func(*aop.Event)) func()

func (*AgentRuntime) WaitOperations

func (rt *AgentRuntime) WaitOperations()

WaitOperations waits for all Runs and asynchronous control operations that were admitted before the call. Transports use it to drain before shutdown.

type App

type App struct {
	Provider          agent.Provider
	ProviderConfig    agent.ProviderConfig
	ProviderFallbacks []agent.ProviderEntry
	Commands          *commands.CommandRegistry
	Hooks             *hooks.Registry
	Engines           any
	Skills            *skills.Store
	SkillDiagnostics  []skills.Diagnostic
	IOAClient         *ioaclient.Client
	IOAStreamClient   ioaclient.StreamAPI
	EventBus          *eventbus.Bus[*aop.Event]
	Events            *sessionEmitter
	Progress          *eventbus.Bus[*toolpb.Progress]
	Recorder          *output.JSONLRecorder
	// contains filtered or unexported fields
}

func NewApp

func NewApp(ctx context.Context, rc ApplicationConfig) (*App, error)

func (*App) Close

func (a *App) Close()

func (*App) InitIOA

func (a *App) InitIOA(ctx context.Context, ioa IOAConfig) error

func (*App) LLMHealth

func (a *App) LLMHealth() LLMHealth

func (*App) Logger

func (a *App) Logger() telemetry.Logger

func (*App) SetLogger

func (a *App) SetLogger(logger telemetry.Logger)

func (*App) StartRecording

func (a *App) StartRecording(path string) error

func (*App) SwitchRecording

func (a *App) SwitchRecording(path string) error

func (*App) WaitEngines

func (a *App) WaitEngines(ctx context.Context) error

type ApplicationConfig

type ApplicationConfig struct {
	Provider      ApplicationProviderConfig
	Scanner       ScannerConfig
	Tools         ToolConfig
	IOA           *IOAConfig
	Logger        telemetry.Logger
	CLISkillPaths []string
	RecordFile    string
	SkipEngines   bool
}

func AppConfig

func AppConfig(option *cfg.Option, features RuntimeFeatures, logger telemetry.Logger) ApplicationConfig

func AppConfigFromDistribute

func AppConfigFromDistribute(dc *types.DistributeConfig, features RuntimeFeatures, logger telemetry.Logger) ApplicationConfig

AppConfigFromDistribute builds the runner configuration directly from the canonical config proto. Fields that have no proto representation (playwright session, uncover credentials, CLI skill paths) stay at their defaults; the startup path layers them from cfg.Option via MergeOptionExtras.

func MergeOptionExtras

func MergeOptionExtras(rc ApplicationConfig, option *cfg.Option) ApplicationConfig

MergeOptionExtras layers fields DistributeConfig does not model onto a proto-built ApplicationConfig.

type ApplicationProviderConfig

type ApplicationProviderConfig struct {
	Enabled   bool
	Config    agent.ProviderConfig
	Fallbacks []agent.ProviderConfig
	Optional  bool
}

type IOAConfig

type IOAConfig struct {
	URL           string
	NodeID        string
	NodeName      string
	Space         string
	RegisterTools bool
	AutoRegister  bool
	NodeMeta      map[string]any
	Identity      protocols.Identity
}

type LLMHealth

type LLMHealth struct {
	State     string
	LatencyMs int64
	Error     string
	CheckedAt time.Time
}

LLMHealth is the latest lightweight provider connectivity check. It is kept separately from ProviderConfig: a syntactically valid configuration can still be unreachable or rejected by the remote service.

type LoadedSkill

type LoadedSkill struct {
	Name string
	Body string
}

LoadedSkill is a skill whose full body is embedded directly into the prompt.

type PromptConfig

type PromptConfig struct {
	Tools            *commands.CommandRegistry
	ScannerDocs      string
	CustomPreamble   string
	Skills           []skills.Skill
	LoadedSkills     []LoadedSkill // skill body 直接嵌入 prompt
	ScannerAgentMode bool
	ScannerName      string
	NodeName         string
	Space            string
}

type REPLMode

type REPLMode uint8
const (
	REPLDisabled REPLMode = iota
	REPLEphemeral
	REPLPersistent
)

type Run

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

func (*Run) TurnID

func (r *Run) TurnID() string

func (*Run) Wait

func (r *Run) Wait() (RunResult, error)

type RunInput

type RunInput struct {
	TurnID        string
	Message       *aop.Message
	Content       []*aop.Content
	MaxTurns      int
	EvalCriteria  string
	EvalMaxRounds int
	Continue      bool
	// contains filtered or unexported fields
}

type RunOutput

type RunOutput interface {
	HandleEvent(*aop.Event)
	SetContextWindow(int)
	Start(label, text string)
	Final(content string)
}

RunOutput is the presentation sink an entry point may attach to a runtime. The runtime never constructs one — CLI/TUI hosts inject it; headless hosts (stdio, WebSocket nodes, the web hub) leave it nil.

type RunResult

type RunResult struct {
	Output        string
	Stop          agent.StopReason
	Usage         *aop.TokenUsage
	ContextTokens int
}

type RuntimeConfig

type RuntimeConfig struct {
	ExistingApp      *App
	IOA              *IOAConfig
	PromptConfig     *PromptConfig
	Output           RunOutput
	ProviderOptional bool
	REPLMode         REPLMode
	MaxPending       int
}

type RuntimeFeatures

type RuntimeFeatures struct {
	ProviderEnabled  bool
	ProviderOptional bool
	ToolsEnabled     bool
	AIEnabled        bool
	ScannerAI        bool
	Warning          string
}

func DirectScannerRuntimeFeatures

func DirectScannerRuntimeFeatures(rest []string) (RuntimeFeatures, []string, error)

func DirectScannerRuntimeFeaturesWithDefault

func DirectScannerRuntimeFeaturesWithDefault(rest []string, defaultVerify string) (RuntimeFeatures, []string, error)

type ScannerConfig

type ScannerConfig struct {
	CyberhubURL        string
	CyberhubKey        string
	CyberhubMode       string
	AIEnabled          bool
	VerifyMode         string
	Proxy              string
	FofaEmail          string
	FofaKey            string
	HunterToken        string
	HunterAPIKey       string
	ReconProxy         string
	ReconLimit         int
	UncoverCredentials map[string]string
}

type Session

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

func (*Session) Agent

func (s *Session) Agent() *agent.Agent

func (*Session) Command

func (s *Session) Command(ctx context.Context, line string) (*types.CommandResult, error)

func (*Session) ID

func (s *Session) ID() string

func (*Session) MessagesSnapshot

func (s *Session) MessagesSnapshot() []*aop.Message

func (*Session) Resume

func (s *Session) Resume(ctx context.Context, path string) (int, error)

func (*Session) Run

func (s *Session) Run(ctx context.Context, input RunInput) (*Run, error)

type SessionCloseReason

type SessionCloseReason string
const (
	SessionCloseCompleted SessionCloseReason = "completed"
	SessionCloseCanceled  SessionCloseReason = "canceled"
	SessionCloseError     SessionCloseReason = "error"
	SessionCloseCleared   SessionCloseReason = "cleared"
	SessionCloseCompacted SessionCloseReason = "compacted"
	SessionCloseResumed   SessionCloseReason = "resumed"
	SessionCloseRuntime   SessionCloseReason = "runtime_closed"
)

type SessionOptions

type SessionOptions struct {
	ID               string
	LogicalID        string
	ParentSessionID  string
	ParentToolCallID string
	AgentName        string
	Messages         []*aop.Message
}

type ToolConfig

type ToolConfig struct {
	Enabled           bool
	BashTimeout       int
	TavilyKeys        string
	PlaywrightSession string
	OptionalTools     []string // optional tool groups to enable (e.g. "search", "browser")
}

type ToolExecutor

type ToolExecutor interface {
	ExecuteTool(context.Context, string, string) (*tool.Result, error)
}

ToolExecutor is the minimal surface a tool call dispatcher needs. *commands.CommandRegistry implements it.

Jump to

Keyboard shortcuts

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