@tduyng/pi-edit-path 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +34 -15
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,34 +1,47 @@
1
1
  # @tduyng/pi-edit-path
2
2
 
3
- 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.
3
+ Two round trips on the edit path are avoidable. One follows a failed edit, the other follows a successful one.
4
4
 
5
- ## then_run
5
+ ## After a failed edit
6
6
 
7
- `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.
7
+ 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.
8
8
 
9
- 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.
9
+ The hint appends the closest region as it reads on disk now, with line numbers and current text, so the retry copies real lines.
10
10
 
11
- 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.
11
+ 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.
12
12
 
13
- 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.
13
+ 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.
14
14
 
15
- 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.
15
+ 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.
16
16
 
17
- ## The edit hint
17
+ ## Fusing the check
18
18
 
19
- 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.
19
+ 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.
20
20
 
21
- 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.
21
+ `then_run` is an optional parameter on `edit` and `write`. It runs after the mutation succeeds.
22
22
 
23
- 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.
23
+ ```text
24
+ edit(path: "src/retry.ts", edits: [...], then_run: {command: "bun test src/retry", timeout: 120})
25
+ ```
26
+
27
+ It 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.
28
+
29
+ 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.
30
+
31
+ `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.
24
32
 
25
- 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.
33
+ ## Cost and switches
26
34
 
27
- ## Cost
35
+ The hint adds no tool, no schema and no prompt text. It reads one file pi already named in its own error.
28
36
 
29
- 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.
37
+ `edit` gains four guideline bullets and `write` gains two. Those six bullets are the whole prompt cost of the fusion.
30
38
 
31
- `PI_HINT_EDIT_HINT=0` disables the hint. It accepts `false`, `no`, and `off` too.
39
+ | Variable | Default | Effect |
40
+ | --- | --- | --- |
41
+ | `PI_HINT_EDIT_HINT` | `1` | `0`, `false`, `no` or `off` disables the hint |
42
+ | `PI_ACTION_FUSION` | `1` | `0` disables the `then_run` parameter |
43
+
44
+ `then_run` runs through the `bash` tool, so that tool has to be active.
32
45
 
33
46
  ## Install
34
47
 
@@ -37,3 +50,9 @@ pi install npm:@tduyng/pi-edit-path
37
50
  ```
38
51
 
39
52
  Local checkout: `pi install /path/to/dotfiles/pi/agent/extensions/pi-edit-path`
53
+
54
+ ## Limits
55
+
56
+ - `then_run` output keeps the last 12,000 characters, and the result says it was cut.
57
+ - The hint refuses files over 2 MB, lists at most 80 region lines and 10 match lines.
58
+ - The hint reads the file as it is now, which is not always what it was when the edit failed.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tduyng/pi-edit-path",
3
- "version": "0.0.2",
4
- "description": "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.",
3
+ "version": "0.0.4",
4
+ "description": "Fuse the validation command into the edit that needs it, and name the region on disk a failed edit meant.",
5
5
  "keywords": [
6
6
  "pi",
7
7
  "pi-package",