Documentation
¶
Overview ¶
Package star runs the Starlark script of a plugin for a client: plugin.star at the root and the lib/*.star files it loads. The runtime itself (loading, limits, the call, the settings, log, env and http builtins) is internal/plugin/starcore, which a server-side caller can link; this package adds what only a client has: the command, tool and event kinds (kinds.go), the arguments and results of a call (request.go) and the files and kb modules. It, with starcore, is the only code that imports go.starlark.net (TestStarlarkIsConfined holds it): everything else sees Program, Registration and Check.
See the package comment of starcore for the two phases of a script (LOAD and CALL) and why the modules are late-bound.
Index ¶
Constants ¶
const ( Failed = starcore.Failed Denied = starcore.Denied LimitExceeded = starcore.LimitExceeded Cancelled = starcore.Cancelled Internal = starcore.Internal )
The kinds of failure of a call.
const ( MaxLoadSteps = starcore.MaxLoadSteps MaxCallStepsTool = starcore.MaxCallStepsTool MaxCallStepsCommand = starcore.MaxCallStepsCommand MaxResultBytes = starcore.MaxResultBytes MaxPrintBytes = starcore.MaxPrintBytes MaxHTTPRequests = starcore.MaxHTTPRequests MaxHTTPResponseBytes = starcore.MaxHTTPResponseBytes MaxHTTPRequestBytes = starcore.MaxHTTPRequestBytes MaxHTTPRedirects = starcore.MaxHTTPRedirects HTTPTimeout = starcore.HTTPTimeout MaxRegistrationText = starcore.MaxRegistrationText MaxFileBytes = starcore.MaxFileBytes MaxGlobResults = starcore.MaxGlobResults MaxGlobVisits = starcore.MaxGlobVisits ToolTimeout = starcore.ToolTimeout EventTimeout = starcore.EventTimeout )
The caps of a call, which the tests and the CLI name.
const ( KindCommand = "command" KindTool = "tool" KindEvent = "event" )
Kind of a registration.
Variables ¶
This section is empty.
Functions ¶
func Line ¶ added in v0.29.0
func Line(r Registration, plug string) string
Line is the registration as the preview and `plugin validate` print it, without its position: it is what two versions are compared on.
Types ¶
type Host ¶
type Host struct {
// LookupEnv reads the environment for env.get; nil is os.LookupEnv. The
// manifest's list is checked before it is asked.
LookupEnv func(string) (string, bool)
// Home, ConfigDir and CacheDir place files.*: the home directory every
// path stays under and the user's config and cache directories, whose
// "cartographer" directory is denied. Empty is the OS's.
Home, ConfigDir, CacheDir string
// KB reaches the KB's tools for kb.call; nil means no KB is reachable
// (kb.call fails, saying so).
KB KBCaller
}
Host is what a call may reach outside the interpreter: the adapters of the capability modules.
type KBCaller ¶
type KBCaller interface {
// Call runs a tool and returns the text of its result; a tool that
// answers with an error returns it as the error.
Call(ctx context.Context, tool string, args map[string]any) (string, error)
// ReadOnly reports whether the server annotates the tool read-only. An
// unknown tool is false, never an error: absent annotation means write.
ReadOnly(ctx context.Context, tool string) (bool, error)
}
KBCaller is what kb.call reaches: the KB's tools through one adapter per surface (the command line and the bridge). Both must be built on the same read-only decision, the server's own annotation: see MCPKB.
type MCPKB ¶
type MCPKB struct {
// contains filtered or unexported fields
}
MCPKB is the KBCaller over an MCP client: both surfaces build it, so the read-only decision (the server's tools/list annotation, kept for toolsTTL) exists once. The script passes `kb` itself, as every routed tool requires; it is not restricted here, the server's token scopes and session KB set are.
func NewMCPKB ¶
func NewMCPKB(c ToolClient) *MCPKB
type Program ¶
Program is a loaded plugin script for a client: the runtime's script and the call of its command, tool and event registrations.
func Load ¶
Load runs plugin.star once, with lib/*.star loadable from it, and reports what it registered. It reads the files it is given and nothing else. A tree without plugin.star and without lib/ is not a script plugin: (nil, nil).
type Registration ¶
type Registration = starcore.Registration
Registration is one contribution the script made while loading.
type Request ¶
type Request struct {
Kind string // KindCommand, KindTool or KindEvent
Name string // the command or tool name, or the event
Plugin string // the plugin's name, for the log prefix
// Version is the plugin's version, sent in http.request's User-Agent.
Version string
// Args are a command's arguments; Params a tool's arguments, a JSON
// object validated against the tool's schema; Event the fields of an
// event's ctx.
Args []string
Params json.RawMessage
Event map[string]any
// ReadOnly is a read-only session: files.write and files.remove are
// denied and kb.call is limited to read-only tools, whatever the manifest
// grants.
ReadOnly bool
// KBReadOnly limits kb.call to read-only tools without touching files.*: a
// tool registered writes=False is advertised read-only to the client, so it
// must not write through the KB whatever the manifest grants.
KBReadOnly bool
// Permissions are the manifest's, nil for none.
Permissions *core.Permissions
// Declared are the manifest's settings and Values the user's; Call types
// them, applies the defaults and hands the script `settings`.
Declared map[string]core.Setting
Values map[string]any
Host Host
// Stdout receives a command's print; Log receives log.* and, for a tool
// or an event, print (a bridge's stdout is protocol). Nil discards.
Stdout, Log io.Writer
}
Request is one call of a registered function.