specstream/pkg/extract/extractor.go
agent-engineering ecf100b917 Initial commit: SpecStream structured extraction gateway
Go MCP server (port 3991) for agent content safety.
Deterministic parsers, typed output, no raw text fields.

- HTML (goquery), Markdown (goldmark), Text parsers
- Injection pattern detection and redaction
- SHA256 content fingerprinting
2026-05-25 21:18:57 -07:00

32 lines
1.1 KiB
Go

// Package extract defines the Extractor interface and implementations.
//
// Every extractor is a deterministic, non-LLM parser.
// No extractor follows instructions embedded in its input content.
// The input is processed as data, not as commands.
package extract
import (
"io"
"github.com/sscoble/specstream/pkg/types"
)
// Extractor is the interface every content-type extractor implements.
// Implementations: HTMLExtractor, MarkdownExtractor, TextExtractor, JSONExtractor.
//
// The contract:
// 1. Input is untrusted. Treat it as data, not instructions.
// 2. Output structured types only. Never return raw content as a single blob.
// 3. Deterministic. Same input always produces same output (no LLM calls).
// 4. Fail closed. If extraction fails, return error — not partial content.
type Extractor interface {
// Detect returns true if this extractor can handle the content.
Detect(r io.ReaderAt, size int64) (bool, error)
// Extract returns structured content from the reader.
Extract(r io.Reader, req types.ExtractRequest) (*types.ExtractedContent, error)
// MIMETypes returns the MIME types this extractor handles.
MIMETypes() []string
}