redact

package
v1.5.136 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 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 redact implements golder's embedded data-loss-prevention layer: it finds credential-shaped values in text that is about to enter the model's context (tool output, prompts, compaction summaries, memory) and replaces them with stable placeholders before the provider ever sees them.

The rule set below is a curated subset of the shapes gitleaks and similar scanners look for. It is deliberately small and dependency-free: the engine uses an anchor automaton plus per-rule regexes instead of running every regex over every byte, so clean text costs one linear pass.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(cfg Config) error

Configure builds and installs the process redactor. Mode Off clears it.

func SetDefault

func SetDefault(r *Redactor)

func ShareText

func ShareText(s string) string

ShareText redacts a transcript for publication, using a plain marker rather than a reversible token.

Types

type Config

type Config struct {
	Mode      Mode
	Entropy   float64 // minimum Shannon entropy for generic assignments; 0 = 3.5
	Allow     []string
	AuditPath string
	SessionID string
	// Placeholder overrides the token format. The share export uses it to emit
	// a plain [REDACTED] instead of a reversible token.
	Placeholder func(rule, hash string) string
	MaxTokens   int // restore-map cap; 0 = 4096
	// Aggressive disables the placeholder/entropy heuristics. The share export
	// uses it: a published transcript must redact "xxxx" and low-entropy
	// assignments too, even though they are usually benign in a live tool result.
	Aggressive bool
	// WholeAssignments replaces the whole NAME=value match for the generic
	// assignment rule instead of only the value. Export-only.
	WholeAssignments bool
}

Config configures one Redactor.

type Finding

type Finding struct {
	Rule   string
	Action string
	Hash   string
	Start  int
	End    int
	Line   int
	Col    int
}

Finding is one detected credential. Hash is a keyed digest prefix; the secret itself is deliberately absent.

type Mode

type Mode int

Mode selects what a finding does to the text.

const (
	// Off disables scanning entirely (Default returns nil in this mode).
	Off Mode = iota
	// Observe records findings and leaves the text untouched.
	Observe
	// Redact replaces each secret with a stable placeholder (the default).
	Redact
	// Block replaces the whole text with a short refusal that names the rules.
	Block
)

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses a user-facing mode name. An empty string means Redact, the safe default for a configured redactor.

func (Mode) String

func (m Mode) String() string

type Redactor

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

Redactor is immutable after construction except for the restore map and the known-secret set, both of which are mutex-guarded. Scan is safe to call from concurrent tool executions.

func Default

func Default() *Redactor

func New

func New(cfg Config) (*Redactor, error)

New builds a redactor. The rule table and automaton are built once; a process should normally create one and reuse it.

func (*Redactor) AddKnown

func (r *Redactor) AddKnown(values ...string)

AddKnown registers exact secret values (for example golder's own provider API keys) that must always be redacted even when their shape is unknown.

func (*Redactor) Message

func (r *Redactor) Message(seam Seam, m agentcore.Message) agentcore.Message

Message redacts the text-bearing fields of one message. Tool-call arguments and thinking signatures are left alone: rewriting them would break replay or execution.

func (*Redactor) Messages

func (r *Redactor) Messages(seam Seam, msgs agentcore.MessageList) agentcore.MessageList

Messages redacts every message in the list. It returns a new slice only while the redactor is active; individual messages are copied only when they change.

func (*Redactor) PreviewText added in v1.5.79

func (r *Redactor) PreviewText(tool, text string) string

PreviewText applies the configured mode to a repeatedly refreshed view of already-produced content. Redacted values use a non-reversible marker; no audit entry or restore token is created. Original input and output seams must still use audited scans.

func (*Redactor) Restore

func (r *Redactor) Restore(s string) (string, int)

Restore expands known placeholders back to their values. Call it only on write-tool arguments: restoring into a shell command would let the model use a placeholder as an oracle to exfiltrate the secret.

func (*Redactor) RestoreJSON

func (r *Redactor) RestoreJSON(s string) (string, int)

RestoreJSON is Restore for raw tool arguments. The replacement is JSON-escaped, so a secret containing quotes, backslashes or newlines (a PEM block) cannot break the argument document.

func (*Redactor) Revision added in v1.5.79

func (r *Redactor) Revision() uint64

Revision changes when the known-secret set changes. It lets a presentation cache invalidate old redacted views without exposing any secret values.

func (*Redactor) Scan

func (r *Redactor) Scan(seam Seam, tool, text string) Result

Scan finds secrets in text and applies the configured mode.

func (*Redactor) Text

func (r *Redactor) Text(seam Seam, tool, text string) string

Text is Scan's text-only convenience form.

func (*Redactor) ToolResult

ToolResult redacts a tool result before it enters the message list. In block mode the whole result is replaced by a refusal and marked as an error.

type Result

type Result struct {
	Text     string
	Findings []Finding
	Blocked  bool
}

Result is one scan's outcome.

type Seam

type Seam string

Seam names the point a scan happened at, for the audit log.

const (
	SeamToolOutput Seam = "tool_output"
	SeamUserPrompt Seam = "user_prompt"
	SeamAssistant  Seam = "assistant"
	SeamCompaction Seam = "compaction"
	SeamMemory     Seam = "memory"
	SeamSession    Seam = "session"
	SeamShare      Seam = "share"
)

Jump to

Keyboard shortcuts

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