omp packages

@tduyng/pi-edit-path0.0.2

Two halves of one edit path: fuse the validation command into the edit that needs it, and name the region on disk a failed edit meant so the retry lands without a re-read.

tienduy-nguyen Published 8 hours ago Apache-2.0 ~183 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

@tduyng/pi-edit-path

Two halves of one edit path. then_run fuses the validation command into the edit that needs it, and the edit hint names the region on disk a failed edit meant, so the retry lands without a re-read.

then_run

then_run is an optional parameter on edit and write: an object with command and timeout (seconds), or the command as a plain string. It runs after the mutation succeeds and is skipped if the mutation fails.

A string carrying an object literal, then_run: '{command: "npm test"}', is read for its command and timeout rather than handed to bash, which used to run the braces and answer command not found. A string with no key in it stays the command. A literal naming no command is reported as a then_run failure after the mutation has landed, so the model is told the file changed and what the argument should have been.

Success and failure use sentinel markers. On success the command output is appended to the mutation result preceded by [then_run:succeeded]. On failure the mutation output is reported first, followed by [then_run:failed] and the error message, all wrapped in a single thrown error so the mutation result is not lost.

The tool definitions are extended, not replaced: the built-in edit and write schemas keep their properties and gain an optional then_run. Each working directory gets its own cached tool definition.

Two guidelines ride on the tool prompts. Pass then_run when the check follows from the same file the edit or write just changed. Use a separate bash call when the check does not follow from the edit, spans files not yet written, or when the model needs to read the edit result before deciding what to run.

The edit hint

On a tool_result where pi's own edit could not find the old text or matched it more than once, the hint appends what the read was for: the closest region as it reads on disk now, with line numbers and current text, or the line of every match when the old text matches more than once. The retry copies old text from those lines.

The hint reports, it never repairs. A miss that survives pi's fuzzy matching is a real mismatch, and silently applying a guess there would write code nobody asked for.

A region is found by line agreement, not by character count. Every distinctive line of old text (at least four characters, so a lone } never votes) is looked up in the file as pi's own matcher would read it, and the window of oldText's height holding the most of them wins. Under half agreeing means no region is shown, because a weak guess invites an edit against the wrong lines.

Agreement alone hides the commonest cause. On a miss where every distinctive line of a doc comment was present in the file, the model had re-wrapped a paragraph at a different column and written one word from memory. A line-for-line search cannot see a re-wrap, so the lines that are in no way on disk are listed by name next to the region.

Cost

The hint adds no tool, no schema and no prompt text. It reads the file pi already named in the error. A file over 2MB is not read. then_run costs two guideline bullets on the edit and write prompts and saves one provider round trip per fused check.

PI_HINT_EDIT_HINT=0 disables the hint. It accepts false, no, and off too.

Install

pi install npm:@tduyng/pi-edit-path

Local checkout: pi install /path/to/dotfiles/pi/agent/extensions/pi-edit-path