star

package
v0.29.2 Latest Latest
Warning

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

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

View Source
const (
	Failed        = starcore.Failed
	Denied        = starcore.Denied
	LimitExceeded = starcore.LimitExceeded
	Cancelled     = starcore.Cancelled
	Internal      = starcore.Internal
)

The kinds of failure of a call.

View Source
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.

View Source
const (
	KindCommand = "command"
	KindTool    = "tool"
	KindEvent   = "event"
)

Kind of a registration.

Variables

This section is empty.

Functions

func Check

func Check(side core.Side, files []core.TreeFile) []string

Check is core.Options.CheckScripts: the problems of a tree's scripts.

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 CallError

type CallError = starcore.CallError

CallError is what Call returns when the call did not succeed.

type ErrKind

type ErrKind = starcore.ErrKind

ErrKind is how a call failed.

type File

type File = starcore.File

File is a script file of the tree.

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 LoadError

type LoadError = starcore.LoadError

LoadError is a script that does not load, with the position of the failure.

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

func (*MCPKB) Call

func (m *MCPKB) Call(ctx context.Context, tool string, args map[string]any) (string, error)

Call abandons the request when the call's context ends, so a write is not left running after the script was told the call failed.

func (*MCPKB) ReadOnly

func (m *MCPKB) ReadOnly(ctx context.Context, tool string) (bool, error)

ReadOnly answers from the list, refetching it when it is older than toolsTTL or does not know the tool (a tool added since); a tool still unknown after a fresh fetch is a write.

type Program

type Program struct {
	*starcore.Script
}

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

func Load(files []core.TreeFile) (*Program, error)

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).

func (*Program) Call

func (p *Program) Call(ctx context.Context, req Request) (Result, error)

Call runs one registered function on a fresh thread and returns its result. The error, when there is one, is a *CallError. Calls are independent: they share only the program's sources.

func (*Program) Lines

func (p *Program) Lines(plug string) []string

Lines are the registrations in the order Sorted lists them.

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.

type Result

type Result struct {
	// Text is a tool's result text, or a command's printed string.
	Text string
	// ExitCode is a command's exit code.
	ExitCode int
}

Result is what a call returned.

type ToolClient

type ToolClient interface {
	CallContext(ctx context.Context, tool string, args any) (json.RawMessage, error)
	ListToolsContext(ctx context.Context) ([]client.ToolInfo, error)
}

ToolClient is the part of client.MCPClient that MCPKB uses.

Jump to

Keyboard shortcuts

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