skillmaterializer

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const CacheRootEnv = "AGENT_ADAPTOR_SKILL_CACHE_ROOT"

CacheRootEnv is the environment variable that overrides the default materializer's cache root. Adapters inspect the same variable (indirectly through internal/skillruntime.ManagedSkillCacheRoot) to identify the paths they are allowed to manage, so exposing it here keeps both sides of the contract in sync.

Variables

View Source
var ErrArchiveFormat = errors.New("agentadaptor: archive format error")

Functions

func ReadArchiveBytes

func ReadArchiveBytes(ctx context.Context, rc io.ReadCloser, limit int64) ([]byte, error)

ReadArchiveBytes reads from rc up to limit+1 bytes; if more is available it returns errArchiveTooLarge so the caller can refuse the archive without OOMing on a multi-gigabyte stream.

Types

type Config

type Config struct {
	CacheRoot         string
	MaxArchiveBytes   int64
	MaxFileBytes      int64
	MaxArchiveEntries int
	SourceMissing     error
}

func DefaultConfig

func DefaultConfig(sourceMissing error) Config

type Extraction

type Extraction struct {
	Files map[string][]byte
}

Extraction is the result of safely walking an archive.

Files maps forward-slashed entry paths (relative to Subpath) to their uncompressed content. The map is suitable for direct hand-off to writeFiles.

func ExtractArchive

func ExtractArchive(raw []byte, format Format, subpath string, cfg Config) (Extraction, error)

ExtractArchive decompresses and extracts an archive byte slice into memory subject to the configured safety limits.

The implementation rejects:

  • any entry whose cleaned path escapes the archive root (zip slip)
  • any entry whose cleaned path escapes Subpath (after normalisation)
  • any non-regular entry: symbolic links, hardlinks, devices, fifos are silently dropped (they don't make sense in a SKILL.md tree)
  • any single uncompressed entry larger than cfg.MaxFileBytes
  • more than cfg.MaxArchiveEntries entries (file + dir count)

Subpath is the prefix inside the archive where SKILL.md is expected to live. Empty means the archive root. Subpath is treated as a forward-slashed posix path; "./" / "../" / leading "/" are normalised away before matching.

type Format

type Format string
const (
	FormatAuto  Format = ""
	FormatZip   Format = "zip"
	FormatTar   Format = "tar"
	FormatTarGz Format = "tar.gz"
)

func SniffArchiveFormat

func SniffArchiveFormat(data []byte) Format

SniffArchiveFormat detects the supported archive formats by their canonical magic bytes. An unknown payload returns FormatAuto and is rejected by ExtractArchive.

type Materializer

type Materializer interface {
	Materialize(ctx context.Context, s driver.Skill) (string, error)
}

defaultSkillMaterializer implements Materializer using the SDK's XDG-like cache root described in docs/api-reference.md §11.1. The archive-handling subset is configurable through Option.

func New

func New(sourceMissing error, opts ...Option) Materializer

New returns the shared private implementation. sourceMissing is injected explicitly so this package remains below the public skill vocabulary while every caller still returns skill's one canonical sentinel.

type Option

type Option func(*Config)

Option configures the private materializer returned by New.

func WithMaxArchiveEntries

func WithMaxArchiveEntries(n int) Option

WithMaxArchiveEntries caps the number of entries (files + dirs) in a single archive. Archives with more entries than the cap surface as an error before any file is written. Default 10000. Values <= 0 are treated as the default.

func WithMaxArchiveSize

func WithMaxArchiveSize(bytes int64) Option

WithMaxArchiveSize caps the total compressed bytes the materializer will read from a SkillFromArchive stream. Streams that exceed the cap surface as an error before any extraction begins. Default 256 MiB. Values <= 0 are treated as the default.

func WithMaxFileSize

func WithMaxFileSize(bytes int64) Option

WithMaxFileSize caps the uncompressed bytes a single archive entry is allowed to occupy. Decompression bombs that inflate one entry past the cap surface as an error mid-extraction; partially-extracted staging directories are cleaned up. Default 64 MiB. Values <= 0 are treated as the default.

func WithSkillCacheRoot

func WithSkillCacheRoot(path string) Option

WithSkillCacheRoot overrides the cache root the default materializer writes to. Empty input falls back to the AGENT_ADAPTOR_SKILL_CACHE_ROOT env var, then os.UserCacheDir(), then os.TempDir() — see managedSkillCacheRoot for the resolution order.

Jump to

Keyboard shortcuts

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