runner

package
v0.0.0-nightly.20260802 Latest Latest
Warning

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

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

Documentation

Index

Constants

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 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 FallbackProviderConfigs

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

func HasScannerFlag

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

func ProviderConfig

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

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) 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 hosts the same explicit Session/Run/Command protocol used by the WebSocket adapter. Both stdin and stdout are webproto.Message JSONL streams.

func RuntimeCommandSpecs

func RuntimeCommandSpecs() []webproto.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) CancelRun

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

func (*AgentRuntime) Close

func (rt *AgentRuntime) Close()

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) (CommandResult, error)

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) HandleProtocol

func (rt *AgentRuntime) HandleProtocol(ctx context.Context, msg webproto.Message, send func(webproto.Message)) bool

HandleProtocol handles the transport-neutral Agent Runtime control frames. The caller owns framing and I/O; AgentRuntime owns all Session and Run state.

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) RunSession

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

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
	DataBus           *eventbus.Bus[output.ToolDataEvent]
	SCOSidecar        *output.SCOSidecar
	// 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) Logger

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

func (*App) SetLogger

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

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
	SkipEngines   bool
}

func AppConfig

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

type ApplicationProviderConfig

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

type CommandResult

type CommandResult struct {
	Command      string            `json:"command"`
	Presentation string            `json:"presentation,omitempty"`
	Parts        []aop.MessagePart `json:"parts,omitempty"`
}

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 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
	Parts         []aop.MessagePart
	NoEcho        bool
	MaxTurns      int
	EvalCriteria  string
	EvalMaxRounds int
	Continue      bool
	// contains filtered or unexported fields
}

type RunResult

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

type RuntimeConfig

type RuntimeConfig struct {
	ExistingApp       *App
	IOA               *IOAConfig
	PromptConfig      *PromptConfig
	NoOutput          bool
	InteractiveOutput bool
	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) Command

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

func (*Session) ID

func (s *Session) ID() string

func (*Session) MessagesSnapshot

func (s *Session) MessagesSnapshot() []agent.ChatMessage

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"
	SessionCloseRuntime   SessionCloseReason = "runtime_closed"
)

type SessionOptions

type SessionOptions struct {
	ID               string
	ParentSessionID  string
	ParentToolCallID string
	AgentName        string
	Messages         []agent.ChatMessage
}

type ToolConfig

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

Jump to

Keyboard shortcuts

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