artifact

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManifestVersion  = 1
	DirName          = ".artifacts"
	ManifestName     = "manifest.json"
	DefaultAgent     = "unknown"
	DefaultRetention = "session"
	ArchiveRetention = "archive"
)
View Source
const LockFileName = ".manifest.lock"

LockFileName is the manifest lock file inside the artifact directory. Every writer takes an exclusive flock on it before a read-modify-write of the manifest (see withManifestLock).

Variables

View Source
var ErrIDExists = errors.New("artifact id already exists")

ErrIDExists reports that a manifest entry with the requested ID exists.

Functions

func ArchiveSessionArtifacts

func ArchiveSessionArtifacts(sess *session.Session) (archiveDir string, count int, err error)

func ClearFocus

func ClearFocus(sess *session.Session) error

func DefaultDestination

func DefaultDestination(artifactType, sourceName string) string

func DetectType

func DetectType(path string) string

func DirForSession

func DirForSession(sess *session.Session) string

func DiscoverAssetBundle

func DiscoverAssetBundle(sess *session.Session, primary string) []string

func EncodeManifest

func EncodeManifest(m *Manifest, sessionName string) ([]byte, error)

EncodeManifest validates m for sessionName and returns the exact bytes SaveManifest writes.

func EnsureArtifactDir

func EnsureArtifactDir(base string) error

func EnsureTheme

func EnsureTheme(sess *session.Session) error

func FocusedID

func FocusedID(sess *session.Session) string

func GenerateID

func GenerateID(artifactType, title string, t time.Time) string

func ManifestPath

func ManifestPath(sess *session.Session) string

func NormalizeFolderPath

func NormalizeFolderPath(folder string) (string, error)

func ParseReferencedAssets

func ParseReferencedAssets(file string, data []byte) []string

func ParseTags

func ParseTags(s string) []string

func ReferencedAssets

func ReferencedAssets(sess *session.Session, a Artifact) []string

func SafeJoin

func SafeJoin(base, rel string) (string, error)

func SafeToOpenExternally

func SafeToOpenExternally(file string) bool

SafeToOpenExternally reports whether a file can be opened with the OS default application without risking code execution.

func SaveManifest

func SaveManifest(sess *session.Session, m *Manifest) error

func SecureExistingPath

func SecureExistingPath(base, rel string) (string, error)

SecureExistingPath resolves rel under base and rejects symlinks in any path component. It is intended for serving/copying/removing existing artifact files without letting a symlink inside .artifacts escape the artifact directory.

func SecureNewPath

func SecureNewPath(base, rel string) (string, error)

SecureNewPath resolves rel under base and rejects symlinks in parent components. If the destination exists and is a symlink, it is rejected too.

func Slugify

func Slugify(s string) string

func SortNewestFirst

func SortNewestFirst(items []Artifact)

func ValidateArtifact

func ValidateArtifact(a Artifact) error

func ValidateManifest

func ValidateManifest(m *Manifest) error

func ValidateRelativePath

func ValidateRelativePath(p string) error

func ValidateRetention

func ValidateRetention(r string) error

func ValidateType

func ValidateType(t string) error

func WebPath

func WebPath(sessionName, file string) string

Types

type AddOptions

type AddOptions struct {
	Source      string
	Reader      io.Reader
	Destination string
	Folder      string
	ID          string
	Type        string
	Title       string
	Summary     string
	Agent       string
	Retention   string
	Tags        []string
	Focus       bool
	Now         time.Time
}

type Artifact

type Artifact struct {
	ID        string    `json:"id"`
	Type      string    `json:"type"`
	Title     string    `json:"title"`
	File      string    `json:"file"`
	Folder    string    `json:"folder,omitempty"`
	Created   time.Time `json:"created"`
	Agent     string    `json:"agent,omitempty"`
	Retention string    `json:"retention,omitempty"`
	Summary   *string   `json:"summary,omitempty"`
	Tags      []string  `json:"tags,omitempty"`
	Assets    []string  `json:"assets,omitempty"`
	Focus     bool      `json:"focus,omitempty"`
}

Artifact describes one file under a session's .artifacts directory.

func Add

func Add(sess *session.Session, opts AddOptions) (out Artifact, err error)

func AppendRegistered

func AppendRegistered(m *Manifest, a Artifact) (Artifact, error)

AppendRegistered validates a and appends it to m, for a file the caller has already written under the artifact directory. It performs no I/O, so callers that must avoid path-based (symlink-following) access can do the file system work themselves. It records no referenced assets (callers use it for untrusted content, whose references must not make removal delete other files). It fails if the ID is taken or another entry names the same file.

func Filter

func Filter(artifacts []Artifact, opts FilterOptions) []Artifact

func Find

func Find(m *Manifest, id string) (*Artifact, int)

func Remove

func Remove(sess *session.Session, id string) (out Artifact, err error)

func ResolveFile

func ResolveFile(sess *session.Session, id string) (string, *Artifact, error)

ResolveFile returns the absolute on-disk path of the artifact with the given ID. The path is validated against the manifest and rejected if any component is a symlink, so callers (the desktop open/save bridge) can never be pointed at a file outside the session's artifact directory.

func SetRetention

func SetRetention(sess *session.Session, id, retention string) (out Artifact, err error)

func UpdateMetadata

func UpdateMetadata(sess *session.Session, id string, update MetadataUpdate) (out Artifact, err error)

type FilterOptions

type FilterOptions struct {
	Type   string
	Tag    string
	Agent  string
	Search string
	Folder string
}

type ListItem

type ListItem struct {
	Artifact
	Path string `json:"path"`
	URL  string `json:"url"`
}

ListItem is the agent/web-facing artifact shape with computed paths.

func WithComputedFields

func WithComputedFields(sessionName string, artifacts []Artifact) []ListItem

type Manifest

type Manifest struct {
	Version   int        `json:"version"`
	Session   string     `json:"session"`
	Artifacts []Artifact `json:"artifacts"`
}

Manifest indexes all artifacts for one devx session.

func LoadManifest

func LoadManifest(sess *session.Session) (*Manifest, error)

func NewManifest

func NewManifest(sessionName string) *Manifest

func ParseManifest

func ParseManifest(data []byte, sessionName string) (*Manifest, error)

ParseManifest parses and validates manifest bytes for sessionName. Callers that must not follow symlinks (e.g. the MCP artifact bridge) read the bytes themselves and use this for the same validation as LoadManifest.

type MetadataUpdate

type MetadataUpdate struct {
	Title     *string
	Type      *string
	Summary   *string
	Tags      []string
	TagsSet   bool
	Retention *string
	Focus     *bool
}

Jump to

Keyboard shortcuts

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