Install
Install with PiG
pig install npm:@tduyng/pi-edit-pathInstall with Pi
pi install npm:@tduyng/pi-edit-pathPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/edit-hint.ts",
"./src/action-fusion.ts",
"./src/shell-edit.ts",
"./src/syntax-check.ts",
"./src/verify-receipt.ts"
]
}README
Written by the package's publisher, shown as published in version 0.0.6 (README.md). PiG does not review it.
@tduyng/pi-edit-path
Three round trips on the edit path are avoidable. One follows a failed edit, one follows a successful one, and one follows an edit that broke the file's syntax.
After a failed edit
When pi's own edit cannot find the old text, or finds it more than once, it reports the miss and nothing else. The retry usually starts with a re-read, and often misses again because the old text was written from memory.
The hint appends the closest region as it reads on disk now, with line numbers and current text, so the retry copies real lines.
Matching is by line agreement, not character similarity. Every distinctive line of the old text is looked up in the file the way pi's own matcher would read it, counting only lines of four characters or more, so a lone } never votes. The window of the old text'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.
Line agreement hides the commonest cause. On one miss every distinctive line of a doc comment was present, because the model had re-wrapped the paragraph and written one word from memory. A line search cannot see a re-wrap, so the hint also names the lines that are not on disk at all.
An oldText that matches more than once gets the line numbers of each match, and for the first three the nearest line within six that occurs once in the file, with the lines between. Line numbers alone sent the model to sed -n or rg for the neighbours in 27 of 58 recorded duplicate failures, one round trip each.
The hint reports and never repairs. A miss that survives pi's fuzzy matching is a real mismatch, and applying a guess would write code nobody asked for.
Fusing the check
The other round trip is the one after the write. Edit a file, call bash to run the test, and that is a whole provider request to learn something the edit already implied.
then_run is an optional parameter on edit and write. It runs after the mutation succeeds.
edit(path: "src/retry.ts", edits: [...], then_run: {command: "bun test src/retry", timeout: 120})
The first write or edit in a session that carries more than 2,000 characters of content gets a note on its result, once, and never again in that session: the same bytes built inside a codemode script cost a few hundred characters of arguments and stay out of the transcript after that. Content the model generates character by character is the largest single line in a long session's context, 119,000 tokens of it in the longest one recorded. A call a codemode script makes gets no note, since the script built the content and the model did not pay for it.
then_run takes {command, timeout} in seconds, or the command as a plain string. On success then_run appends the output after [then_run:succeeded]. On failure it reports the mutation output first, then [then_run:failed] and the error, inside one thrown error, so the edit result is never lost.
then_run: "tests" picks the check itself: the tests that import the changed file. It lists the repository with git ls-files, reads relative imports in TypeScript and JavaScript and dotted imports in Python, and walks up to three levels of importers until a level holds a test.
A test file named after the changed file counts even without the import, an edited test runs itself, and Go runs the tests of the changed package. Each package runs with its own runner from its own root: vitest or jest when its package.json names one, bun test when a bun lockfile is there, pytest (through uv when there is a uv.lock), or go test.
The result lists the tests and the command before the output, and a file no test reaches says so without running anything, since a full suite is the slow answer the selection exists to avoid. Picking the tests costs about 40 ms on a 400-file repository and 300 ms on 3,000 files.
When the check follows from the file the edit just changed, pass then_run. Use a separate bash call when the check spans files not yet written, or when the edit result has to be read before deciding what to run.
then_run is a parameter rather than a tool because the built-in definition is spread into the extension's own. Every property pi had stays, and one optional field is added. A second tool would need its own schema, its own permission story, and a model deciding between two ways to change a file.
After an edit that breaks the syntax
An edit that leaves a brace open is found only by the next check, a turn later, and the error then points at a symptom far from the edit. SWE-agent rejected such edits at the tool and fixed more issues for it.
After each successful edit or write, the file is parsed again. When it no longer parses and it did before, the parser's own message with line and column is appended to the result. A file that was already broken stays quiet, so a refactor through a broken state is not nagged at every step. The edit is kept, never reverted.
| Files | Parser |
|---|---|
| TS, JS, JSX, TSX | bun build --no-bundle |
JSON, except tsconfig, jsconfig and .vscode | JSON.parse |
| Python | ast.parse |
| sh, bash, zsh, fish | -n on that shell |
| Nix | nix-instantiate --parse |
| Go | gofmt -e |
| Lua | luac -p |
A parser that is not installed is skipped. The check costs one parse on success, about 110 ms for bun and 10 ms for Python, and a second parse of the old text only when the new one fails.
The receipt in the footer
After a compaction, or after a long turn, the transcript no longer says what was checked and what changed since. The footer carries one segment for that.
| Footer | Meaning |
|---|---|
just check passed | the last check passed and nothing changed since |
2 edits since just check | two edits landed after the check that passed |
tsc failed | the last check failed |
1 edit unchecked | no check has run in this session |
A check is the command a project declares it with: just check, bun test, bun run typecheck, tsc, oxlint, pytest, cargo test, go test, make check, nix flake check, or a script named check, test, verify or lint. Wrappers are read through, so nice -n 19 just check and cd services && bun test are both recognised. A fused then_run counts as the edit's own check, which means then_run: "tests" that selected no test stays an edit and not a verification. bun build is not a check, because the syntax pass runs it after every edit and every edit would read as verified.
The segment costs nothing: no tool, no schema, no context text. The state is per session, so a claim never outlives the run that made it. It names the check and not its output.
Cost and switches
The hint adds no tool, no schema and no prompt text. It reads one file pi already named in its own error.
edit gains four guideline bullets and write gains two. Those six bullets are the whole prompt cost of the fusion.
| Variable | Default | Effect |
|---|---|---|
PI_HINT_EDIT_HINT | 1 | 0, false, no or off disables the hint |
PI_ACTION_FUSION | 1 | 0 disables the then_run parameter |
PI_SYNTAX_CHECK | 1 | 0 disables the parse after an edit |
PI_VERIFY_RECEIPT | 1 | 0 disables the footer receipt |
then_run runs through the bash tool, so that tool has to be active.
Install
pi install npm:@tduyng/pi-edit-path
Limits
then_runoutput keeps the last 12,000 characters, and the result says it was cut."tests"reads imports as text: path aliases, workspace package names, and Rust are not followed, so a test reached only through them is missed.- The hint refuses files over 2 MB, lists at most 80 region lines and 10 match lines.
- The hint reads the file as it is now, which is not always what it was when the edit failed.
- The receipt sees the tools: an edit made inside a codemode script, or a file changed on disk by another process after the check, leaves it alone.