pi-lean-edit

Safer, cheaper edits by verifying prior reads in the harness instead of the prompt. Lets the harness verify the model already read the latest text it wants to edit, avoiding old-text replay and hash-decorated reads.

Packages

Package details

extension

Install pi-lean-edit from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-lean-edit
Package
pi-lean-edit
Version
0.3.6
Published
Aug 28, 2026
Downloads
939/mo · 36/wk
Author
sergiobonf
License
unknown
Types
extension
Size
84.4 KB
Dependencies
2 dependencies · 4 peers
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-lean-edit

Safer, cheaper edits by verifying prior reads in the harness instead of the prompt.

Formerly pi-smart-edit.

pi-lean-edit lets the harness verify the model already read the latest text it wants to edit, reducing stale-edit failures without resending old text in edit requests and without the per-read overhead of hash-decorated output.

Install or test

Install permanently:

pi install npm:pi-lean-edit

Test without installing permanently:

pi --no-extensions -e npm:pi-lean-edit

To load it alongside your normal setup:

pi -e npm:pi-lean-edit

Tools

read

{ path: string; offset?: number; limit?: number; columnOffset?: number; columnLimit?: number }

Only path is required. For normal reads, use path alone or offset/limit for a line range. Use columnOffset with columnLimit only for a huge single-line window; omit limit or set limit=1. Shows numbered text lines and stores shown ranges as in-memory snapshots for that file. Adjacent line reads merge into wider covered ranges. Adjacent/overlapping huge-line column windows compose into wider column coverage.

edit

type LineRange = { startLine: number; endLine?: number; newText: string };
type ColumnRange = { startLine: number; startColumn: number; endColumn: number; newText: string };

LineRange & { path: string }
// or
ColumnRange & { path: string }
// or either range shape in a batch
{ path: string; edits: Array<LineRange | ColumnRange> }

edit applies one or more non-overlapping inclusive ranges only when the requested text matches text previously shown by read or a failed edit. Column ranges must stay within one source line, but their replacement text may contain newlines. If a range was not read or its text changed, the edit is not applied; for line-range edits, the error returns and snapshots the current target with up to five surrounding lines on each side so the same or a nearby corrected edit can be retried. Text beyond the configured automatic output limits still requires read. Normal-line column reads show the whole line; huge-line column reads can cover matching column ranges. After a successful edit, edited text must be read again before reuse. Line-count-preserving edits keep unaffected later reads valid; line-count-changing edits invalidate them.

Concurrency

Cooperating pi-lean-edit processes in one checkout serialize edit and write mutations per canonical file; different files can still proceed concurrently. Snapshots remain per process, so every subagent must perform its own read before edit. For substantial parallel work, isolated worktrees or disjoint files are still preferable. Shell commands and other tools that do not use this cooperative lock can still race with these operations.

Metrics

Successful edits record saved characters versus exact-text edit payloads. Failed edits increment failure rate. Global metrics persist at ~/.pi/agent/pi-lean-edit/metrics.json by default, or PI_LEAN_EDIT_METRICS_PATH if set.

Show stats:

/lean-edit-stats

Test

npm test

Configuration

Run /lean-edit-settings to configure both collapsed and expanded rendering for read, edit, and write. ctrl+o switches between those two configured views. Each setting accepts:

  • minimal: compact rendering
  • medium: detailed rendering capped at 20 rendered lines
  • full: fully detailed rendering

Collapsed defaults are all minimal. Expanded defaults are read=minimal, edit=full, and write=medium. Settings persist globally in ~/.pi/agent/pi-lean-edit/settings.json.

read output is capped by line and byte limits. Defaults: PI_LEAN_EDIT_MAX_READ_LINES=2000, PI_LEAN_EDIT_MAX_READ_BYTES=50000.