core

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPermissionAuditEvent

func AppendPermissionAuditEvent(event permission.AuditEvent) error

func CloseDaemonConnections

func CloseDaemonConnections() int

CloseDaemonConnections force closes all cached daemon connections. Used during opagent shutdown to avoid orphan daemon child processes.

func CompletionAgentIDForSystem

func CompletionAgentIDForSystem(cfg *op.SystemConfig) string

func ConfigGetHandler

func ConfigGetHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func ConfigSystemGetHandler

func ConfigSystemGetHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronAddHandler

func CronAddHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronGetHandler

func CronGetHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronHistoryHandler

func CronHistoryHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronListHandler

func CronListHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronRemoveHandler

func CronRemoveHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronRunHandler

func CronRunHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronUpdateHandler

func CronUpdateHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func CronUpsertHandler

func CronUpsertHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func DefaultCompletionAgentID

func DefaultCompletionAgentID() string

func GetObjectStore

func GetObjectStore() objectstore.Store

func IsRuntimeIdle

func IsRuntimeIdle(gracePeriod time.Duration) bool

func NotifyInfo

func NotifyInfo(params *op.InfoNotificationParams) error

func NotifyProgress

func NotifyProgress(opCode op.OpCode, meta op.Meta, content op.Content)

NotifyProgress sends a notification with metadata to the thread.

func OpAgentHandler

func OpAgentHandler(ctx context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpAgentLoopCreateHandler

func OpAgentLoopCreateHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpAgentScanHandler

func OpAgentScanHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpEditorCompletionCancelHandler

func OpEditorCompletionCancelHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpEditorCompletionHandler

func OpEditorCompletionHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpMessageAckHandler

func OpMessageAckHandler(req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpMessageArchiveHandler

func OpMessageArchiveHandler(req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpMessageListHandler

func OpMessageListHandler(req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpMessageReadHandler

func OpMessageReadHandler(req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpMessageReplyHandler

func OpMessageReplyHandler(req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpNodeHandler

func OpNodeHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpNodeListHandler

func OpNodeListHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionApprovalCancelHandler

func OpPermissionApprovalCancelHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionApprovalListHandler

func OpPermissionApprovalListHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionApprovalResolveHandler

func OpPermissionApprovalResolveHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionProfileListHandler

func OpPermissionProfileListHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionTrustGetHandler

func OpPermissionTrustGetHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionTrustSetHandler

func OpPermissionTrustSetHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionWorkspaceGetHandler

func OpPermissionWorkspaceGetHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpPermissionWorkspaceSelectHandler

func OpPermissionWorkspaceSelectHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpRuntimeEvidenceAnswerHandler

func OpRuntimeEvidenceAnswerHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpSandboxSetupHandler

func OpSandboxSetupHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpSandboxStatusGetHandler

func OpSandboxStatusGetHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadActiveListHandler

func OpThreadActiveListHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadCompactHandler

func OpThreadCompactHandler(ctx context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadCreateHandler

func OpThreadCreateHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadFollowUpHandler

func OpThreadFollowUpHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadFollowUpPromoteHandler

func OpThreadFollowUpPromoteHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadForkHandler

func OpThreadForkHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadInterruptedHandler

func OpThreadInterruptedHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadMetaGetHandler

func OpThreadMetaGetHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadMetaUpdateHandler

func OpThreadMetaUpdateHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadQueueGetHandler

func OpThreadQueueGetHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadQueueRemoveHandler

func OpThreadQueueRemoveHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadReviewListHandler

func OpThreadReviewListHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadReviewResolveHandler

func OpThreadReviewResolveHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadReviewRollbackHandler

func OpThreadReviewRollbackHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadSnapshotGetHandler

func OpThreadSnapshotGetHandler(req *op.OpNodeRequest) (*op.OpNodeResult, error)

func OpThreadSteerHandler

func OpThreadSteerHandler(_ context.Context, req *op.OpAgentRequest) (*op.OpAgentResult, error)

func OpThreadSubmitHandler

func OpThreadSubmitHandler(ctx context.Context, req *op.OpNodeRequest) (*op.OpNodeResult, error)

func RefreshNodeCache

func RefreshNodeCache(ctx context.Context, opts scan.ScanOptions) error

RefreshNodeCache rescans the configured baseDir and replaces the cached node set. The cache is updated only after the full scan completes so renames and deletions do not leave stale nodes behind.

func ResetHostHooks

func ResetHostHooks()

func SetConn

func SetConn(conn *Connection)

func SetDefaultObjectStore

func SetDefaultObjectStore(store objectstore.Store)

func SetDefaultStorage

func SetDefaultStorage(storage Storage)

SetDefaultStorage allows external initialization of the default storage instance

func SetHostHooks

func SetHostHooks(hooks HostHooks)

func StartCron

func StartCron(ctx context.Context, cfg *op.SystemConfig) error

func StartNotify

func StartNotify(ctx context.Context)

func StopCron

func StopCron()

func SubscribeNotifications

func SubscribeNotifications(buffer int) (<-chan *op.InfoNotificationParams, func())

SubscribeNotifications registers a bounded, best-effort event consumer. A slow subscriber drops events instead of blocking agent execution.

Types

type Agent

type Agent struct {
	AgentID            string
	AgentMeta          *op.AgentMeta
	AvailableSkills    []op.OpNode
	AvailableSubagents []op.OpNode
	Conn               *Connection
	ToolSpecs          map[string]*op.ToolSpec
	Meta               op.Meta
	Sysprompt          string
	PromptIsFinal      bool
}

func NewAgent

func NewAgent(ctx context.Context, node *op.OpNode, meta op.Meta) (*Agent, error)

type AgentLoop

type AgentLoop struct {
	Ctx                  context.Context    `json:"-"`
	Cancel               context.CancelFunc `json:"-"`
	Agent                *Agent
	Meta                 op.Meta
	ThreadID             string
	TurnID               string
	ChatPath             string
	Workdir              string
	ThinkingLevel        string
	ContextWindow        int64
	PlanTurn             bool
	SelectedSkillIDs     []string
	SelectedSkillContext op.Meta
	Model                *ModelClient
	// contains filtered or unexported fields
}

func NewAgentLoop

func NewAgentLoop(ctx context.Context, node *op.OpNode, meta op.Meta, content op.Content) (*AgentLoop, error)

func NewContinuationAgentLoop

func NewContinuationAgentLoop(ctx context.Context, node *op.OpNode, meta op.Meta) (*AgentLoop, error)

func NewQueuedPromptAgentLoop

func NewQueuedPromptAgentLoop(ctx context.Context, node *op.OpNode, meta op.Meta, pending PendingLoopMessage) (*AgentLoop, error)

type Connection

type Connection struct {
	NodeID string `json:"nodeID"`
	Name   string `json:"name"`
	// ConnType    ConnType           `json:"connType"`
	Meta                op.Meta            `json:"meta"`
	TransType           op.TransportType   `json:"type"`
	Command             []string           `json:"command"`
	OpCodes             []op.OpCode        `json:"opcodes"`
	URL                 string             `json:"url"`
	Description         string             `json:"description"`
	Daemon              bool               `json:"daemon"`
	Session             *op.ClientSession  `json:"-"`
	Ctx                 context.Context    `json:"-"`
	Cancel              context.CancelFunc `json:"-"`
	CacheKey            string             `json:"-"`
	PermissionThreadID  string             `json:"-"`
	PermissionWorkspace string             `json:"-"`
	PermissionDigest    string             `json:"-"`
	// contains filtered or unexported fields
}

func CreateConnection

func CreateConnection(ctx context.Context, node *op.OpNode) (*Connection, error)

func CreateSystemConnection

func CreateSystemConnection(ctx context.Context, node *op.OpNode) (*Connection, error)

CreateSystemConnection is the only non-thread local-process entry point. It is limited to product-installed nodes explicitly registered for startup; conversation actions must use the thread-scoped agent/tool helpers instead.

func CreateToolDiscoveryConnection

func CreateToolDiscoveryConnection(ctx context.Context, node *op.OpNode) (*Connection, error)

func EnsureAgentConnection

func EnsureAgentConnection(ctx context.Context, node *op.OpNode, meta op.Meta) (*Connection, error)

EnsureAgentConnection keeps process-backed agents under the immutable thread permission snapshot. Safe profiles cannot hand an entire remote agent session an unrestricted network channel; use exact-scope remote MCP instead.

func EnsureConnection

func EnsureConnection(ctx context.Context, node *op.OpNode) (*Connection, error)

func EnsureToolConnection

func EnsureToolConnection(ctx context.Context, node *op.OpNode, meta op.Meta, cwd string) (*Connection, error)

func GetConn

func GetConn(nodeID string) *Connection

func (*Connection) CallAgent

func (conn *Connection) CallAgent(ctx context.Context, agentID string, meta op.Meta, content op.Content) (*op.CallAgentResult, error)

func (*Connection) CallNode

func (conn *Connection) CallNode(ctx context.Context, meta op.Meta, content op.Content) (*op.CallNodeResult, error)

func (*Connection) CallTool

func (conn *Connection) CallTool(ctx context.Context, params *op.CallToolParams) (*op.CallToolResult, error)

func (*Connection) Close

func (conn *Connection) Close()

func (*Connection) ForceClose

func (conn *Connection) ForceClose()

func (*Connection) ListToolSpecs

func (conn *Connection) ListToolSpecs() ([]*op.ToolSpec, error)

func (*Connection) ListToolSpecsContext

func (conn *Connection) ListToolSpecsContext(ctx context.Context) ([]*op.ToolSpec, error)

func (*Connection) NotifyInfo

func (conn *Connection) NotifyInfo(ctx context.Context, params *op.InfoNotificationParams) error

func (*Connection) OpNode

func (conn *Connection) OpNode(ctx context.Context, params *op.OpNodeParams) (*op.OpNodeResult, error)

func (*Connection) RuntimeSnapshot

func (conn *Connection) RuntimeSnapshot(now time.Time) *ConnectionRuntimeSnapshot

type ConnectionRuntimeSnapshot

type ConnectionRuntimeSnapshot struct {
	NodeID       string           `json:"nodeID"`
	Name         string           `json:"name,omitempty"`
	Transport    op.TransportType `json:"transport,omitempty"`
	Daemon       bool             `json:"daemon,omitempty"`
	ConnectedAt  *time.Time       `json:"connectedAt,omitempty"`
	PID          int              `json:"pid,omitempty"`
	StartedAt    *time.Time       `json:"startedAt,omitempty"`
	UptimeSec    int64            `json:"uptimeSec,omitempty"`
	LastActiveAt *time.Time       `json:"lastActiveAt,omitempty"`
	URL          string           `json:"url,omitempty"`
}

func ListActiveConnectionSnapshots

func ListActiveConnectionSnapshots(now time.Time) []*ConnectionRuntimeSnapshot

type ContinueLoopConfig

type ContinueLoopConfig struct {
	PendingMessages         []op.Message
	SkipInitialSteeringPoll bool
}

type CronTask

type CronTask struct {
	ID                  string                 `json:"id"`
	Name                string                 `json:"name"`
	Description         string                 `json:"description,omitempty"`
	Enabled             bool                   `json:"enabled"`
	PermissionProfileID op.PermissionProfileID `json:"permissionProfileID,omitempty"`
	Schedule            CronTaskSchedule       `json:"schedule"`
	Target              CronTaskTarget         `json:"target"`
	Payload             CronTaskPayload        `json:"payload"`
	CreatedAtMs         int64                  `json:"createdAtMs,omitempty"`
	UpdatedAtMs         int64                  `json:"updatedAtMs,omitempty"`
}

func (*CronTask) UnmarshalJSON

func (t *CronTask) UnmarshalJSON(data []byte) error

type CronTaskHistoryResult

type CronTaskHistoryResult struct {
	TaskID string                    `json:"taskID"`
	Limit  int                       `json:"limit"`
	Runs   []CronTaskRunHistoryEntry `json:"runs"`
}

type CronTaskListResult

type CronTaskListResult struct {
	Version int              `json:"version"`
	Tasks   []CronTaskRecord `json:"tasks"`
}

type CronTaskPayload

type CronTaskPayload struct {
	Kind string         `json:"kind"`
	Text string         `json:"text,omitempty"`
	Data map[string]any `json:"data,omitempty"`
}

type CronTaskRecord

type CronTaskRecord struct {
	Task  CronTask       `json:"task"`
	State *CronTaskState `json:"state,omitempty"`
}

type CronTaskRunHistoryEntry

type CronTaskRunHistoryEntry struct {
	RunID         string `json:"runID"`
	TaskID        string `json:"taskID"`
	Trigger       string `json:"trigger"`
	ScheduledAtMs int64  `json:"scheduledAtMs,omitempty"`
	StartedAtMs   int64  `json:"startedAtMs"`
	FinishedAtMs  int64  `json:"finishedAtMs,omitempty"`
	DurationMs    int64  `json:"durationMs,omitempty"`
	Status        string `json:"status"`
	Error         string `json:"error,omitempty"`
	ThreadID      string `json:"threadID,omitempty"`
	ChatPath      string `json:"chatPath,omitempty"`
	AgentID       string `json:"agentID,omitempty"`
}

type CronTaskRunResult

type CronTaskRunResult struct {
	Queued bool           `json:"queued"`
	Task   CronTaskRecord `json:"task"`
}

type CronTaskSchedule

type CronTaskSchedule struct {
	Cron  string `json:"cron,omitempty"`
	Every string `json:"every,omitempty"`
	Time  string `json:"time,omitempty"`
}

type CronTaskState

type CronTaskState struct {
	TaskID            string           `json:"taskID"`
	SpecHash          string           `json:"specHash,omitempty"`
	NextRunAtMs       int64            `json:"nextRunAtMs,omitempty"`
	RunNowAtMs        int64            `json:"runNowAtMs,omitempty"`
	RunNowPayload     *CronTaskPayload `json:"runNowPayload,omitempty"`
	LastRunAtMs       int64            `json:"lastRunAtMs,omitempty"`
	RunningAtMs       int64            `json:"runningAtMs,omitempty"`
	LastError         string           `json:"lastError,omitempty"`
	ConsecutiveErrors int              `json:"consecutiveErrors,omitempty"`
}

type CronTaskStoreFile

type CronTaskStoreFile struct {
	Version int        `json:"version"`
	Tasks   []CronTask `json:"tasks"`
}

type CronTaskTarget

type CronTaskTarget struct {
	Kind    string `json:"kind"`
	AgentID string `json:"agentID"`
	CWD     string `json:"cwd"`
}

type HostHooks

type HostHooks struct {
	ResolveHeaders         func(context.Context, map[string]string) (map[string]string, error)
	AuthorizeSystemService func(context.Context, *op.OpNode) error
	AuthorizeRemoteNode    func(context.Context, *op.OpNode) error
	AugmentPrompt          func(context.Context, string, string, op.Meta) (string, error)
	TransformToolArguments func(context.Context, op.Meta, string, string, any, any) (any, error)
	AuthorizeCron          func(context.Context, op.OpCode, op.Meta, op.Content) error
}

HostHooks are process-wide in v0.1 because the runtime supports one instance per process. Product integrations may install policy here; standalone OpAgent keeps the fail-closed defaults below.

type Loop

type Loop struct {
	Ctx      context.Context
	Meta     op.Meta
	ThreadID string
	TurnID   string
	Workdir  string
}

Loop is the minimal runtime handle for a running agent loop (tool calls, registry). It is built from AgentLoop when running the loop.

type ModelClient

type ModelClient struct {
	Canonical ai.CanonicalProvider
	Responses ai.ResponsesProvider
	Ctx       context.Context
	// contains filtered or unexported fields
}

func NewModelClient

func NewModelClient(ctx context.Context, modelID string, meta op.Meta) (*ModelClient, error)

type PendingLoopMessage

type PendingLoopMessage struct {
	Message              op.Message
	QueueKind            op.ThreadQueueKind
	QueueItemID          string
	SelectedSkillIDs     []string
	SelectedSkillContext op.Meta
	PlanTurn             bool
}

type RunLoopConfig

type RunLoopConfig struct {
	GetSteeringMessages     func(context.Context) ([]PendingLoopMessage, error)
	GetFollowUpMessages     func(context.Context) ([]PendingLoopMessage, error)
	InitialPendingMessages  []PendingLoopMessage
	SkipInitialSteeringPoll bool
}

RunLoopConfig holds optional callbacks for steering and follow-up messages (pi-mono style). If a callback is nil, no messages are injected.

type Storage

type Storage interface {

	// user task
	GetUserTask(ctx context.Context, taskID string) (*op.UserTask, error)
	ListUserTasks(ctx context.Context, uid string) ([]*op.UserTask, error)
	UpsertUserTask(ctx context.Context, task *op.UserTask) error
	BindThreadIDToUserTaskID(ctx context.Context, taskID, threadID string) error
	DeleteThreadIDFromUserTask(ctx context.Context, taskID, threadID string) error
	DeleteUserTask(ctx context.Context, taskID string) error

	// user settings
	UpsertUserSettings(ctx context.Context, settings *op.UserSettings) error
	GetUserSettings(ctx context.Context, uid string) (*op.UserSettings, error)

	// ListUIDs returns distinct UIDs that exist in storage.
	ListUIDs(ctx context.Context) ([]string, error)
}

Storage defines the underlying storage interface. Agent/skill/tool records have been moved to nodestore (in-memory cache). This interface retains only thread, user, and model persistence.

func GetStorage

func GetStorage() Storage

GetStorage returns the default storage instance

type ToolCall

type ToolCall struct {
	Type string   `json:"type"`
	ID   string   `json:"id"`
	Info toolInfo `json:"info"`
}

type ToolCallDelta

type ToolCallDelta struct {
	Index       int
	ID          string
	Type        string
	Name        string
	Description string
	Arguments   string
}

type ToolCallState

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

func NewToolCallState

func NewToolCallState() *ToolCallState

func (*ToolCallState) Accumulate

func (s *ToolCallState) Accumulate(delta ToolCallDelta)

func (*ToolCallState) Finalize

func (s *ToolCallState) Finalize() []ToolCall

func (*ToolCallState) HasPending

func (s *ToolCallState) HasPending() bool

func (*ToolCallState) Reset

func (s *ToolCallState) Reset()

Jump to

Keyboard shortcuts

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