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 SchemeSyntax(source string) (string, bool)
- func Unpack(src string, opts UnpackOptions) error
- func UnpackRemove(src string, insecure bool, destDir string) error
- type Bundle
- func FetchBundle(source string, insecure bool, cacheDir string) (*Bundle, error)
- func OpenBundle(fsys fs.FS, source string) (*Bundle, error)
- func OpenBundleDir(dir string) (*Bundle, error)
- func OpenBundleZip(r io.ReaderAt, size int64, source string) (*Bundle, error)
- func VirtualBundle(name, version string, fsys fs.FS, source string) *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) LoadWithContext(ctx context.Context, 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 SchemeOpener
- type SchemeRegistry
- func (r *SchemeRegistry) FetchBundle(source string, insecure bool, cacheDir string) (*Bundle, error)
- func (r *SchemeRegistry) Lookup(scheme string) SchemeOpener
- func (r *SchemeRegistry) Register(scheme string, opener SchemeOpener) error
- func (r *SchemeRegistry) Registered() []string
- func (r *SchemeRegistry) Unregister(scheme string) bool
- 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") )
var ErrUnknownScheme = errors.New("no plugin provides the source scheme")
ErrUnknownScheme reports a source that looks like <scheme>://… but whose scheme has no registered opener — almost always a fetcher plugin that was never loaded. Callers match on it to add context only they can supply, such as the flags or configuration that load a plugin in their environment.
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. Plugin-served content never appears here — it is held in memory only — so there is nothing per-file to prune. Stale .pfile pairs written by an earlier build are cleaned up too.
func RegisterPackageLibrary ¶ added in v0.18.0
RegisterPackageLibrary registers the scriptling.package library on the given Scriptling instance. Convenience wrapper around NewPackageLibrary.
func SchemeSyntax ¶ added in v0.23.0
SchemeSyntax reports whether source looks like a custom <scheme>://rest source, regardless of whether any opener is registered for it. It returns ("", false) for http(s) URLs (owned by FetchBundle), local paths, and malformed sources. Callers use it to tell a missing plugin apart from a missing file.
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, a remote .zip URL (fetched with caching; source may include a #sha256=<hex> fragment), or a custom <scheme>:// source routed through the process-wide default scheme registry (see RegisterScheme — typically a fetcher plugin serving files on demand). A scheme-shaped source whose scheme has no opener is an error naming the missing plugin, not a missing-file error.
Hosts with their own SchemeRegistry call SchemeRegistry.FetchBundle instead.
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.
func VirtualBundle ¶ added in v0.23.0
VirtualBundle wraps an fs.FS as a bundle with an explicitly supplied manifest — for sources with no manifest.toml of their own, such as a fetcher plugin's library (the host synthesizes the standard layout).
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. A bundle whose storage fails (a fetcher plugin that cannot be reached, say) aborts the search with that error — only a plain not-found continues past a bundle, so an unreachable source is reported instead of silently skipping its modules.
func (*Loader) LoadWithContext ¶ added in v0.23.0
LoadWithContext preserves caller context through context-aware fallbacks and observes cancellation between bundle probes. Bundle storage uses fs.FS, whose ReadFile contract has no per-call context.
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 SchemeOpener ¶ added in v0.23.0
SchemeOpener opens a bundle from a source using the registered scheme. The signature matches FetchBundle so openers compose with every existing caller. Openers that need a context capture one at registration; see pluginpack.Bridge.
type SchemeRegistry ¶ added in v0.23.0
type SchemeRegistry struct {
// contains filtered or unexported fields
}
SchemeRegistry maps custom source schemes to bundle openers. It is safe for concurrent use. The zero value is not usable; call NewSchemeRegistry.
func DefaultSchemeRegistry ¶ added in v0.23.0
func DefaultSchemeRegistry() *SchemeRegistry
DefaultSchemeRegistry returns the process-wide registry that FetchBundle and the package-level Register/Unregister functions use.
func NewSchemeRegistry ¶ added in v0.23.0
func NewSchemeRegistry() *SchemeRegistry
NewSchemeRegistry returns an empty scheme registry.
func (*SchemeRegistry) FetchBundle ¶ added in v0.23.0
func (r *SchemeRegistry) FetchBundle(source string, insecure bool, cacheDir string) (*Bundle, error)
FetchBundle opens source through this registry's openers, falling back to the built-in directory / zip / URL handling for non-scheme sources.
func (*SchemeRegistry) Lookup ¶ added in v0.23.0
func (r *SchemeRegistry) Lookup(scheme string) SchemeOpener
Lookup returns the opener for a scheme, or nil when it is not registered.
func (*SchemeRegistry) Register ¶ added in v0.23.0
func (r *SchemeRegistry) Register(scheme string, opener SchemeOpener) error
Register routes sources with the given scheme to opener. Registering a scheme twice, or a built-in (http, https, file), is an error — one scheme has one owner. Use Unregister to release it first.
func (*SchemeRegistry) Registered ¶ added in v0.23.0
func (r *SchemeRegistry) Registered() []string
Registered returns the registered custom schemes in sorted order.
func (*SchemeRegistry) Unregister ¶ added in v0.23.0
func (r *SchemeRegistry) Unregister(scheme string) bool
Unregister releases a scheme so it can be claimed again, and reports whether it was registered. Hosts that reload plugins call this on teardown.
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