Documentation
¶
Index ¶
- Constants
- Variables
- func ClearCache(cacheDir string) error
- func DefaultCacheDir() (string, error)
- func Fetch(source string, insecure bool) ([]byte, error)
- func FetchFile(path string, maxSize ...int64) ([]byte, error)
- func FetchWithCache(source string, insecure bool, cacheDir string, maxSize ...int64) ([]byte, error)
- func HashBytes(data []byte) string
- func IsURL(source string) bool
- func NewPackageLibrary(loader *Loader) *object.Library
- func Pack(srcDir, dst string, force bool) (string, []string, error)
- func PruneCache(cacheDir string, ttl time.Duration) error
- func RegisterPackageLibrary(p interface{ ... }, loader *Loader)
- func Unpack(src string, opts UnpackOptions) error
- func UnpackRemove(src string, insecure bool, destDir string) error
- type Bundle
- type DirDocReader
- type DocReader
- type Loader
- func (l *Loader) AddBundle(b *Bundle) error
- func (l *Loader) AddFromPath(source string, insecure bool) error
- func (l *Loader) BundleByName(name string) *Bundle
- func (l *Loader) BundleNames() []string
- func (l *Loader) Bundles() []*Bundle
- func (l *Loader) Description() string
- func (l *Loader) Load(name string) (string, bool, error)
- func (l *Loader) ResolveMain() (entry MainEntry, found bool, err error)
- func (l *Loader) SetCacheDir(dir string)
- func (l *Loader) SetFallback(fallback libloader.LibraryLoader)
- type MainEntry
- type Manifest
- type Package
- type UnpackOptions
- type ZipDocReader
Constants ¶
const ( DefaultMaxPackageSize int64 = 100 * 1024 * 1024 // 100MB DefaultCacheTTL = 7 * 24 * time.Hour // 7 days )
const ( Extension = ".zip" ManifestFile = "manifest.toml" LibDir = "lib" DocsDir = "docs" )
const PackageLibraryName = "scriptling.package"
Variables ¶
var ( ErrInvalidPackage = errors.New("invalid package format") ErrMissingManifest = errors.New("missing manifest.toml") ErrInvalidManifest = errors.New("invalid manifest format") ErrModuleNotFound = errors.New("module not found in package") ErrFetchFailed = errors.New("failed to fetch package") )
Functions ¶
func ClearCache ¶
ClearCache removes all cached packages from cacheDir. If cacheDir is empty, uses the OS default cache directory.
func DefaultCacheDir ¶
DefaultCacheDir returns the default cache directory for packages.
func Fetch ¶
Fetch loads bytes from a URL or local path. For URLs, uses the cache with ETag/Last-Modified freshness checks.
func FetchWithCache ¶
func FetchWithCache(source string, insecure bool, cacheDir string, maxSize ...int64) ([]byte, error)
FetchWithCache loads bytes from a URL or local path, using cacheDir for remote URLs. If cacheDir is empty, uses the OS default cache directory. An optional #sha256=<hex> fragment on source is stripped before fetching and used to verify the downloaded bytes; a mismatch is a fatal error. maxSize limits download size (0 = use DefaultMaxPackageSize).
func NewPackageLibrary ¶ added in v0.19.0
NewPackageLibrary builds the scriptling.package library bound to the given loader. Exposed so embedders and tests can register it on a custom registrar or inspect it directly.
func Pack ¶
Pack creates a package from srcDir, writing to dst. Use force to overwrite an existing dst. Returns the SHA-256 hex hash of the written package and a list of warnings for skipped files.
Inclusion is manifest-driven: manifest.toml, every dir in libs, the main script file (when main names a .py file), and the convention dirs (tools/, resources/, prompts/, webroot/, docs/) when present. Dotfiles are skipped silently; anything else at the top level produces a warning.
A libs dir listed in the manifest but missing, or a main script file that does not exist, is a build error.
func PruneCache ¶
PruneCache removes cache entries that have not been accessed within ttl. If cacheDir is empty, uses the OS default cache directory. If ttl is 0, uses DefaultCacheTTL. Each cache entry is a .zip/.meta pair; the .zip mod time tracks last access.
func RegisterPackageLibrary ¶ added in v0.18.0
RegisterPackageLibrary registers the scriptling.package library on the given Scriptling instance. Convenience wrapper around NewPackageLibrary.
func Unpack ¶
func Unpack(src string, opts UnpackOptions) error
Unpack extracts a package from a local path or URL.
Types ¶
type Bundle ¶ added in v0.18.0
type Bundle struct {
Manifest Manifest
// contains filtered or unexported fields
}
Bundle is an application bundle: a manifest plus an fs.FS over the bundle contents. Two equivalent backends exist — a development folder on disk (os.DirFS) and a built .zip artifact (zipFS). Both read entirely on demand; no file content is held in memory between calls except the manifest.
func FetchBundle ¶ added in v0.18.0
FetchBundle opens a bundle from a local directory, a local .zip, or a remote .zip URL (fetched with caching; source may include a #sha256=<hex> fragment).
func OpenBundle ¶ added in v0.18.0
OpenBundle wraps an existing fs.FS as a bundle, reading and validating its manifest.
func OpenBundleDir ¶ added in v0.18.0
OpenBundleDir opens a development folder (containing manifest.toml) as a bundle.
func OpenBundleZip ¶ added in v0.18.0
OpenBundleZip opens a built .zip artifact as a bundle. File content is read on demand from the zip — nothing is decompressed into memory at open time except the manifest.
type DirDocReader ¶
type DirDocReader struct {
// contains filtered or unexported fields
}
DirDocReader reads docs from an unpacked package directory.
func NewDirDocReader ¶
func NewDirDocReader(dir string) *DirDocReader
NewDirDocReader creates a DocReader for an unpacked package directory.
func (*DirDocReader) ListDocs ¶
func (r *DirDocReader) ListDocs() []string
func (*DirDocReader) Name ¶
func (r *DirDocReader) Name() string
type DocReader ¶
type DocReader interface {
// Name returns a display name for this source.
Name() string
// ListDocs returns all doc file paths relative to docs/ (e.g. "guide.md").
ListDocs() []string
// ReadDoc reads a doc file by its relative path.
ReadDoc(name string) ([]byte, error)
}
DocReader provides access to docs/ content from a package source.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader implements libloader.LibraryLoader over a set of bundles. Bundles are searched in reverse order (last added = highest priority); within a bundle, each manifest libs dir is searched in declared order.
func (*Loader) AddBundle ¶ added in v0.18.0
AddBundle adds a bundle to the loader. Returns an error if a bundle with the same manifest name is already loaded.
func (*Loader) AddFromPath ¶
AddFromPath loads a bundle from a local directory, a local .zip, or a URL. source may include a #sha256=<hex> fragment for integrity verification.
func (*Loader) BundleByName ¶ added in v0.18.0
BundleByName returns the bundle with the given manifest name, or nil.
func (*Loader) BundleNames ¶ added in v0.18.0
BundleNames returns the manifest names of all loaded bundles.
func (*Loader) Bundles ¶ added in v0.18.0
Bundles returns the bundles added to the loader, in add order.
func (*Loader) Description ¶
Description implements libloader.LibraryLoader.
func (*Loader) Load ¶
Load implements libloader.LibraryLoader. Searches bundles in reverse order (last = highest priority), then fallback.
func (*Loader) ResolveMain ¶ added in v0.18.0
ResolveMain determines the main entry point of the last bundle that declares one, using lookup-order resolution: a main ending in .py that exists as a file in the bundle is a script; otherwise main is treated as module.function. found is false when no bundle declares main; an error is returned when main is declared but unresolvable.
func (*Loader) SetCacheDir ¶
SetCacheDir overrides the default OS cache directory for remote packages.
func (*Loader) SetFallback ¶
func (l *Loader) SetFallback(fallback libloader.LibraryLoader)
SetFallback sets the fallback loader used when no bundle provides the module.
type MainEntry ¶ added in v0.18.0
type MainEntry struct {
// Script is the content of a .py file within the bundle, run as top-level
// code. Set when main ends in .py and the file exists.
Script []byte
// ScriptName is the slash path of the script within the bundle (for error
// messages).
ScriptName string
// Module and Function name the module.function entry point, used when
// Script is nil.
Module string
Function string
}
MainEntry describes a bundle's resolved main entry point.
type Manifest ¶
type Manifest struct {
Name string `toml:"name"`
Version string `toml:"version"`
Description string `toml:"description,omitempty"`
Main string `toml:"main,omitempty"` // module.function entry point, or a .py script path within the bundle
Libs []string `toml:"libs,omitempty"` // module search dirs inside the bundle (default ["lib"])
Serve []string `toml:"serve,omitempty"` // protocols to start: "http", "mcp", "json-rpc"
AdditionalFiles []string `toml:"additional_files,omitempty"` // extra files/dirs to include (dir ends with /)
}
Manifest describes package metadata.
func ReadManifestFromDir ¶
ReadManifestFromDir reads manifest.toml from a source directory.
type Package ¶
type Package struct {
Manifest Manifest
// contains filtered or unexported fields
}
Package represents a loaded package. All file contents are decompressed into memory at Open time. docs/ entries are intentionally excluded; use ZipDocReader for those.
func (*Package) HasDocs ¶
HasDocs returns true if the package contains a docs folder. Since docs/ is not loaded into p.files, we track this separately.
type UnpackOptions ¶
UnpackOptions configures extraction behaviour.
type ZipDocReader ¶
type ZipDocReader struct {
// contains filtered or unexported fields
}
ZipDocReader reads docs from a zip package file.
func NewZipDocReader ¶
func NewZipDocReader(src string, insecure bool) (*ZipDocReader, error)
NewZipDocReader opens a zip and extracts only the docs/ entries.
func (*ZipDocReader) ListDocs ¶
func (r *ZipDocReader) ListDocs() []string
func (*ZipDocReader) Name ¶
func (r *ZipDocReader) Name() string