rewrite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package rewrite implements the Layer B text rewrite hook (WR rewrite_text.py).

Index

Constants

View Source
const (
	BackendPrintPrompt = "print-prompt"
	BackendOllama      = "ollama"
	BackendOpenAI      = "openai" // OpenAI-compatible /v1/chat/completions
)

Backends.

View Source
const (
	StrengthParaphrase    = "paraphrase"
	StrengthHumanize      = "humanize"
	StrengthCode          = "code"
	StrengthBacktranslate = "backtranslate"
	StrengthStructural    = "structural"
)

Strengths.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(strength, text, lang, originalLang string) string

BuildPrompt builds the Layer B attack prompt (WR-compatible wording).

func CheckRemote

func CheckRemote(baseURL string, allowRemote bool) error

CheckRemote enforces loopback-only endpoints unless AllowRemote.

func LexicalDivergence

func LexicalDivergence(original, candidate string) float64

LexicalDivergence is bigram Jaccard distance: 0 identical, 1 fully different.

func NormalizeBackend

func NormalizeBackend(s string) (string, error)

NormalizeBackend maps aliases.

func NormalizeStrength

func NormalizeStrength(s string) (string, error)

NormalizeStrength maps aliases.

func SelectCandidate

func SelectCandidate(original string, candidates []string) (string, []float64)

SelectCandidate picks the most lexically diverged rewrite.

Types

type Options

type Options struct {
	Backend      string
	Strength     string
	Model        string
	Endpoint     string
	APIKey       string
	Timeout      time.Duration
	Temperature  float64
	Candidates   int
	Lang         string
	OriginalLang string
	AllowRemote  bool
	LayerAAfter  bool
	Aggressive   bool // Layer A after: confusables
	HTTPClient   *http.Client
}

Options configure a single-file rewrite.

type Result

type Result struct {
	Text   string         `json:"text"`
	Prompt string         `json:"prompt,omitempty"`
	Info   map[string]any `json:"info"`
}

Result is the rewrite outcome.

func Run

func Run(ctx context.Context, text string, opt Options) (Result, error)

Run executes the rewrite hook.

Jump to

Keyboard shortcuts

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