rewrite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 7 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 struct {
	From string `json:"from"`
	To   string `json:"to"`
	// ToSep, when set ("/" or `\`), also converts the path separators that follow a
	// match (for moves between Windows and macOS/Linux). The rest of the path ends at the
	// first byte that cannot be part of a file name segment, such as a space or quote.
	ToSep string `json:"toSep,omitempty"`
}

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

type Options

type Options struct {
	Mappings []Mapping
	// DropThinking removes thinking / redacted_thinking blocks entirely. Required when the
	// target machine is signed in to a different Anthropic account: those blocks carry
	// signatures bound to the original account, and removing only the signature fails.
	DropThinking bool
	// StripBridge drops bridge-session records so the copy does not reattach to the source
	// session's Remote Control link.
	StripBridge bool
	// AppendRelocated appends {"type":"relocated",...} the way Claude Code's /cd does, so
	// readers of the last 64 KB see the new project directory.
	SessionID    string
	RelocatedCWD string
	// 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 transcript rewrite.

type Stats

type Stats struct {
	Lines            int            `json:"lines"`
	LinesChanged     int            `json:"linesChanged"`
	Replacements     map[string]int `json:"replacements"` // by Mapping.From
	DroppedBridge    int            `json:"droppedBridge"`
	DroppedThinking  int            `json:"droppedThinking"`
	Redactions       int            `json:"redactions"`
	AppendedRelocate bool           `json:"appendedRelocated"`
}

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