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
- func EnvFlag(name string) bool
- func EnvList(name string) []string
- func IsContractUnresolvable(err error) bool
- func SameDirectTarget(left, right string) (bool, error)
- func TargetHintArgs(sources target.Sources) map[string]any
- func TrustedTupleComplete(service, method string, paramTypes []string, args any) bool
- func ValidateExecutablePlan(plan Plan, phase string) error
- func ValidatePlanSchema(plan Plan, phase string) error
- func ValidateReplayPlan(plan Plan, phase string) error
- func ValidateTargetResolved(cfg target.Config, phase string) error
- func ValidateTargetTransport(cfg target.Config, phase string) error
- type DirectExecution
- type ExecutionPolicy
- func (p ExecutionPolicy) Diagnostics() ExecutionPolicyDiagnostics
- func (p ExecutionPolicy) DirectTargetHostAllowed(directURL string) (bool, string, error)
- func (p ExecutionPolicy) Preflight(plan Plan, phase string) Preflight
- func (p ExecutionPolicy) Validate(plan Plan, phase string) error
- func (p ExecutionPolicy) ValidateProjectConfig(phase string) error
- func (p ExecutionPolicy) ValidateRealInvokeEnabled(phase string) error
- func (p ExecutionPolicy) ValidateTarget(plan Plan, phase string) error
- type ExecutionPolicyDiagnostics
- type Input
- type Outcome
- type Plan
- type Preflight
Constants ¶
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" )
const (
DirectTransportName = "direct-bolt"
)
const PlanSchemaVersion = "sofarpc.invoke.plan/v2"
Variables ¶
This section is empty.
Functions ¶
func EnvFlag ¶
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 ¶
EnvList returns the comma-separated values of the named environment variable with whitespace trimmed and empty items dropped.
func IsContractUnresolvable ¶
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 TargetHintArgs ¶
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 ¶
TrustedTupleComplete reports whether the caller supplied everything a trusted plan needs without a contract: service, method, parameter types, and args.
func ValidateExecutablePlan ¶
ValidateExecutablePlan applies replay-safe plan invariants plus the current pure-Go transport and argument rules before touching the wire layer.
func ValidatePlanSchema ¶
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 ¶
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 ¶
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.
Types ¶
type DirectExecution ¶
func ExecuteDirectIfPossible ¶
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 (p ExecutionPolicy) Diagnostics() ExecutionPolicyDiagnostics
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) 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 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 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 ¶
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.