mask

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 5 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 mask provides emission-time masking of secret values in Rune's output streams, so credentials never reach a terminal transcript or an agent's chat history (spec 013-secret-masking).

A Set is derived once per run from the task environment's variable NAMES (built-in sensitive patterns plus `set secrets` declarations, minus `set unmasked` exemptions) and is immutable afterwards. A Writer wraps an output stream and replaces every verbatim occurrence of a Set entry with the fixed Placeholder before bytes reach the underlying writer.

Invariants:

  • Values (or lines of multi-line values) shorter than MinLen bytes are never tracked; multi-line values are tracked per line only, keeping the Writer's carry bound small.
  • The Writer is safe for concurrent use and holds back at most maxEntryLen−1 bytes (a stream tail that is a proper prefix of an entry).
  • Flush emits the carry after masking any completed entries in it; callers may only flush when no producer can still be writing (the engine flushes after the scheduler has joined every task).
  • An empty Set means callers skip wrapping entirely, so secret-free runs stay byte-identical.

Index

Constants

View Source
const (
	// Placeholder replaces every occurrence of a tracked secret value on every
	// output surface (contract §2.2).
	Placeholder = "***"
	// MinLen is the minimum tracked value (or value-line) length in bytes;
	// shorter values are never value-masked to avoid corrupting unrelated
	// output (FR-007).
	MinLen = 4
)

Variables

This section is empty.

Functions

func SensitiveName added in v0.10.0

func SensitiveName(name string) bool

SensitiveName reports whether name matches one of the built-in sensitive-name patterns, ignoring case. It is the pattern rule alone, for names that are not environment variables, such as task parameters: the environment's exemptions do not apply there.

Types

type Set

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

Set is an immutable collection of secret values to mask. It is safe for concurrent readers.

func NewSet

func NewSet(env, declared, exempt []string) *Set

NewSet derives the secret-value set from KEY=value environment pairs. A variable is tracked when its name matches a built-in pattern and is not exempted, or when it is explicitly declared. Values are split per line; lines shorter than MinLen are dropped (data-model derivation steps 1–4).

func (*Set) Empty

func (s *Set) Empty() bool

Empty reports whether the set tracks no values; callers skip wrapping writers entirely for an empty set (FR-008). A nil Set is empty.

func (*Set) MaskString

func (s *Set) MaskString(in string) string

MaskString replaces every occurrence of every entry in one shot (no carry).

type Writer

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

Writer wraps an output stream and masks every occurrence of the Set's entries at emission time, including occurrences split across Write calls (FR-003/FR-004). It is safe for concurrent use: parallel tasks share the engine's streams.

func NewWriter

func NewWriter(dst io.Writer, set *Set) *Writer

NewWriter wraps dst. Callers should not wrap at all when set.Empty() — that keeps secret-free runs byte-identical (FR-008).

func (*Writer) Close

func (w *Writer) Close() error

Close flushes the writer. It never closes the underlying stream (the wrapped writer is typically os.Stdout/os.Stderr or a caller-owned buffer).

func (*Writer) Flush

func (w *Writer) Flush() error

Flush emits the withheld tail. Completed entries inside it are masked; a genuinely incomplete prefix is emitted verbatim (it is not the secret). Callers may only flush when no producer can still be writing — the engine flushes after the scheduler has joined every task (research.md D4).

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write masks p (together with any carried tail) and forwards the result. It reports len(p) consumed on success even when a tail is withheld.

Jump to

Keyboard shortcuts

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