invoke

package
v0.0.0-...-c671013 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 19 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 invoke owns the generic-invoke core path: it builds Plans from resolved target + contract + args, and it executes them through the pure-Go direct transport. The planning half remains independently testable, so dryRun never needs a runtime.

Index

Constants

View Source
const (
	EnvAllowInvoke                   = "SOFARPC_ALLOW_INVOKE"
	EnvAllowTargetOverride           = "SOFARPC_ALLOW_TARGET_OVERRIDE"
	EnvAllowedTargetHosts            = "SOFARPC_ALLOWED_TARGET_HOSTS"
	EnvMaxConcurrentInvokes          = "SOFARPC_MAX_CONCURRENT_INVOKES"
	EnvMaxConcurrentInvokesPerTarget = "SOFARPC_MAX_CONCURRENT_INVOKES_PER_TARGET"
	EnvInvokeQueueTimeoutMS          = "SOFARPC_INVOKE_QUEUE_TIMEOUT_MS"
)
View Source
const (
	DirectTransportName = "direct-bolt"
)
View Source
const PlanSchemaVersion = "sofarpc.invoke.plan/v2"

Variables

This section is empty.

Functions

func EnvFlag

func EnvFlag(name string) bool

EnvFlag reports whether the named guardrail environment variable is set to a true value, using strict strconv.ParseBool semantics. Every execution entrypoint (MCP tools, the call CLI) must parse opt-ins through this single helper so an env value can never enable one path that another refuses.

func EnvList

func EnvList(name string) []string

EnvList returns the comma-separated values of the named environment variable with whitespace trimmed and empty items dropped.

func IsContractUnresolvable

func IsContractUnresolvable(err error) bool

IsContractUnresolvable reports whether err, anywhere in its chain, is the contract.unresolvable rejection that lets auto contract mode fall back to trusted execution.

func SameDirectTarget

func SameDirectTarget(left, right string) (bool, error)

func TargetHintArgs

func TargetHintArgs(sources target.Sources) map[string]any

TargetHintArgs builds the sofarpc_target arguments that send an agent to the resolved layer breakdown, scoped to the project when one is known.

func TrustedTupleComplete

func TrustedTupleComplete(service, method string, paramTypes []string, args any) bool

TrustedTupleComplete reports whether the caller supplied everything a trusted plan needs without a contract: service, method, parameter types, and args.

func ValidateExecutablePlan

func ValidateExecutablePlan(plan Plan, phase string) error

ValidateExecutablePlan applies replay-safe plan invariants plus the current pure-Go transport and argument rules before touching the wire layer.

func ValidatePlanSchema

func ValidatePlanSchema(plan Plan, phase string) error

ValidatePlanSchema rejects payload/session plans produced by incompatible future or pre-versioned plan shapes. Replay callers should run this before dry-run output or execution so unknown payloads are never treated as valid.

func ValidateReplayPlan

func ValidateReplayPlan(plan Plan, phase string) error

ValidateReplayPlan rejects captured or literal plans that cannot be safely replayed. It owns the stable plan invariants so MCP session replay and literal payload replay fail with the same structured errors.

func ValidateTargetResolved

func ValidateTargetResolved(cfg target.Config, phase string) error

ValidateTargetResolved rejects when no config layer produced a target to execute against. It is the single owner of the "nothing resolved" rule: BuildPlan and doctor both route here so agents read one message.

func ValidateTargetTransport

func ValidateTargetTransport(cfg target.Config, phase string) error

ValidateTargetTransport rejects a resolved target the pure-Go transport cannot execute. It is the single owner of the supported-transport rule: Execute applies it on the wire path, doctor previews it.

Types

type DirectExecution

type DirectExecution struct {
	Handled     bool
	Result      any
	Diagnostics map[string]any
}

func ExecuteDirectIfPossible

func ExecuteDirectIfPossible(ctx context.Context, plan Plan, phase string) (DirectExecution, error)

ExecuteDirectIfPossible runs a plan through the pure-Go direct transport when the target is a supported direct+bolt shape. Unsupported targets return Handled=false so callers can fall back to the worker path.

type ExecutionPolicy

type ExecutionPolicy struct {
	AllowInvoke         bool
	AllowTargetOverride bool
	AllowedTargetHosts  []string
	Sources             target.Sources
	// RequestedProfile comes from the live call context. Replay leaves it empty.
	RequestedProfile string
}

ExecutionPolicy is the core invoke guardrail. It keeps real-invoke enablement and target checks behind one interface so invoke and replay enforce the same rules.

func (ExecutionPolicy) Diagnostics

func (ExecutionPolicy) DirectTargetHostAllowed

func (p ExecutionPolicy) DirectTargetHostAllowed(directURL string) (bool, string, error)

func (ExecutionPolicy) Preflight

func (p ExecutionPolicy) Preflight(plan Plan, phase string) Preflight

Preflight checks the plan without acquiring an invocation slot or opening a connection.

func (ExecutionPolicy) Validate

func (p ExecutionPolicy) Validate(plan Plan, phase string) error

func (ExecutionPolicy) ValidateProjectConfig

func (p ExecutionPolicy) ValidateProjectConfig(phase string) error

func (ExecutionPolicy) ValidateRealInvokeEnabled

func (p ExecutionPolicy) ValidateRealInvokeEnabled(phase string) error

ValidateRealInvokeEnabled rejects when real invocation has not been enabled.

func (ExecutionPolicy) ValidateTarget

func (p ExecutionPolicy) ValidateTarget(plan Plan, phase string) error

type ExecutionPolicyDiagnostics

type ExecutionPolicyDiagnostics struct {
	AllowInvoke         bool     `json:"allowInvoke"`
	AllowTargetOverride bool     `json:"allowTargetOverride"`
	AllowedTargetHosts  []string `json:"allowedTargetHosts,omitempty"`
}

type Input

type Input struct {
	Service              string
	Method               string
	ParamTypes           []string
	Args                 any
	Version              string
	TargetAppName        string
	Target               target.Input
	InvocationProperties invocationprops.Declarations
}

Input is what sofarpc_invoke passes in. Target fields are merged into target.Sources via target.Resolve — BuildPlan does that internally.

type Outcome

type Outcome struct {
	Result      any
	Diagnostics map[string]any
}

func Execute

func Execute(ctx context.Context, plan Plan, phase string) (Outcome, error)

Execute runs a plan through the pure-Go direct transport. Plans that don't match the supported direct shape fail with a structured error.

type Plan

type Plan struct {
	SchemaVersion        string                       `json:"schemaVersion"`
	Service              string                       `json:"service"`
	Method               string                       `json:"method"`
	ParamTypes           []string                     `json:"paramTypes"`
	ReturnType           string                       `json:"returnType,omitempty"`
	Args                 []any                        `json:"args"`
	Version              string                       `json:"version,omitempty"`
	TargetAppName        string                       `json:"targetAppName,omitempty"`
	Target               target.Config                `json:"target"`
	InvocationProperties invocationprops.Declarations `json:"invocationProperties,omitempty"`
	Overloads            []javamodel.Method           `json:"overloads,omitempty"`
	Selected             int                          `json:"selected"`
	ContractSource       string                       `json:"contractSource,omitempty"`
	TargetLayers         []target.Layer               `json:"targetLayers,omitempty"`
	ArgSource            string                       `json:"argSource,omitempty"`
	// Profile records the Active Target Profile this plan was built under, for
	// replay provenance. It is additive to the v2 schema (omitempty) and does
	// not affect replay: the resolved Target and InvocationProperties are
	// already frozen above, so replay executes them verbatim.
	Profile string `json:"profile,omitempty"`
}

Plan is the replayable invocation payload plus diagnostics. Env-backed InvocationProperties stay redacted in the plan and are resolved immediately before a real invoke/replay touches the wire.

func BuildPlan

func BuildPlan(in Input, facade contract.Store, sources target.Sources) (Plan, error)

BuildPlan resolves target + contract + args and returns a Plan. It never performs I/O — callers have already materialised target.Sources and plugged a contract.Store.

Two modes:

  • facade-store: facade != nil, standard path with overload disambiguation and skeleton rendering.
  • trusted: facade == nil, the agent supplies a complete service/method/paramTypes/args tuple and we hand it straight to the direct transport. The agent is expected to know the wire shape from elsewhere (IDL, prior describe output, etc.).

Failure modes (all *errcode.Error):

  • target.missing: no layer supplied a target mode.
  • workspace.facade-not-configured: trusted mode is missing paramTypes or args — without a facade we cannot synthesize either.
  • contract.*: propagated from contract.ResolveMethod (facade mode only).
  • input.args-invalid: args provided with the wrong arity.

type Preflight

type Preflight struct {
	Ready          bool           `json:"ready"`
	PolicyError    *errcode.Error `json:"policyError,omitempty"`
	ExecutionError *errcode.Error `json:"executionError,omitempty"`
}

Preflight reports the local policy and plan checks for a dry-run.

Jump to

Keyboard shortcuts

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