Documentation
¶
Overview ¶
Package oci provides unified OCI reference parsing, validation, and local-build tagging helpers shared by the skills and plugins services.
Index ¶
- Constants
- func IsLocalBuild(ctx context.Context, store TargetStore, tag string) (bool, error)
- func IsRegistryReference(raw string) bool
- func ResolveBuildTag(raw, artifactName string) (string, error)
- func TagAsLocalBuild(ctx context.Context, store TargetStore, d digest.Digest, tag string) error
- func ValidateBuildTagInput(raw string) error
- type RefKind
- type Reference
- type TargetStore
Constants ¶
const DefaultTag = "latest"
DefaultTag is the tag appended to tag-less repository references and used when a build does not specify --tag.
const LocalBuildAnnotation = "dev.stacklok.toolhive.local-build"
LocalBuildAnnotation marks a tag in a local OCI store as produced by a local build (`thv skill build` or `thv ai-plugin build`) rather than an OCI pull (install, content preview). The value is always "true" when set; absence means "not a local build".
The annotation is stamped at the descriptor level inside the store's root index.json, not on the manifest content. Two properties follow from that:
- Push resolves the artifact by digest, which returns a plain descriptor (oras-go's oci.Store strips annotations when the reference is a digest), so the marker never crosses the wire.
- Pull calls Store.Tag with the pulled digest, which also resolves by digest before tagging, so pulled tags inherit no annotations and stay invisible to ListBuilds.
The key is reverse-DNS namespaced so it composes with other locally-built artifact types (containers, MCP server images) in the future.
Variables ¶
This section is empty.
Functions ¶
func IsLocalBuild ¶
IsLocalBuild reports whether the given tag in the local OCI store carries the local-build marker. Tags created by OCI pulls do not carry it, so this is the filter used by ListBuilds and local-store installs to exclude cached remote artifacts.
func IsRegistryReference ¶
IsRegistryReference reports whether raw parses as a valid registry-qualified OCI reference. Used by lockfile recording to distinguish remotely restorable references from local-store-only tags.
func ResolveBuildTag ¶
ResolveBuildTag resolves the final local OCI store tag for a build given the caller's raw --tag flag and the artifact's declared name (from SKILL.md or plugin.json).
Rules:
- Empty raw tag + empty artifactName -> "" (untagged; caller returns digest).
- Empty raw tag + non-empty artifactName -> "<artifactName>:latest".
- Bare tag (e.g. "v1.0.0") -> "<artifactName>:<tag>" (400 if artifactName is empty).
- Local or registry-qualified tag ref -> normalized "<repo>:<tag>" or "<registry>/<repo>:<tag>" (defaulting tag-less refs with '/' to ":latest").
- Digest references are rejected with HTTP 400.
func TagAsLocalBuild ¶
TagAsLocalBuild tags digest d with the given tag and stamps the local-build marker on the root-index descriptor entry. Callers must only invoke it from code paths that genuinely produced the artifact locally (Build).
func ValidateBuildTagInput ¶
ValidateBuildTagInput validates the raw --tag flag before packaging runs so invalid syntax or digest references fail fast without writing orphaned blobs to the local OCI store. An empty raw string is valid (the build will default to <artifactName>:latest).
Types ¶
type RefKind ¶
type RefKind int
RefKind classifies the syntactic form of an OCI tag or reference.
const ( // RefKindBareTag is a single-token tag with no '/', ':', or '@' // (e.g. "v1.0.0", "latest", "my-skill"). RefKindBareTag RefKind = iota // RefKindLocal is a registry-less OCI reference whose first segment is a // repository or namespace rather than a registry host // (e.g. "my-skill:v1.0.0", "org/my-skill:v1.0.0", "org/my-skill"). RefKindLocal // RefKindRegistry is an OCI reference with an explicit registry host // (e.g. "ghcr.io/org/my-skill:v1.0.0", "localhost:5000/my-skill:v1"). RefKindRegistry )
type Reference ¶
type Reference struct {
// Raw is the original input string passed to ParseRef.
Raw string
// Kind classifies whether the input is a bare tag, a registry-less local
// reference, or a registry-qualified reference.
Kind RefKind
// Registry is the explicit registry host for RefKindRegistry references,
// preserving the host spelling from Raw (e.g. "ghcr.io", "localhost:5000",
// "docker.io"). Empty for RefKindBareTag and RefKindLocal.
Registry string
// Repository is the repository path without the registry host or tag/digest
// (e.g. "my-skill", "org/my-skill"). Empty for RefKindBareTag.
Repository string
// Tag is the OCI tag portion (defaulted to DefaultTag for tag-less
// non-digest references). Empty for digest-only references.
Tag string
// Digest is the digest identifier (e.g. "sha256:...") when the input is a
// digest reference. Empty otherwise.
Digest string
// HasExplicitTag reports whether the input explicitly specified a tag
// (always true for RefKindBareTag, false for tag-less "org/name" or
// "ghcr.io/org/name", and false for digest references).
HasExplicitTag bool
// contains filtered or unexported fields
}
Reference is the parsed, validated representation of an OCI tag or reference.
func ParseRef ¶
ParseRef parses and validates raw as a bare tag, a registry-less local OCI reference, or a registry-qualified OCI reference.
Classification rules:
- No '/', ':', or '@' -> RefKindBareTag (validated as an OCI tag).
- Contains '/', ':', or '@' and the first '/'-segment is "localhost" or contains '.' or ':' -> RefKindRegistry.
- Contains '/', ':', or '@' otherwise -> RefKindLocal.
Tag-less non-digest references with '/' (e.g. "org/my-skill", "ghcr.io/org/my-skill", "localhost:5000/my-skill") are normalized by appending ":latest" while keeping HasExplicitTag == false. Registry-less references are never implicitly expanded to Docker Hub.
func ValidatePushReference ¶
ValidatePushReference validates that raw is a registry-qualified OCI reference suitable for pushing to a remote registry. Registry-less local references and bare tags are rejected with HTTP 400 so push never implicitly targets Docker Hub.
func (Reference) HasRegistry ¶
HasRegistry reports whether the reference carries an explicit registry host.
func (Reference) IsBareTag ¶
IsBareTag reports whether the reference is a single-token bare tag with no '/', ':', or '@'.
func (Reference) IsLocal ¶
IsLocal reports whether the reference is a registry-less structured reference (name:tag, org/name, org/name:tag, etc.).
func (Reference) NameRef ¶
NameRef returns the underlying go-containerregistry Reference for RefKindRegistry values, or nil for bare tags and local references.
func (Reference) RepoBasename ¶
RepoBasename returns the final path segment of Repository (e.g. "my-skill" for "org/my-skill" or "my-skill"), or empty string for RefKindBareTag.
type TargetStore ¶
TargetStore is the minimal interface satisfied by both *ociskills.Store and *ociplugins.Store for descriptor-level local-build tagging.