sanitize

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package sanitize cleans raw Claude Code transcript text BEFORE it is redacted, hashed, or stored (CAPQ-4 / FR-Q3). Real transcripts leak terminal control codes, Claude Code command wrappers, and literal escape sequences into the captured text; if those reach the marketplace they produce garbage titles and unreadable bodies, and — worse — they can hide secrets from the redactor.

The contractual pipeline order is: sanitize → redact → hash/store. Sanitizing first guarantees the redactor sees plain text (so a secret buried inside an ANSI escape or a <command-*> wrapper is still caught) and that the canonical content hash is stable across re-runs.

Sanitize applies, in this exact internal order:

(a) strip ANSI/C0 control sequences (CSI/SGR escapes, OSC, lone ESC, and the
    remaining C0 control bytes \x00–\x1f except \n and \t; bare \r dropped);
(b) DROP the entire <local-command-caveat>…</local-command-caveat> block
    (inner text included) — its body is always Claude Code boilerplate
    ("Caveat: The messages below were generated by the user while running
    local commands…"), never genuine user content (CAPQ D2). Then unwrap the
    remaining Claude Code wrappers (<command-name>, <command-message>,
    <command-args>, <local-command-stdout>, <local-command-stderr>,
    <task-notification>) — keep inner text, drop tags;
(c) unescape literal escape sequences that leaked as text: \n → newline,
    \t → tab.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(s string) string

Sanitize cleans a single string per the package contract. It is pure and idempotent: sanitizing already-sanitized text is a no-op.

func Strings

func Strings(in []string) []string

Strings sanitizes each element of in, returning a new slice. nil in, nil out.

Types

This section is empty.

Jump to

Keyboard shortcuts

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