moduleapi

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 22 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

Overview

Package moduleapi defines the compile-time contract between the Node runtime and optional native feature modules under modules/*/node.

Core packages never import concrete feature modules; an explicit assembly package (such as internal/assembly/host) constructs an Assembly and passes it to node.StartWithOptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCustomTool

func BuildCustomTool(spec ToolSpec, instruction string, execute func(context.Context, canonical.ToolRequest) engine.ToolResult) (engine.Tool, error)

BuildCustomTool constructs an engine.Tool directly from a ToolSpec and custom execution hooks (used by modules such as code-index workflows, OCR listing, and memory).

func ConnectionServices

func ConnectionServices(a Assembly) (DatabaseExecutor, SSHFactory)

ConnectionServices retains the connection-only view of assembly resolution.

Types

type ArtifactViewProvider

type ArtifactViewProvider interface {
	ArtifactViews() []BuiltInArtifactView
}

ArtifactViewProvider is optionally implemented by native modules that ship document renderers. A module can keep old versions registered for replay.

type Assembly

type Assembly struct {
	// SystemPrompt replaces the default product instructions for main and
	// delegated turns. An empty value selects the Harness default.
	SystemPrompt string
	// Nil and empty lists select no packages.
	BundledDefaults []plugins.DefaultPackage
	// BundledPackages is immutable and rooted at plugins/<name>, with plugins/catalog.json.
	BundledPackages fs.FS
	CodeIndex       codeindexapi.Factory
	// Databases overrides the selected database executor when non-nil.
	Databases DatabaseExecutor
	// SSH overrides the selected SSH provider's factory when non-nil.
	SSH SSHFactory
	// Terminal overrides the selected terminal provider's factory when non-nil.
	Terminal TerminalFactory
	// Deprecated: retained for source compatibility. Workspace modules must
	// register their own handlers through WorkspaceServiceProvider.
	LegacyWorkspaceModules bool
	Modules                []Module
}

Assembly selects the compile-time Node modules and optional services.

func (Assembly) ArtifactViewFor

func (a Assembly) ArtifactViewFor(reference protocol.PluginReference) (BuiltInArtifactView, bool)

ArtifactViewFor only matches the recorded native reference; a package with the same name still uses the assets from its own captured revision.

func (Assembly) CommandHandlerFor

func (a Assembly) CommandHandlerFor(kind string) CommandHandler

CommandHandlerFor returns the assembled module owning the given protocol command kind, if any.

func (Assembly) HasModule

func (a Assembly) HasModule(id string) bool

HasModule reports presence by identity, independently of service availability.

func (Assembly) LookupTool

func (a Assembly) LookupTool(name string) (ToolMeta, bool)

LookupTool resolves presentation metadata for a canonical module tool name or its legacy plugin/MCP alias.

func (Assembly) NativeSkillPackages

func (a Assembly) NativeSkillPackages() []operations.NativeSkillPackage

NativeSkillPackages returns the skill trees contributed by assembled modules.

func (Assembly) NativeSkills

func (a Assembly) NativeSkills() []protocol.NativeSkill

NativeSkills returns the protocol-facing metadata of all built-in module skills.

func (Assembly) ReplacesPlugin

func (a Assembly) ReplacesPlugin(name string) bool

ReplacesPlugin reports whether any assembled module supersedes the tool declarations of the named legacy plugin package.

func (Assembly) ResolveServices

func (a Assembly) ResolveServices() ResolvedServices

ResolveServices selects the first provider of each factory in assembly order. A legacy factory override can accompany a typed provider or an old named module; alone it does not enable a service (except the standalone code index).

type BrowserToolConfig

type BrowserToolConfig struct {
	Spec         ToolSpec
	Instruction  string
	PluginGate   string
	PrepareArgs  func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
	FormatResult func(ctx context.Context, result engine.ToolResult) engine.ToolResult
}

BrowserToolConfig configures one built-in controller browser tool.

type BuiltInArtifactView

type BuiltInArtifactView struct {
	Reference protocol.PluginReference
	View      protocol.ArtifactView
	Tree      fs.FS
}

BuiltInArtifactView pairs an immutable native artifact owner with its view declaration and embedded resources. It does not grant artifact access.

type BuiltInSkill

type BuiltInSkill struct {
	Package string
	Skill   protocol.PluginSkill
	Tree    fs.FS
}

BuiltInSkill describes a compile-time skill bundled inside a native module.

type CatalogSpec

type CatalogSpec struct {
	Instructions string     `json:"instructions,omitempty"`
	Tools        []ToolSpec `json:"tools"`
}

CatalogSpec pairs optional module-level instructions with its tool specs.

func LoadCatalog

func LoadCatalog(raw []byte) (CatalogSpec, error)

LoadCatalog decodes an embedded module tool catalog and fills default policy, presentation and grouping values.

type CodeIndexServiceProvider

type CodeIndexServiceProvider interface {
	NewCodeIndexService(string, codeindexapi.Watch) codeindexapi.Service
}

type CommandHandler

type CommandHandler interface {
	HandlesCommand(kind string) bool
	ExecuteCommand(ctx context.Context, host Host, caller protocol.NodeID, request protocol.Request) (protocol.Output, []protocol.Event, error)
}

CommandHandler is optionally implemented by native modules that own direct Node protocol commands (such as native memory catalog CRUD).

type ConnectionToolConfig

type ConnectionToolConfig struct {
	Spec            ToolSpec
	Instruction     string
	TurnInstruction prompt.Part
	Captured        []protocol.ConnectionResource
	PrepareArgs     func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
	FormatResult    func(ctx context.Context, preparedArgs json.RawMessage, result engine.ToolResult) engine.ToolResult
}

ConnectionToolConfig configures one native tool backed by a database or SSH connection operation.

type DatabaseServiceProvider

type DatabaseServiceProvider interface {
	ExecuteDatabase(context.Context, store.DatabaseOperation) (protocol.DatabaseOutcome, error)
}

DatabaseServiceProvider supplies the executor for the Node's database commands.

type DispatchProvider

type DispatchProvider interface {
	NativeDispatchNamespace() string
}

DispatchProvider is optionally implemented by native modules that own a persistent Node dispatch namespace (for example scheduled-tasks or reminders) so existing schedules and jobs continue running after legacy plugins retire.

type ExternalBrowserToolConfig

type ExternalBrowserToolConfig struct {
	Spec         ToolSpec
	Instruction  string
	Close        func() error
	PrepareArgs  func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
	FormatResult func(ctx context.Context, result engine.ToolResult) engine.ToolResult
}

ExternalBrowserToolConfig configures one managed Chromium browser tool.

type GitCommandResult

type GitCommandResult struct {
	Stdout, Stderr []byte
	ExitCode       int
	Truncated      bool
	InvalidUTF8    bool
}

type GitOptions

type GitOptions struct {
	Run         GitRunner
	Now         func() time.Time
	Environment []string
	Profile     string
	// Lock covers local Git effects, not waits on a remote transfer.
	Lock func(string) func()
}

GitOptions is the existing injected Git execution boundary. Only a workspace provider that implements Git consumes it.

type GitRunner

type GitRunner func(context.Context, string, []string, []byte) (GitCommandResult, error)

type Host

type Host interface {
	WorkspaceTool(inv *store.AgentInvocation, cfg WorkspaceToolConfig) (engine.Tool, error)
	ScopedTool(inv *store.AgentInvocation, cfg ScopedToolConfig) (engine.Tool, error)
	ConnectionTool(inv *store.AgentInvocation, cfg ConnectionToolConfig) (engine.Tool, error)
	BrowserTool(inv *store.AgentInvocation, cfg BrowserToolConfig) (engine.Tool, error)
	ExternalBrowserTool(inv *store.AgentInvocation, cfg ExternalBrowserToolConfig) (engine.Tool, error)

	HasCodeIndex() bool
	RunWorkspaceOperation(ctx context.Context, inv *store.AgentInvocation, op protocol.ToolOperation, args json.RawMessage) (protocol.Output, error)
	ListLocalModels(ctx context.Context, kind protocol.ModelsKind) ([]protocol.ModelsLocalModel, error)

	ConnectionCatalog(ctx context.Context, inv *store.AgentInvocation) (store.ConnectionCatalog, error)
	CaptureConnectionTargets(inv *store.AgentInvocation, targets []protocol.ConnectionResource)

	BrowserAvailable(inv *store.AgentInvocation) bool
	ExternalBrowserAvailable() bool
	ExternalBrowserEnabled(ctx context.Context) (bool, error)
	ExternalBrowserCloseOnCancel(ctx context.Context, session protocol.SessionID) func() error

	ComputerEnabled(ctx context.Context) (bool, error)
	ConnectComputerMCP(ctx context.Context, inv *store.AgentInvocation, catalog CatalogSpec) ([]engine.Tool, error)

	PluginCaptured(inv *store.AgentInvocation, name string) (protocol.PluginReference, bool)
	PluginInstalled(ctx context.Context, name string) (installed bool, enabled bool, err error)

	PluginStorageGet(ctx context.Context, inv *store.AgentInvocation, namespace, key string) (protocol.PluginStorageEntry, error)
	PluginStorageSearch(ctx context.Context, inv *store.AgentInvocation, namespace string, query protocol.PluginStorageSearch) (protocol.PluginStorageSearchPage, error)
	PluginStorageTransaction(ctx context.Context, inv *store.AgentInvocation, namespace string, ops []protocol.PluginTransactionOperation) ([]protocol.Output, error)
	ConfigureStorageApproval(ctx context.Context, db *sql.Conn, turn protocol.TurnID, value protocol.ConversationApproval) (protocol.ConversationApproval, error)

	// Controller-scoped storage helpers for native module commands (outside an agent turn).
	StorageGet(ctx context.Context, namespace, key string) (protocol.PluginStorageEntry, error)
	StorageListKeys(ctx context.Context, namespace, prefix string, after *string, limit uint16) (protocol.PluginStoragePage, error)
	StorageSearch(ctx context.Context, namespace string, query protocol.PluginStorageSearch) (protocol.PluginStorageSearchPage, error)
	StorageTransaction(ctx context.Context, namespace string, ops []protocol.PluginTransactionOperation) ([]protocol.Output, error)
	StorageDispatch(ctx context.Context, namespace string, action protocol.DispatchCommand) (protocol.DispatchOutput, error)
	StopDispatchTurn(ctx context.Context, namespace string, job protocol.JobID) error

	// Turn-scoped list/dispatch helpers for native module agent tools.
	PluginStorageListKeys(ctx context.Context, inv *store.AgentInvocation, namespace, prefix string, after *string, limit uint16) (protocol.PluginStoragePage, error)
	PluginStorageDispatch(ctx context.Context, inv *store.AgentInvocation, namespace string, action protocol.DispatchCommand) (protocol.DispatchOutput, error)

	LocalNodeID() protocol.NodeID
	Now() time.Time
	ProjectExists(ctx context.Context, id string) (bool, error)
	ReadProjectCatalog(ctx context.Context) (protocol.ProjectsCatalog, error)
	ListTeams(ctx context.Context) ([]protocol.TeamProfile, error)
	ResolveModel(ctx context.Context, model string, effort *protocol.Effort, config *protocol.SessionConfig) (protocol.SessionConfig, error)
	ReadProviderAccountHTTP(ctx context.Context, provider protocol.ProviderID, expectedRevision uint64, namespace string, resolve func(protocol.Authentication) (protocol.PluginModelAuthEndpoint, bool)) (protocol.Authentication, protocol.PluginHttpResponse, error)
	ForwardModuleCommand(ctx context.Context, target protocol.NodeID, command protocol.Command) (protocol.Output, error)
}

Host exposes narrowly scoped Node execution services to native modules.

type Module

type Module interface {
	ID() string
	ReplacesPlugins() []string
	Catalog() []ToolMeta
	ToolsForTurn(ctx context.Context, host Host, inv *store.AgentInvocation) ([]engine.Tool, error)
}

Module is one compile-time native Node feature module.

type ProjectSourcePreparer

type ProjectSourcePreparer func(context.Context, string, protocol.ProjectsSource) (string, error)

type RegisteredModule

type RegisteredModule struct {
	Module
	Services ServiceCapabilities
}

func (RegisteredModule) RuntimeAvailable

func (m RegisteredModule) RuntimeAvailable(running ServiceCapabilities) bool

type RepositoryWatch

type RepositoryWatch struct {
	Open       func(context.Context, string) (RepositoryWatchFilter, []string, error)
	Invalidate func(string)
}

type RepositoryWatchFilter

type RepositoryWatchFilter interface {
	Changed([]string) bool
	ReferencesChanged([]string) bool
}

type ResolvedServices

type ResolvedServices struct {
	Databases             DatabaseExecutor
	SSH                   SSHFactory
	Terminal              TerminalFactory
	CodeIndex             codeindexapi.Factory
	Workspace             []WorkspaceBinder
	WorkspaceCapabilities ServiceCapabilities
	Modules               []RegisteredModule
}

type SSHFactory

type SSHFactory func(SSHServiceOptions) SSHService

type SSHServiceOptions

type SSHServiceOptions struct {
	Context       context.Context
	ReadSSH       func(context.Context, protocol.SshID, uint64) (protocol.SshProfile, protocol.SshCredential, error)
	WorkspaceRoot func(context.Context, protocol.WorktreeID, bool) (string, error)
	Transfers     *files.Transfers
	Terminals     *terminal.Service
	Installations *host.Installations
	Link          func() *link.Link
}

type SSHServiceProvider

type SSHServiceProvider interface {
	NewSSHService(SSHServiceOptions) SSHService
}

SSHServiceProvider supplies the service for the Node's SSH commands.

type ScopedToolConfig

type ScopedToolConfig struct {
	Spec        ToolSpec
	Instruction string
	PrepareArgs func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
}

ScopedToolConfig configures one native tool backed by a scoped Node operation such as local model install/removal.

type ServiceCapabilities

type ServiceCapabilities uint8
const (
	ServiceDatabase ServiceCapabilities = 1 << iota
	ServiceSSH
	ServiceTerminal
	ServiceGit
	ServiceWorktrees
	ServiceCodeIndex
)

type SkillProvider

type SkillProvider interface {
	Skills() []BuiltInSkill
}

SkillProvider is optionally implemented by native modules that ship built-in skills (for example, web-search:research).

type TerminalServiceProvider

type TerminalServiceProvider interface {
	NewTerminalService(context.Context, protocol.NodeID, func(context.Context, protocol.TerminalInfo)) *terminal.Service
}

TerminalServiceProvider supplies the Node's controller terminal service.

type ToolMeta

type ToolMeta struct {
	Name          string                    `json:"name"`
	LegacyPackage string                    `json:"legacy_package,omitempty"`
	LegacyServer  string                    `json:"legacy_server,omitempty"`
	LegacyName    string                    `json:"legacy_name,omitempty"`
	Presentation  protocol.ToolPresentation `json:"presentation,omitempty"`
	Grouping      protocol.ToolGrouping     `json:"grouping,omitempty"`
	Display       *protocol.ToolDisplay     `json:"display,omitempty"`
}

ToolMeta describes presentation, grouping, localized display metadata and legacy package-alias resolution for one native module tool.

func (ToolMeta) LegacyAlias

func (m ToolMeta) LegacyAlias() string

LegacyAlias returns the canonical alias formerly generated when this tool was owned by a bundled plugin package (or plugin MCP server), or an empty string if none applies.

type ToolSpec

type ToolSpec struct {
	Name          string                                `json:"name"`
	LegacyPackage string                                `json:"legacy_package,omitempty"`
	LegacyServer  string                                `json:"legacy_server,omitempty"`
	LegacyName    string                                `json:"legacy_name,omitempty"`
	Description   string                                `json:"description"`
	Operation     protocol.ToolOperation                `json:"operation,omitempty"`
	Action        string                                `json:"action,omitempty"`
	Parameters    json.RawMessage                       `json:"parameters"`
	Initial       bool                                  `json:"initial,omitempty"`
	ReadOnly      bool                                  `json:"read_only,omitempty"`
	Concurrent    bool                                  `json:"concurrent,omitempty"`
	StreamRead    bool                                  `json:"stream_read,omitempty"`
	Contexts      []protocol.PluginConversationResource `json:"contexts,omitempty"`
	Platforms     []string                              `json:"platforms,omitempty"`
	Presentation  protocol.ToolPresentation             `json:"presentation,omitempty"`
	Grouping      protocol.ToolGrouping                 `json:"grouping,omitempty"`
	Display       *protocol.ToolDisplay                 `json:"display,omitempty"`
}

ToolSpec holds the declarative metadata of one native module tool, typically embedded as JSON in the module package.

func (ToolSpec) Available

func (s ToolSpec) Available(inv *store.AgentInvocation) bool

Available reports whether this tool can be offered in the captured turn.

func (ToolSpec) LegacyAlias

func (s ToolSpec) LegacyAlias() string

LegacyAlias returns the former plugin-scoped alias for this tool, if any.

func (ToolSpec) Meta

func (s ToolSpec) Meta() ToolMeta

Meta converts this specification to its static presentation metadata.

func (ToolSpec) SearchLabels

func (s ToolSpec) SearchLabels() []string

SearchLabels returns sorted, deduplicated display labels for tool_search.

type WorkspaceBinder

type WorkspaceBinder func(*WorkspaceRuntime) (WorkspaceBindings, error)

type WorkspaceBindings

type WorkspaceBindings struct {
	Commands             map[string]WorkspaceCommand
	ProjectSources       map[string]ProjectSourcePreparer
	RepositoryWatch      *RepositoryWatch
	CaptureBoundary      func(root string) (string, error)
	StageTurnHunk        func(context.Context, string, protocol.ConversationCheckpointHunkSelection, func(string) (string, error)) (protocol.Output, error)
	RemoveUnusedWorktree func(context.Context, store.ProjectWorktree, func()) (bool, error)
}

type WorkspaceCommand

type WorkspaceCommand struct {
	Lock WorkspaceLock
	// ProjectRoot selects the project's main workspace for commands addressed
	// to a project rather than a worktree.
	ProjectRoot func(protocol.Command) protocol.ProjectID
	Run         func(context.Context, WorkspaceCommandScope, protocol.Command) (protocol.Output, error)
}

WorkspaceCommand runs inside the same authorization, root resolution and durable completion path as core workspace operations.

type WorkspaceCommandScope

type WorkspaceCommandScope interface {
	Root() string
	ProtectEntry(path string) error
	Changed()
	CaptureWorktree(protocol.WorktreeID) (store.ProjectWorktree, error)
	RegisterWorktree(value protocol.Worktree, adopt bool) (protocol.Output, error)
	RemoveWorktree(id protocol.WorktreeID, remove func(path string) error) (protocol.Output, error)
}

type WorkspaceFactory

type WorkspaceFactory[T any] struct {
	Open func(WorkspaceOptions) (T, func() error, error)
}

WorkspaceFactory identifies one shared service. Modules that select the same factory instance bind only their own handlers to that service.

func (*WorkspaceFactory[T]) Bind

func (f *WorkspaceFactory[T]) Bind(bind func(T) WorkspaceBindings) WorkspaceBinder

type WorkspaceLock

type WorkspaceLock uint8
const (
	// WorkspaceLockEffect holds the resolved roots to durable completion.
	WorkspaceLockEffect WorkspaceLock = iota
	// WorkspaceLockLocal leaves locking of individual effect phases to the service.
	WorkspaceLockLocal
	// WorkspaceLockChange holds the roots and advances the registration revision on release.
	WorkspaceLockChange
)

type WorkspaceOptions

type WorkspaceOptions struct {
	Context     context.Context
	Profile     string
	Environment []string
	Lock        func(string) func()
	Git         GitOptions
}

type WorkspaceRuntime

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

WorkspaceRuntime owns the services selected during one Node's startup.

func NewWorkspaceRuntime

func NewWorkspaceRuntime(options WorkspaceOptions) *WorkspaceRuntime

func (*WorkspaceRuntime) Close

func (r *WorkspaceRuntime) Close() error

type WorkspaceServiceProvider

type WorkspaceServiceProvider interface {
	WorkspaceServices() WorkspaceServices
}

type WorkspaceServices

type WorkspaceServices struct {
	Git       bool
	Worktrees bool
	Bind      WorkspaceBinder
}

WorkspaceServices declares a module's capabilities and binds its handlers. A capability by itself does not register commands or start a service.

type WorkspaceToolConfig

type WorkspaceToolConfig struct {
	// FileWritePaths declares that preparation preserves the file targets in the operation arguments.
	FileWritePaths bool
	// ArtifactPackage identifies the compile-time owner of a session artifact operation.
	ArtifactPackage protocol.PluginReference
	Spec            ToolSpec
	Instruction     string
	TurnInstruction prompt.Part
	ContextParts    []string
	PrepareArgs     func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
	FormatResult    func(ctx context.Context, args json.RawMessage, result engine.ToolResult) engine.ToolResult
}

WorkspaceToolConfig configures one native tool backed by a workspace operation.

Jump to

Keyboard shortcuts

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