resourcelib

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package resourcelib manages operator-owned reusable resources, independently of discovered assets. Publication is explicit; stored files are never executed.

Index

Constants

View Source
const (
	MaxFileBytes     int64 = 256 << 20
	MaxLibraryBytes  int64 = 10 << 30
	MaxTaskBytes     int64 = 1 << 30
	MaxTaskResources       = 32
	MaxFiles               = 2048
	MaxEndpoints           = 32
)
View Source
const DocumentName = "RESOURCE.md"
View Source
const MaxDocumentBytes = 64 << 10

Variables

View Source
var (
	ErrConflict    = errors.New("resource changed; reload the current revision and create a draft from the latest version before retrying")
	ErrUnavailable = errors.New("resource unavailable or task access not granted")
	ErrLimit       = errors.New("resource quota exceeded")
)

Functions

func OpenTaskFile

func OpenTaskFile(rootDir, p string) (*os.File, error)

OpenTaskFile rejects every symlink component and confines source reads even when another process renames components during the operation.

func ValidatePath

func ValidatePath(p string) error

func ValidateResource

func ValidateResource(r *Resource) error

func WriteCredential

func WriteCredential(ctx context.Context, taskRoot string, v Version, name string, data []byte) (string, error)

Types

type Actor

type Actor struct {
	TaskID   int64  `json:"task_id"`
	ThreadID string `json:"thread_id"`
	RunnerID string `json:"runner_id"`
}

Actor is populated by the server, never trusted from tool/HTTP input.

type Conflict

type Conflict struct {
	CurrentRevision  int64 `json:"current_revision"`
	CurrentVersionID int64 `json:"current_version_id"`
}

func (*Conflict) Error

func (e *Conflict) Error() string

func (*Conflict) Unwrap

func (e *Conflict) Unwrap() error

type DeleteRequest added in v0.13.0

type DeleteRequest struct {
	ResourceID       int64  `json:"resource_id"`
	ExpectedRevision int64  `json:"expected_revision"`
	RequestID        string `json:"request_id"`
	Reason           string `json:"reason"`
}

type DeleteResult added in v0.13.0

type DeleteResult struct {
	Resource               Resource `json:"resource"`
	Deleted                bool     `json:"deleted"`
	RemoteCleanupPerformed bool     `json:"remote_cleanup_performed"`
	HistoryRetained        bool     `json:"history_retained"`
}

type DocumentMeta

type DocumentMeta struct {
	Name        string   `yaml:"name" json:"name"`
	Description string   `yaml:"description" json:"description"`
	Tags        []string `yaml:"tags,omitempty" json:"tags"`
}

func ParseDocument

func ParseDocument(data []byte) (DocumentMeta, error)

Document is the versioned entry point, following the same progressive loading pattern as a Skill, but using a separate registry and invocation tools.

type Draft

type Draft struct {
	ID                 int64  `json:"id"`
	ResourceID         int64  `json:"resource_id"`
	BaseVersionID      int64  `json:"base_version_id"`
	Revision           int64  `json:"revision"`
	State              string `json:"state"`
	PublishedVersionID int64  `json:"published_version_id"`
	Size               int64  `json:"size"`
	Manifest
	Actor     Actor     `json:"actor"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Endpoint

type Endpoint struct {
	Name          string `json:"name"`
	URL           string `json:"url"`
	HasCredential bool   `json:"has_credential"`
}

type Event

type Event struct {
	ID        int64     `json:"id"`
	VersionID int64     `json:"version_id"`
	Kind      string    `json:"kind"`
	Actor     Actor     `json:"actor"`
	Detail    string    `json:"detail"`
	CreatedAt time.Time `json:"created_at"`
}

type File

type File struct {
	Path       string `json:"path"`
	Digest     string `json:"sha256"`
	Size       int64  `json:"size"`
	Executable bool   `json:"executable"`
}

type InUse added in v0.13.0

type InUse struct {
	References []Reference `json:"references"`
}

func (*InUse) Error added in v0.13.0

func (e *InUse) Error() string

type InputError

type InputError struct{ Message string }

func (*InputError) Error

func (e *InputError) Error() string

type Manifest

type Manifest struct {
	Metadata  DocumentMeta `json:"metadata"`
	Files     []File       `json:"files"`
	Endpoints []Endpoint   `json:"endpoints"`
	OS        string       `json:"os"`
	Arch      string       `json:"arch"`
}

type Reference added in v0.13.0

type Reference struct {
	TaskID       int64  `json:"task_id"`
	VersionID    int64  `json:"version_id,omitempty"`
	DeploymentID int64  `json:"deployment_id,omitempty"`
	State        string `json:"state"`
	Blocking     bool   `json:"blocking"`
}

type Resource

type Resource struct {
	ID            int64      `json:"id"`
	Name          string     `json:"name"`
	Kind          string     `json:"kind"`
	Description   string     `json:"description"`
	Tags          []string   `json:"tags"`
	AccessMode    string     `json:"access_mode"`
	Enabled       bool       `json:"enabled"`
	Revision      int64      `json:"revision"`
	CreatorTaskID int64      `json:"creator_task_id"`
	UpdatedAt     time.Time  `json:"updated_at"`
	DeletedAt     *time.Time `json:"deleted_at,omitempty"`
}

type Store

type Store struct {
	DB   *sql.DB
	Root string
	Key  []byte
}

func (*Store) BlobPath

func (s *Store) BlobPath(f File) string

func (*Store) Configure

func (s *Store) Configure(ctx context.Context, id, revision int64, endpoints []Endpoint, osName, arch string, secrets map[string]string, a Actor) (Draft, error)

Configure replaces endpoints/platform metadata, preserving credentials for unchanged endpoint names. An explicit empty secret clears that credential.

func (*Store) Create

func (s *Store) Create(ctx context.Context, r *Resource, a Actor) error

func (*Store) CreateWithRequest added in v0.13.0

func (s *Store) CreateWithRequest(ctx context.Context, r *Resource, a Actor, requestID string) error

func (*Store) Credentials

func (s *Store) Credentials(ctx context.Context, taskID, versionID int64) (map[string]string, error)

func (*Store) Delete added in v0.13.0

func (s *Store) Delete(ctx context.Context, in DeleteRequest, actor Actor) (DeleteResult, error)

func (*Store) Discard

func (s *Store) Discard(ctx context.Context, id, revision int64, a Actor) error

func (*Store) Draft

func (s *Store) Draft(ctx context.Context, id int64) (Draft, error)

func (*Store) Drafts

func (s *Store) Drafts(ctx context.Context, id int64) ([]Draft, error)

func (*Store) Events

func (s *Store) Events(ctx context.Context, id, before int64) ([]Event, error)

func (*Store) Get

func (s *Store) Get(ctx context.Context, id int64) (Resource, error)

func (*Store) Grant

func (s *Store) Grant(ctx context.Context, taskID, id, versionID, expected int64) (Version, error)

func (*Store) List

func (s *Store) List(ctx context.Context, q, kind string, before int64) ([]Resource, error)

func (*Store) Materialize

func (s *Store) Materialize(ctx context.Context, v Version, taskRoot string) (string, error)

Materialize supplies a complete disposable working copy, never a writable hard link to global data. An atomic directory rename hides partial copies.

func (*Store) NewDraft

func (s *Store) NewDraft(ctx context.Context, id, base int64, a Actor) (Draft, error)

func (*Store) Observe

func (s *Store) Observe(ctx context.Context, id, version int64, status, detail string, a Actor) error

func (*Store) Pin

func (s *Store) Pin(ctx context.Context, taskID, id, versionID int64, grant bool) (Version, error)

Pin binds one immutable version per resource per task. Admin grants can change a pin explicitly; agent use is idempotent and never silently upgrades it.

func (*Store) Publish

func (s *Store) Publish(ctx context.Context, id, revision int64, note, validation string, a Actor) (Version, error)

func (*Store) ReadDocument

func (s *Store) ReadDocument(ctx context.Context, m Manifest) (string, error)

func (*Store) References added in v0.13.0

func (s *Store) References(ctx context.Context, id int64) ([]Reference, error)

func (*Store) RemoveFile

func (s *Store) RemoveFile(ctx context.Context, id, revision int64, p string, a Actor) (Draft, error)

func (*Store) Sweep

func (s *Store) Sweep(ctx context.Context, olderThan time.Time) (int, error)

Sweep removes old, unreferenced blobs left by discarded/replaced drafts or an uncertain commit. The publication lock prevents deleting a just-published blob. Maintenance is independent of execution startup and never scans task folders.

func (*Store) Switch

func (s *Store) Switch(ctx context.Context, taskID, id, versionID, expected int64) (Version, error)

Switch changes an existing task pin only if the caller still observes the expected version. It grants no new access and preserves all old file paths.

func (*Store) TaskVersions

func (s *Store) TaskVersions(ctx context.Context, taskID int64) ([]Version, error)

func (*Store) Update

func (s *Store) Update(ctx context.Context, r *Resource, a Actor) error

func (*Store) UpdateStates

func (s *Store) UpdateStates(ctx context.Context, taskID int64) ([]UpdateState, error)

UpdateStates queries the bounded set of task pins, not resource files/history. The version index is the durable source of truth, so restarts or lost network notifications cannot permanently lose a publication.

func (*Store) UpdateWithRequest added in v0.13.0

func (s *Store) UpdateWithRequest(ctx context.Context, r *Resource, a Actor, requestID string) error

func (*Store) Upload

func (s *Store) Upload(ctx context.Context, id, revision int64, p string, executable bool, reader io.Reader, a Actor) (Draft, error)

func (*Store) Version

func (s *Store) Version(ctx context.Context, id int64) (Version, error)

func (*Store) VersionPath

func (s *Store) VersionPath(v Version) string

func (*Store) Versions

func (s *Store) Versions(ctx context.Context, id int64) ([]Version, error)

type UpdateState

type UpdateState struct {
	ResourceID int64 `json:"resource_id"`
	PinnedID   int64 `json:"pinned_version_id"`
	LatestID   int64 `json:"latest_version_id"`
	Enabled    bool  `json:"enabled"`
}

UpdateState contains only identifiers, never documents, files or credentials.

type Version

type Version struct {
	ID         int64 `json:"id"`
	ResourceID int64 `json:"resource_id"`
	Version    int   `json:"version"`
	Size       int64 `json:"size"`
	Manifest
	Note       string    `json:"note"`
	Validation string    `json:"validation"`
	Actor      Actor     `json:"actor"`
	CreatedAt  time.Time `json:"created_at"`
}

Jump to

Keyboard shortcuts

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