@jerryan/pi-hashline-edit 0.7.4 → 0.8.2
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.
- package/LICENSE +21 -21
- package/README.md +6 -4
- package/index.ts +6 -0
- package/package.json +53 -53
- package/src/edit-diff.ts +201 -390
- package/src/edit.ts +81 -65
- package/src/file-kind.ts +130 -130
- package/src/fs-write.ts +76 -76
- package/src/hashline.ts +699 -1071
- package/src/package-info.ts +1 -1
- package/src/path-utils.ts +13 -13
- package/src/read.ts +3 -3
- package/src/runtime.ts +3 -3
- package/src/snapshot.ts +29 -29
- package/src/undo.ts +212 -0
- package/tool-descriptions/edit.md +23 -23
- package/tool-descriptions/read-guidelines.md +1 -1
- package/tool-descriptions/read.md +5 -5
- package/tool-descriptions/undo.md +8 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 RimuruW
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RimuruW
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# pi-hashline-edit
|
|
4
4
|
|
|
5
|
-
A [pi-
|
|
5
|
+
A fork of [pi-hashline-edit](https://github.com/RimuruW/pi-hashline-edit) with a trimmed edit schema, unified diff presentation, and extra safety guardrails. A [pi-coding-agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent) extension.
|
|
6
6
|
|
|
7
7
|
Every line returned by `read` carries a short content hash. Edits reference these hashes instead of raw text, so the tool can detect stale context and reject outdated changes before they reach the file.
|
|
8
8
|
|
|
@@ -10,13 +10,13 @@ Inspired by [oh-my-pi](https://github.com/can1357/oh-my-pi).
|
|
|
10
10
|
|
|
11
11
|
## Differences from upstream
|
|
12
12
|
|
|
13
|
-
This is a fork of the original [pi-hashline-edit](https://github.com/
|
|
13
|
+
This is a fork of the original [pi-hashline-edit](https://github.com/RimuruW/pi-hashline-edit). The core protocol (hash-anchored reads, stale-anchor rejection, atomic writes) is unchanged from upstream. Key differences:
|
|
14
14
|
|
|
15
15
|
- **Single edit shape.** One entry type: `{ range: [start, end], lines: [...] }`. No `op` field, no `append`/`prepend`/`replace_text` ops, no `after`/`before`. The tuple enforces explicit endpoint anchors, eliminating the common "forgot `end`" failure mode.
|
|
16
16
|
- **Standard hex hash alphabet.** `0-9 A-F` instead of `ZPMQVRWSNKTXJBYH`. Hex pairs are more likely to be single tokens.
|
|
17
17
|
- **Symmetric boundary-duplication detection.** Runtime warnings catch duplicated boundary lines on both sides of a replacement, not just trailing.
|
|
18
18
|
- **`read` raw mode.** `raw: true` returns plain text without `LINE#HASH│` anchors, for reads that don't plan to edit.
|
|
19
|
-
- **
|
|
19
|
+
- **Context-based FNV-1a hashing.** Each line's hash incorporates its immediate neighbors (previous and next). Distant edits don't invalidate anchors; nearby edits do, which is the intended safety behavior.
|
|
20
20
|
- **Minimal prompt surface.** Prompt text describes what the model needs to use the tool; return-format documentation and error catalogues are omitted.
|
|
21
21
|
- **No legacy compatibility.** The `{ oldText, newText }` substring-replace format is not accepted. The schema is hashline-only.
|
|
22
22
|
|
|
@@ -105,7 +105,9 @@ Each edit result shows a unified diff with hashline-formatted lines:
|
|
|
105
105
|
|
|
106
106
|
Hashes are computed with inline FNV-1a (32-bit, mask-reduced to 8 bits), then mapped to a 2-character hex string from `0-9 A-F`.
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
Each line's hash incorporates the line itself plus its immediate neighbors (previous and next). Missing neighbors at file boundaries contribute an empty string. This means:
|
|
109
|
+
- **Distant edits are stable.** Changing line 100 does not invalidate anchors on line 1.
|
|
110
|
+
- **Nearby edits are detected.** Changing line 5 invalidates anchors on lines 4, 5, and 6, because their context changed. The model must re-read to get fresh anchors for edits in that vicinity.
|
|
109
111
|
|
|
110
112
|
## Development
|
|
111
113
|
|
package/index.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { registerEditTool } from "./src/edit";
|
|
3
3
|
import { registerReadTool } from "./src/read";
|
|
4
|
+
import { registerUndoTool, setCurrentTurn } from "./src/undo";
|
|
4
5
|
|
|
5
6
|
export default function (pi: ExtensionAPI): void {
|
|
6
7
|
registerReadTool(pi);
|
|
7
8
|
registerEditTool(pi);
|
|
9
|
+
registerUndoTool(pi);
|
|
10
|
+
|
|
11
|
+
pi.on("turn_start", async (event) => {
|
|
12
|
+
setCurrentTurn(event.turnIndex);
|
|
13
|
+
});
|
|
8
14
|
|
|
9
15
|
const debugValue = process.env.PI_HASHLINE_DEBUG;
|
|
10
16
|
if (debugValue === "1" || debugValue === "true") {
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jerryan/pi-hashline-edit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/JerryAZR/pi-hashline-edit.git"
|
|
8
|
-
},
|
|
9
|
-
"author": "JerryAZR",
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"registry": "https://registry.npmjs.org/"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"pi-package",
|
|
15
|
-
"pi",
|
|
16
|
-
"coding-agent",
|
|
17
|
-
"extension",
|
|
18
|
-
"hashline"
|
|
19
|
-
],
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"files": [
|
|
22
|
-
"index.ts",
|
|
23
|
-
"src",
|
|
24
|
-
"tool-descriptions",
|
|
25
|
-
"README.md",
|
|
26
|
-
"LICENSE"
|
|
27
|
-
],
|
|
28
|
-
"pi": {
|
|
29
|
-
"extensions": [
|
|
30
|
-
"./index.ts"
|
|
31
|
-
]
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"diff": "^8.0.2",
|
|
35
|
-
"file-type": "^21.3.
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"@earendil-works/pi-ai": ">=0.74.0",
|
|
39
|
-
"@earendil-works/pi-coding-agent": ">=0.74.0",
|
|
40
|
-
"@earendil-works/pi-tui": "*",
|
|
41
|
-
"@sinclair/typebox": "*"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"test": "vitest run",
|
|
45
|
-
"test:watch": "vitest"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
49
|
-
"@types/node": "^22.0.0",
|
|
50
|
-
"ajv": "^8.20.0",
|
|
51
|
-
"vitest": "^3.0.0"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@jerryan/pi-hashline-edit",
|
|
3
|
+
"version": "0.8.2",
|
|
4
|
+
"description": "Fork of pi-hashline-edit with trimmed schema, unified diff, and extra safety guardrails.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/JerryAZR/pi-hashline-edit.git"
|
|
8
|
+
},
|
|
9
|
+
"author": "JerryAZR",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi",
|
|
16
|
+
"coding-agent",
|
|
17
|
+
"extension",
|
|
18
|
+
"hashline"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"index.ts",
|
|
23
|
+
"src",
|
|
24
|
+
"tool-descriptions",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"pi": {
|
|
29
|
+
"extensions": [
|
|
30
|
+
"./index.ts"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"diff": "^8.0.2",
|
|
35
|
+
"file-type": "^21.3.4"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@earendil-works/pi-ai": ">=0.74.0",
|
|
39
|
+
"@earendil-works/pi-coding-agent": ">=0.74.0",
|
|
40
|
+
"@earendil-works/pi-tui": "*",
|
|
41
|
+
"@sinclair/typebox": "*"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"ajv": "^8.20.0",
|
|
51
|
+
"vitest": "^3.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|