pi-smart-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-smart-edit from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-smart-edit
Package
pi-smart-edit
Version
0.1.3
Published
May 24, 2026
Downloads
not available
Author
sergiobonf
License
unknown
Types
extension
Size
55.3 KB
Dependencies
1 dependency · 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-smart-edit

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

pi-smart-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-smart-edit

Test without installing permanently:

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

To load it alongside your normal setup:

pi -e npm:pi-smart-edit

Tools

read

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

Shows numbered text lines and stores shown ranges as in-memory snapshots for that file. Adjacent reads merge into wider covered ranges.

edit

{ path: string; startLine: number; endLine?: number; newText: string }
// or
{ path: string; edits: Array<{ startLine: number; endLine?: number; newText: string }> }

edit applies one or more non-overlapping inclusive ranges after read has shown those ranges for the same canonical file. If the file changed, it fails with file stale, read again.

Metrics

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

Show stats:

/smart-edit-stats

Test

npm test

Test

npm test

Notes

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