kit

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 4 Imported by: ? 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 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

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

func Run

func Run(script string, opts ...Option) (starlet.StringAnyMap, error)

Run is the package-level one-liner for a build-your-own shell: it wires a default-named box from the options and runs the embedded script source.

func RunFS

func RunFS(fsys fs.FS, entry string, opts ...Option) (starlet.StringAnyMap, error)

RunFS is the package-level one-liner that runs entry out of fsys (typically an embed.FS of .star files), so a shell can ship a whole tree of scripts.

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

func New(name string, opts ...Option) *Kit

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

func (k *Kit) Box() (*starbox.Starbox, error)

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.

func (*Kit) Run

func (k *Kit) Run(script string) (starlet.StringAnyMap, error)

Run constructs the box and executes the given script source.

func (*Kit) RunFile

func (k *Kit) RunFile(file string) (starlet.StringAnyMap, error)

RunFile constructs the box and executes a script file read from the configured filesystem (see WithFS).

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

func WithFS(fsys fs.FS) Option

WithFS sets the filesystem the script's load() statements and RunFile read from — typically an embed.FS of .star files.

func WithGlobal

func WithGlobal(key string, value interface{}) Option

WithGlobal injects a single host value as a script global.

func WithGlobalReassign

func WithGlobalReassign(on bool) Option

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

func WithMaxOutputEntries(n uint) Option

WithMaxOutputEntries caps the number of top-level result entries a run may produce (0 = unlimited).

func WithMaxSteps

func WithMaxSteps(n uint64) Option

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

func WithModules(names ...string) Option

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

func WithOutputConversion(on bool) Option

WithOutputConversion toggles whether Run results are converted to native Go values (on by default). Turn it off to keep raw Starlark values.

func WithPolicy

func WithPolicy(p starbox.Policy) Option

WithPolicy installs a starbox load-gate policy (the host-only capability allowlist). Without it, every wired module is loadable.

func WithPrintFunc

func WithPrintFunc(pf starlet.PrintFunc) Option

WithPrintFunc overrides how the script's print() output is rendered. Without it, starbox's default timestamped stderr printer is used.

func WithRecursion

func WithRecursion(on bool) Option

WithRecursion toggles recursion support in the script dialect.

Jump to

Keyboard shortcuts

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