Documentation
¶
Overview ¶
Package kit builds a starbox runtime for embedded Starlark scripts with host-selected modules and runtime options.
The standard CLI and custom shells share this construction path. Matching behavior requires matching modules, options, capability policies, and dependency versions. New starts with an empty module set. WithPolicy installs the host's module policy.
A custom shell registers the modules its scripts need. The selected Go module graph can also include requirements of the parent starcli module.
//go:embed app.star
var app string
func main() {
if _, err := kit.Run(app, kit.WithModules("json", "math")); err != nil {
log.Fatal(err)
}
}
Index ¶
- Constants
- func Run(script string, opts ...Option) (starlet.StringAnyMap, error)
- func RunFS(fsys fs.FS, entry string, opts ...Option) (starlet.StringAnyMap, error)
- type Kit
- type Option
- func WithDynamicLoader(loader starbox.DynamicModuleLoader) Option
- func WithFS(fsys fs.FS) Option
- func WithGlobal(key string, value interface{}) Option
- func WithGlobalReassign(on bool) Option
- func WithGlobals(g starlet.StringAnyMap) Option
- func WithLoader(name string, loader starlet.ModuleLoader) Option
- func WithLogger(l *zap.SugaredLogger) Option
- func WithMaxOutputEntries(n uint) Option
- func WithMaxSteps(n uint64) Option
- func WithModuleSet(set starbox.ModuleSetName) Option
- func WithModules(names ...string) Option
- func WithOutputConversion(on bool) Option
- func WithPolicy(p starbox.Policy) Option
- func WithPrintFunc(pf starlet.PrintFunc) Option
- func WithRecursion(on bool) Option
Constants ¶
const DefaultName = "app"
DefaultName is the box name used by the package-level Run / RunFS helpers when no explicit name is given.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Kit ¶
type Kit struct {
// contains filtered or unexported fields
}
Kit holds the configuration for a starbox runtime. Build one with New and a set of Option values, then call Box, Run, or RunFile. The zero value is not usable; always go through New.
func New ¶
New returns a Kit for a box with the given name, applying the options. The defaults match a clean, predictable runtime: the empty module set (nothing is loaded unless asked via WithModules / WithLoader / WithDynamicLoader), output conversion on (Run results come back as native Go values), and global reassignment, recursion, and execution budgets all off/unlimited.
func (*Kit) Box ¶
Box constructs the configured *starbox.Starbox. Module names resolve in starbox's order — starlet builtins first, then explicit WithLoader entries, then the WithDynamicLoader fallback — so the same name list works whether a shell wires modules one by one or through a registry.
type Option ¶
type Option func(*Kit)
Option configures a Kit.
func WithDynamicLoader ¶
func WithDynamicLoader(loader starbox.DynamicModuleLoader) Option
WithDynamicLoader registers a single loader that resolves any requested module name on demand — the way the standard starcli exposes its whole module registry. Names listed in WithModules that are neither builtins nor explicit loaders are resolved through it.
func WithFS ¶
WithFS sets the filesystem the script's load() statements and RunFile read from — typically an embed.FS of .star files.
func WithGlobal ¶
WithGlobal injects a single host value as a script global.
func WithGlobalReassign ¶
WithGlobalReassign toggles top-level global reassignment in the script dialect.
func WithGlobals ¶
func WithGlobals(g starlet.StringAnyMap) Option
WithGlobals injects host values as script globals.
func WithLoader ¶
func WithLoader(name string, loader starlet.ModuleLoader) Option
WithLoader registers an explicit loader for a module name — the way a build- your-own shell wires a specific starpkg module it imports, e.g. WithLoader(qrcode.ModuleName, qrcode.NewModule().LoadModule()). A registered loader is always loaded; it does not also need to appear in WithModules.
func WithLogger ¶
func WithLogger(l *zap.SugaredLogger) Option
WithLogger routes the script's log module to the given zap logger.
func WithMaxOutputEntries ¶
WithMaxOutputEntries caps the number of top-level result entries a run may produce (0 = unlimited).
func WithMaxSteps ¶
WithMaxSteps bounds a single run to n Starlark execution steps (0 = unlimited), a guard against runaway loops a wall-clock timeout cannot stop.
func WithModuleSet ¶
func WithModuleSet(set starbox.ModuleSetName) Option
WithModuleSet selects a predefined starbox module set (EmptyModuleSet by default). WithModules still adds individual modules on top of the set.
func WithModules ¶
WithModules names modules to load. A name that is a starlet builtin (e.g. "json", "math") resolves on its own; any other name must be backed by a loader registered via WithLoader or WithDynamicLoader.
func WithOutputConversion ¶
WithOutputConversion toggles whether Run results are converted to native Go values (on by default). Turn it off to keep raw Starlark values.
func WithPolicy ¶
WithPolicy installs a starbox load-gate policy (the host-only capability allowlist). Without it, every wired module is loadable.
func WithPrintFunc ¶
WithPrintFunc overrides how the script's print() output is rendered. Without it, starbox's default timestamped stderr printer is used.
func WithRecursion ¶
WithRecursion toggles recursion support in the script dialect.