workspace

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 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 workspace manages workspace directories and the file operations exposed over the API.

A managed workspace is a directory directly under the store root, named by its ID. A host-directory attachment points at an existing project directory inside an allowed root (NATIVE_AGENT_ALLOWED_ROOTS); its record is stored under <root>/.attachments and removing the workspace removes only that record. Every path supplied by a client is resolved relative to the workspace directory; traversal and symbolic links are rejected so a request can never reach outside the workspace.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID        = errors.New("workspace id is invalid")
	ErrNotFound         = errors.New("not found")
	ErrInvalidPath      = errors.New("file path is invalid")
	ErrFileTooLarge     = errors.New("file exceeds the configured upload limit")
	ErrTooManyEntries   = errors.New("workspace contains too many entries")
	ErrIsDirectory      = errors.New("target is a directory")
	ErrPathConflict     = errors.New("destination already exists")
	ErrInvalidOperation = errors.New("file operation is invalid")
	// ErrAttachmentDisabled is returned when no allowed roots are configured.
	ErrAttachmentDisabled = errors.New("host-directory attachments need NATIVE_AGENT_ALLOWED_ROOTS")
)

Sentinel errors returned by Store. Callers map them to API status codes with errors.Is.

Functions

func MediaType

func MediaType(filePath string) string

MediaType guesses the MIME type from the file extension.

Types

type Attachment

type Attachment struct {
	Path  string `json:"path"`
	State string `json:"state" enum:"ready,unavailable" doc:"unavailable: the directory is gone or no longer inside an allowed root."`
}

Attachment is the host directory backing an attached workspace.

type ConflictPolicy

type ConflictPolicy string

ConflictPolicy defines what a file operation does when its destination exists.

const (
	ConflictError   ConflictPolicy = "error"
	ConflictReplace ConflictPolicy = "replace"
)

type Entry

type Entry struct {
	Path      string    `json:"path"`
	Directory bool      `json:"directory"`
	Size      int64     `json:"size"`
	MediaType string    `json:"media_type,omitempty"`
	Modified  time.Time `json:"modified_at"`
}

Entry describes one file or directory inside a workspace.

type Info

type Info struct {
	ID      string `json:"workspace_id"`
	Storage string `json:"storage" enum:"managed,attachment" doc:"managed: a directory the gateway owns; attachment: a host directory."`
	// Attachment is present when Storage is attachment.
	Attachment *Attachment `json:"attachment,omitempty"`
	Times      Times       `json:"times"`
}

Info describes a workspace.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store owns the workspace root directory.

func NewStore

func NewStore(root string, roots *fsroot.Set, maxFileBytes int64, maxEntries int) (*Store, error)

NewStore creates root (mode 0700) when missing and returns a Store backed by it. roots (may be nil) are the directories that can be attached as workspaces.

func (*Store) AttachHostDirectory

func (s *Store) AttachHostDirectory(path string) (Info, error)

AttachHostDirectory registers an existing directory inside an allowed root. Attaching the same directory again returns the existing workspace.

func (*Store) Copy

func (s *Store) Copy(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)

Copy copies a regular file or directory tree. Symbolic links and special files are rejected.

func (*Store) Create

func (s *Store) Create() (string, error)

Create allocates a new empty workspace and returns its ID.

func (*Store) CreateDirectory

func (s *Store) CreateDirectory(id, requestedPath string, conflict ConflictPolicy) (Entry, error)

CreateDirectory creates one directory. Its parent must already exist.

func (*Store) Delete

func (s *Store) Delete(id, requestedPath string) error

Delete removes a file or directory tree inside the workspace.

func (*Store) Dir

func (s *Store) Dir(id string) (string, error)

Dir returns the absolute directory of an existing workspace.

func (*Store) Health

func (s *Store) Health() error

Health verifies that the configured storage root is still an accessible directory.

func (*Store) Info

func (s *Store) Info(id string) (Info, error)

Info returns a workspace description.

func (*Store) List

func (s *Store) List(id string) ([]Entry, error)

List returns every entry in the workspace sorted by path. Symbolic links are skipped.

func (*Store) Move

func (s *Store) Move(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)

Move renames a regular file or directory inside one workspace.

func (*Store) Open

func (s *Store) Open(id, requestedPath string) (*os.File, Entry, error)

Open returns a regular file for reading. The caller must close it.

func (*Store) Protect

func (s *Store) Protect(dirs ...string)

Protect adds directories that attachments must neither be inside nor contain. Call it before serving requests.

func (*Store) Remove

func (s *Store) Remove(id string) error

Remove deletes a managed workspace with all of its contents, or only the record of an attached workspace (the project directory is never touched).

func (*Store) Upload

func (s *Store) Upload(id, requestedPath string, source io.Reader) (UploadedFile, error)

Upload streams source into requestedPath atomically (temporary file + rename) and returns the stored file metadata together with its SHA-256 digest.

func (*Store) Workspaces

func (s *Store) Workspaces() ([]Info, error)

Workspaces lists managed and attached workspaces.

type Times

type Times struct {
	CreatedAt time.Time `json:"created_at" doc:"When the workspace was created or attached."`
	// LastUsedAt is the latest session activity in the workspace (a run starting, binding its
	// conversation or finishing); absent before the first run.
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
}

Times are a workspace's timestamps.

type UploadedFile

type UploadedFile struct {
	Entry

	SHA256 string `json:"sha256"`
}

UploadedFile is the result of a successful upload.

Jump to

Keyboard shortcuts

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