Help us shape the future of Go! Take the 2026 Go Developer Survey

tee

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tee implements the TeePlugin: a transform plugin that wraps every non-trivial pipeline stage with `| tee /OUT/<idx>-<cmd>.stdout.txt` so the host can post-mortem the per-stage output of a script.

Behavior

For every pipeline stage in the script (including a single-command "pipeline" that has no `|` operator), the plugin inserts a tee stage immediately after it that mirrors the stage's stdout to a file inside Options.OutputDir. Stages whose command name does not match Options.TargetCommandMatch (when non-nil) are skipped. Stages whose command name is `tee` itself are also skipped — the plugin is idempotent under repeated application.

PIPESTATUS preservation

The naive `cmd | tee file` rewrite would shift PIPESTATUS by one position per inserted stage and change the exit status reported via pipefail. The spec calls for porting just-bash's restore semantics "faithfully"; the Phase 13 MVP injects the tee but does NOT yet emit the restore-pipeline. Scripts that observe `$PIPESTATUS` or `set -o pipefail` exit codes after a wrapped pipeline will see the shifted form. This is documented in DECISIONS.md as a Phase 13 follow-up.

Metadata

The plugin's metadata payload is a `[]TeeFileInfo` (one entry per wrapped stage, in source order). It is exposed under BashExecResult.Metadata[Name] as `map[string]any{ "files": []TeeFileInfo{...} }`.

Index

Constants

View Source
const MetadataKey = "files"

MetadataKey is the key under the plugin's metadata payload that carries the []TeeFileInfo slice.

View Source
const Name = "tee"

Name is the metadata key the plugin uses.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// OutputDir is the directory the tee file paths are joined under.
	// Required; empty disables the plugin (Transform becomes a no-op).
	OutputDir string

	// TargetCommandMatch decides which commands get wrapped. Nil
	// means "every stage with a recognizable command name".
	TargetCommandMatch func(string) bool

	// Timestamp is exposed to plugins/hosts that want a single
	// monotonic clock value for the wrapped run. Defaults to
	// time.Now() at New time.
	Timestamp time.Time
}

Options configures a TeePlugin.

type Plugin

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

Plugin is the TeePlugin instance. Each Transform call assigns its own sequential CommandIndex starting at 0; sharing a Plugin across pipelines is safe (no per-Plugin state is mutated across calls).

func New

func New(opts Options) *Plugin

New constructs a TeePlugin. Timestamp defaults to time.Now when the caller leaves it zero.

func (*Plugin) Name

func (*Plugin) Name() string

Name implements transform.Plugin.

func (*Plugin) Transform

func (p *Plugin) Transform(ctx transform.Context) transform.Result

Transform mutates Origin in place, wrapping every matching pipeline stage. Returns metadata listing the inserted tee files.

type TeeFileInfo

type TeeFileInfo struct {
	CommandIndex int    `json:"commandIndex"`
	CommandName  string `json:"commandName"`
	Command      string `json:"command"`
	StdoutFile   string `json:"stdoutFile"`
}

TeeFileInfo is one entry in the plugin's metadata payload — one per wrapped pipeline stage.

Jump to

Keyboard shortcuts

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