dive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dive wraps invocations of the wagoodman/dive CLI and parses its JSON analysis output.

Index

Constants

View Source
const DefaultTimeout = 5 * time.Minute

DefaultTimeout is used when DIVE_MCP_TIMEOUT is unset or unparsable.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analysis

type Analysis struct {
	Layers []Layer   `json:"layer"`
	Image  ImageInfo `json:"image"`
}

Analysis is the top-level structure written by `dive <image> --json <file>`.

type FileReference

type FileReference struct {
	Count     int    `json:"count"`
	SizeBytes int64  `json:"sizeBytes"`
	File      string `json:"file"`
}

FileReference is a file that appears in more than one layer (a candidate for wasted space), along with how many times and how many bytes it costs.

func TopWasted

func TopWasted(refs []FileReference, limit int) []FileReference

TopWasted returns up to limit FileReferences sorted in descending order of TotalWastedBytes. The input slice is not mutated.

func (FileReference) TotalWastedBytes

func (f FileReference) TotalWastedBytes() int64

TotalWastedBytes returns Count * SizeBytes, i.e. the total bytes attributable to this file across all of its duplicated occurrences.

type ImageInfo

type ImageInfo struct {
	SizeBytes        int64           `json:"sizeBytes"`
	InefficientBytes int64           `json:"inefficientBytes"`
	EfficiencyScore  float64         `json:"efficiencyScore"`
	FileReference    []FileReference `json:"fileReference"`
}

ImageInfo summarizes the whole image, including candidate wasted files.

type Layer

type Layer struct {
	Index     int    `json:"index"`
	ID        string `json:"id"`
	DigestID  string `json:"digestId"`
	SizeBytes int64  `json:"sizeBytes"`
	Command   string `json:"command"`
	// FileList holds the (large) per-file tree for the layer. It is not
	// needed by any of the dive-mcp tools, so it is captured loosely and
	// never unmarshalled into a rigid struct.
	FileList []json.RawMessage `json:"fileList,omitempty"`
}

Layer describes a single image layer as reported by dive.

type Runner

type Runner struct {
	// BinPath is the resolved path to the dive executable.
	BinPath string
	// Timeout bounds each invocation of dive.
	Timeout time.Duration
	// contains filtered or unexported fields
}

Runner locates and invokes the dive CLI, caching parsed analyses for the lifetime of the process so that multiple MCP tool calls against the same (image, source) pair only shell out to dive once.

func NewRunner

func NewRunner() (*Runner, error)

NewRunner locates the dive binary (via DIVE_MCP_DIVE_PATH or PATH) and reads DIVE_MCP_TIMEOUT for the per-invocation timeout. It returns an error with actionable guidance if dive cannot be found.

func (*Runner) Analyze

func (r *Runner) Analyze(ctx context.Context, image, source string) (*Analysis, error)

Analyze runs (or fetches from cache) the dive analysis for image using the given source ("", "docker", "podman", or "docker-archive").

Jump to

Keyboard shortcuts

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