{"modulePath":"github.com/hex1n/sofarpc-cli","version":"v0.0.0-20261202072051-c67101320811","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package invoke\n\nPackage 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.\n\n## Constants\n\n```go\nconst (\n\tEnvAllowInvoke                   = \"SOFARPC_ALLOW_INVOKE\"\n\tEnvAllowTargetOverride           = \"SOFARPC_ALLOW_TARGET_OVERRIDE\"\n\tEnvAllowedTargetHosts            = \"SOFARPC_ALLOWED_TARGET_HOSTS\"\n\tEnvMaxConcurrentInvokes          = \"SOFARPC_MAX_CONCURRENT_INVOKES\"\n\tEnvMaxConcurrentInvokesPerTarget = \"SOFARPC_MAX_CONCURRENT_INVOKES_PER_TARGET\"\n\tEnvInvokeQueueTimeoutMS          = \"SOFARPC_INVOKE_QUEUE_TIMEOUT_MS\"\n)\n```\n\n```go\nconst (\n\tDirectTransportName = \"direct-bolt\"\n)\n```\n\n```go\nconst PlanSchemaVersion = \"sofarpc.invoke.plan/v2\"\n```\n\n## Functions\n\n```go\nfunc EnvFlag(name string) bool\n```\nEnvFlag 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.\n\n```go\nfunc EnvList(name string) []string\n```\nEnvList returns the comma-separated values of the named environment variable with whitespace trimmed and empty items dropped.\n\n```go\nfunc IsContractUnresolvable(err error) bool\n```\nIsContractUnresolvable reports whether err, anywhere in its chain, is the contract.unresolvable rejection that lets auto contract mode fall back to trusted execution.\n\n```go\nfunc SameDirectTarget(left, right string) (bool, error)\n```\n\n```go\nfunc TargetHintArgs(sources target.Sources) map[string]any\n```\nTargetHintArgs builds the sofarpc\\_target arguments that send an agent to the resolved layer breakdown, scoped to the project when one is known.\n\n```go\nfunc TrustedTupleComplete(service, method string, paramTypes []string, args any) bool\n```\nTrustedTupleComplete reports whether the caller supplied everything a trusted plan needs without a contract: service, method, parameter types, and args.\n\n```go\nfunc ValidateExecutablePlan(plan Plan, phase string) error\n```\nValidateExecutablePlan applies replay-safe plan invariants plus the current pure-Go transport and argument rules before touching the wire layer.\n\n```go\nfunc ValidatePlanSchema(plan Plan, phase string) error\n```\nValidatePlanSchema 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.\n\n```go\nfunc ValidateReplayPlan(plan Plan, phase string) error\n```\nValidateReplayPlan 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.\n\n```go\nfunc ValidateTargetResolved(cfg target.Config, phase string) error\n```\nValidateTargetResolved 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.\n\n```go\nfunc ValidateTargetTransport(cfg target.Config, phase string) error\n```\nValidateTargetTransport 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.\n\n## Types\n\n```go\ntype DirectExecution struct {\n\tHandled     bool\n\tResult      any\n\tDiagnostics map[string]any\n}\n```\n\n```go\nfunc ExecuteDirectIfPossible(ctx context.Context, plan Plan, phase string) (DirectExecution, error)\n```\nExecuteDirectIfPossible 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.\n\n```go\ntype ExecutionPolicy struct {\n\tAllowInvoke         bool\n\tAllowTargetOverride bool\n\tAllowedTargetHosts  []string\n\tSources             target.Sources\n\t// RequestedProfile comes from the live call context. Replay leaves it empty.\n\tRequestedProfile string\n}\n```\nExecutionPolicy is the core invoke guardrail. It keeps real-invoke enablement and target checks behind one interface so invoke and replay enforce the same rules.\n\n```go\nfunc (p ExecutionPolicy) Diagnostics() ExecutionPolicyDiagnostics\n```\n\n```go\nfunc (p ExecutionPolicy) DirectTargetHostAllowed(directURL string) (bool, string, error)\n```\n\n```go\nfunc (p ExecutionPolicy) Preflight(plan Plan, phase string) Preflight\n```\nPreflight checks the plan without acquiring an invocation slot or opening a connection.\n\n```go\nfunc (p ExecutionPolicy) Validate(plan Plan, phase string) error\n```\n\n```go\nfunc (p ExecutionPolicy) ValidateProjectConfig(phase string) error\n```\n\n```go\nfunc (p ExecutionPolicy) ValidateRealInvokeEnabled(phase string) error\n```\nValidateRealInvokeEnabled rejects when real invocation has not been enabled.\n\n```go\nfunc (p ExecutionPolicy) ValidateTarget(plan Plan, phase string) error\n```\n\n```go\ntype ExecutionPolicyDiagnostics struct {\n\tAllowInvoke         bool     `json:\"allowInvoke\"`\n\tAllowTargetOverride bool     `json:\"allowTargetOverride\"`\n\tAllowedTargetHosts  []string `json:\"allowedTargetHosts,omitempty\"`\n}\n```\n\n```go\ntype Input struct {\n\tService              string\n\tMethod               string\n\tParamTypes           []string\n\tArgs                 any\n\tVersion              string\n\tTargetAppName        string\n\tTarget               target.Input\n\tInvocationProperties invocationprops.Declarations\n}\n```\nInput is what sofarpc\\_invoke passes in. Target fields are merged into target.Sources via target.Resolve — BuildPlan does that internally.\n\n```go\ntype Outcome struct {\n\tResult      any\n\tDiagnostics map[string]any\n}\n```\n\n```go\nfunc Execute(ctx context.Context, plan Plan, phase string) (Outcome, error)\n```\nExecute runs a plan through the pure-Go direct transport. Plans that don't match the supported direct shape fail with a structured error.\n\n```go\ntype Plan struct {\n\tSchemaVersion        string                       `json:\"schemaVersion\"`\n\tService              string                       `json:\"service\"`\n\tMethod               string                       `json:\"method\"`\n\tParamTypes           []string                     `json:\"paramTypes\"`\n\tReturnType           string                       `json:\"returnType,omitempty\"`\n\tArgs                 []any                        `json:\"args\"`\n\tVersion              string                       `json:\"version,omitempty\"`\n\tTargetAppName        string                       `json:\"targetAppName,omitempty\"`\n\tTarget               target.Config                `json:\"target\"`\n\tInvocationProperties invocationprops.Declarations `json:\"invocationProperties,omitempty\"`\n\tOverloads            []javamodel.Method           `json:\"overloads,omitempty\"`\n\tSelected             int                          `json:\"selected\"`\n\tContractSource       string                       `json:\"contractSource,omitempty\"`\n\tTargetLayers         []target.Layer               `json:\"targetLayers,omitempty\"`\n\tArgSource            string                       `json:\"argSource,omitempty\"`\n\t// Profile records the Active Target Profile this plan was built under, for\n\t// replay provenance. It is additive to the v2 schema (omitempty) and does\n\t// not affect replay: the resolved Target and InvocationProperties are\n\t// already frozen above, so replay executes them verbatim.\n\tProfile string `json:\"profile,omitempty\"`\n}\n```\nPlan 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.\n\n```go\nfunc BuildPlan(in Input, facade contract.Store, sources target.Sources) (Plan, error)\n```\nBuildPlan resolves target + contract + args and returns a Plan. It never performs I/O — callers have already materialised target.Sources and plugged a contract.Store.\n\nTwo modes:\n\n  - facade-store: facade != nil, standard path with overload disambiguation and skeleton rendering.\n  - 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.).\n\nFailure modes (all \\*errcode.Error):\n\n  - target.missing: no layer supplied a target mode.\n  - workspace.facade-not-configured: trusted mode is missing paramTypes or args — without a facade we cannot synthesize either.\n  - contract.\\*: propagated from contract.ResolveMethod (facade mode only).\n  - input.args-invalid: args provided with the wrong arity.\n\n```go\ntype Preflight struct {\n\tReady          bool           `json:\"ready\"`\n\tPolicyError    *errcode.Error `json:\"policyError,omitempty\"`\n\tExecutionError *errcode.Error `json:\"executionError,omitempty\"`\n}\n```\nPreflight reports the local policy and plan checks for a dry-run.\n\n","path":"github.com/hex1n/sofarpc-cli/internal/core/invoke","name":"invoke","synopsis":"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.","isRedistributable":true}
