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 ¶
- func Configure(cfg Config) error
- func SetDefault(r *Redactor)
- func ShareText(s string) string
- type Config
- type Finding
- type Mode
- type Redactor
- func (r *Redactor) AddKnown(values ...string)
- func (r *Redactor) Message(seam Seam, m agentcore.Message) agentcore.Message
- func (r *Redactor) Messages(seam Seam, msgs agentcore.MessageList) agentcore.MessageList
- func (r *Redactor) Restore(s string) (string, int)
- func (r *Redactor) RestoreJSON(s string) (string, int)
- func (r *Redactor) Scan(seam Seam, tool, text string) Result
- func (r *Redactor) Text(seam Seam, tool, text string) string
- func (r *Redactor) ToolResult(tool string, res agentcore.AgentToolResult) agentcore.AgentToolResult
- type Result
- type Seam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefault ¶
func SetDefault(r *Redactor)
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 ¶
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 )
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 New ¶
New builds a redactor. The rule table and automaton are built once; a process should normally create one and reuse it.
func (*Redactor) AddKnown ¶
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 ¶
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) Restore ¶
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 ¶
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) ToolResult ¶
func (r *Redactor) ToolResult(tool string, res agentcore.AgentToolResult) agentcore.AgentToolResult
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.