editor

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultIdleThreshold = 2 * time.Second

DefaultIdleThreshold is the minimum time since last modification before a live edit is considered safe.

View Source
const TransparentPNG1x1 = "" /* 152-byte string literal not displayed */

TransparentPNG1x1 is a 1x1 transparent PNG encoded as base64.

Variables

View Source
var ErrRaceDetected = errors.New("race detected: file modified during live edit")

ErrRaceDetected is returned when the JSONL file changes during a live edit, indicating Claude Code wrote between operations.

View Source
var ErrSessionNotIdle = errors.New("session not idle: mtime too recent")

ErrSessionNotIdle is returned when the session mtime is too recent to safely edit.

Functions

func CountSeparatorTokens added in v0.3.0

func CountSeparatorTokens(entries []jsonl.Entry) int

CountSeparatorTokens estimates the token cost of separators in entries.

func IsIdle added in v0.3.0

func IsIdle(path string, threshold time.Duration) (bool, time.Time, error)

IsIdle returns true if the file's mtime is older than threshold. Also returns the current mtime for subsequent race detection.

Types

type CleanAllResult added in v0.3.0

type CleanAllResult struct {
	ProgressRemoved    int
	SnapshotsRemoved   int
	SidechainsRemoved  int
	TangentsRemoved    int
	FailedRetries      int
	StaleReadsRemoved  int
	ImagesReplaced     int
	SeparatorsStripped int
	OutputsTruncated   int
	TotalTokensSaved   int
	BytesBefore        int64
	BytesAfter         int64
}

CleanAllResult holds the combined results of all cleanup operations.

func CleanAll added in v0.3.0

func CleanAll(path string) (*CleanAllResult, error)

CleanAll runs all cleanup operations in optimal order with a single backup. Order: entry deletions first, then content surgery.

type CleanLiveOpts added in v0.3.0

type CleanLiveOpts struct {
	Aggressive bool          // include Tier 4-5 (images, separators, truncation)
	Threshold  time.Duration // idle threshold (default: DefaultIdleThreshold)
}

CleanLiveOpts configures a live cleanup pass.

type CleanLiveResult added in v0.3.0

type CleanLiveResult struct {
	ProgressRemoved    int
	SnapshotsRemoved   int
	ImagesReplaced     int // Tier 4, only with Aggressive
	SeparatorsStripped int // Tier 4, only with Aggressive
	OutputsTruncated   int // Tier 5, only with Aggressive
	TotalTokensSaved   int
	BytesBefore        int64
	BytesAfter         int64
}

CleanLiveResult holds the combined results of live cleanup operations.

func CleanLive added in v0.3.0

func CleanLive(path string, opts CleanLiveOpts) (*CleanLiveResult, error)

CleanLive runs safe cleanup operations on a potentially active session.

Tier 1: progress removal Tier 2: snapshot removal With Aggressive: Tier 4: image replacement, separator stripping Tier 5: bash output truncation

Between each sub-operation, the file mtime is checked. If it changed (meaning Claude Code wrote to it), the operation aborts and restores from the original backup.

Tier 6-7 operations (sidechains, tangents, retries, dedup) are NEVER available in live mode regardless of flags.

type DedupResult added in v0.3.0

type DedupResult struct {
	StaleReadsRemoved int
	EntriesRemoved    int
	BlocksRemoved     int
	ChainRepairs      int
	BytesBefore       int64
	BytesAfter        int64
}

DedupResult holds the result of a duplicate read deduplication operation.

func DeduplicateReads added in v0.3.0

func DeduplicateReads(path string, dupResult *analyzer.DuplicateReadResult) (*DedupResult, error)

DeduplicateReads removes stale file read tool_use/tool_result pairs. For each stale read:

  • If assistant message has only that tool_use → delete entire entry
  • If assistant message has other blocks → remove just that tool_use block
  • Remove the corresponding tool_result block from user message
  • If user message only has that tool_result → delete entire entry

Always creates a backup before modifying.

type DeleteResult

type DeleteResult struct {
	EntriesRemoved int
	ChainRepairs   int
	BytesBefore    int64
	BytesAfter     int64
}

DeleteResult holds the result of a delete operation.

func Delete

func Delete(path string, toDelete map[int]bool) (*DeleteResult, error)

Delete removes selected entries from a JSONL file, repairing parentUuid chains. Always creates a backup before modifying.

func RemoveProgress

func RemoveProgress(path string) (*DeleteResult, error)

RemoveProgress removes all progress messages from a JSONL file. Always creates a backup before modifying.

type RepairResult added in v0.3.0

type RepairResult struct {
	IssuesFixed    int
	EntriesRemoved int
	ImagesReplaced int
	ChainRepairs   int
}

RepairResult holds the outcome of a repair operation.

func Repair added in v0.3.0

func Repair(path string, issues []analyzer.Issue) (*RepairResult, error)

Repair applies fixes for detected issues. Creates a backup before modifying. Uses dry-run via Diagnose first.

type ReplaceImagesResult

type ReplaceImagesResult struct {
	ImagesReplaced int
	BytesSaved     int64
}

ReplaceImagesResult holds the result of an image replacement operation.

func ReplaceImages

func ReplaceImages(path string) (*ReplaceImagesResult, error)

ReplaceImages replaces all base64 images with 1x1 transparent PNG placeholders. Always creates a backup before modifying.

type RetryCleanResult added in v0.3.0

type RetryCleanResult struct {
	FailedRemoved  int
	EntriesRemoved int
	BlocksRemoved  int
	ChainRepairs   int
	BytesBefore    int64
	BytesAfter     int64
}

RetryCleanResult holds the result of a failed retry cleanup operation.

func RemoveFailedRetries added in v0.3.0

func RemoveFailedRetries(path string, retryResult *analyzer.RetryResult) (*RetryCleanResult, error)

RemoveFailedRetries removes failed tool attempts that were superseded by retries. For each failed sequence:

  • Remove the tool_use block from the assistant message (or whole entry if only block)
  • Remove the error tool_result block from the user message (or whole entry)

Always creates a backup before modifying.

type StripResult added in v0.3.0

type StripResult struct {
	LinesStripped    int
	MessagesModified int
	CharsSaved       int
}

StripResult holds the outcome of separator stripping.

func StripSeparators added in v0.3.0

func StripSeparators(path string) (*StripResult, error)

StripSeparators removes decorative separator lines from assistant messages. Only modifies assistant entries. Creates a backup before writing.

type TruncateResult added in v0.3.0

type TruncateResult struct {
	OutputsTruncated int
	TokensSaved      int
	BytesBefore      int64
	BytesAfter       int64
}

TruncateResult holds the result of an output truncation operation.

func TruncateOutputs added in v0.3.0

func TruncateOutputs(path string, threshold, keepLines int) (*TruncateResult, error)

TruncateOutputs truncates large Bash tool_result content to first+last keepLines lines. threshold is the minimum byte size to trigger truncation. keepLines is the number of lines to keep at the start and end.

Jump to

Keyboard shortcuts

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