rewrite

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 9 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 rewrite adapts a copied session to the target machine.

It applies a single-pass prefix map (repo root, worktree, home, config dir) to every JSON string in the transcript, keys included, on path boundaries. It handles JSON-escaped Windows paths and paths that follow JSON escapes, converts separators below mapped folders between Windows and macOS/Linux, and never edits ids or signed thinking blocks (dropping them whole only for cross-account moves). It strips the source's Remote Control link record, optionally redacts secrets, and appends a `relocated` record the way Claude Code's own /cd does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Text

func Text(r io.Reader, w io.Writer, mappings []Mapping) (int, error)

Text rewrites a plain-text file (spilled tool output) with unescaped path forms.

Types

type Mapping

type Mapping = agent.Mapping

Mapping replaces one absolute path prefix with another (unescaped paths).

type Options

type Options struct {
	Mappings []Mapping
	// Policy is the agent module's: protected keys, dropped records and elements, renames.
	Policy agent.RewritePolicy
	// Redact, if set, is applied to every rewritable string token (raw JSON bytes) after path
	// mapping; it returns the new bytes and how many secrets it replaced.
	Redact func(raw []byte) ([]byte, int)
}

Options controls a rewrite.

type Stats

type Stats struct {
	Lines          int            `json:"lines"`
	LinesChanged   int            `json:"linesChanged"`
	Replacements   map[string]int `json:"replacements"` // by Mapping.From
	DroppedRecords int            `json:"droppedRecords,omitempty"`
	DroppedElems   int            `json:"droppedElements,omitempty"`
	RenamedIDs     int            `json:"renamedIds,omitempty"`
	Redactions     int            `json:"redactions"`
}

Stats reports what a rewrite changed.

func JSONL

func JSONL(r io.Reader, w io.Writer, opt Options) (Stats, error)

JSONL rewrites a transcript from r to w, line by line. Unchanged lines are copied byte for byte; the line structure (and the order of keys) is always preserved.

Jump to

Keyboard shortcuts

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