@heyhuynhgiabuu/pi-diff 0.8.1 → 0.9.0
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/README.md +6 -0
- package/dist/core/apply-patch.d.ts +18 -3
- package/dist/core/apply-patch.d.ts.map +1 -1
- package/dist/core/apply-patch.js +492 -116
- package/dist/core/apply-patch.js.map +1 -1
- package/dist/core/replace.d.ts +8 -0
- package/dist/core/replace.d.ts.map +1 -1
- package/dist/core/replace.js +38 -19
- package/dist/core/replace.js.map +1 -1
- package/dist/core/text-encoding.d.ts +4 -2
- package/dist/core/text-encoding.d.ts.map +1 -1
- package/dist/core/text-encoding.js +13 -6
- package/dist/core/text-encoding.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -76
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -53,6 +53,12 @@ pi-diff wraps the built-in `write` and `edit` tools from the pi SDK, including s
|
|
|
53
53
|
|
|
54
54
|
For `edit` calls, Pi's SDK performs matching, uniqueness and overlap validation, mutation queueing, and the file write. pi-diff adapts the SDK's returned unified patch into its syntax-highlighted renderer, so the preview reflects the actual matched source rather than the requested text.
|
|
55
55
|
|
|
56
|
+
### `apply_patch` safety contract
|
|
57
|
+
|
|
58
|
+
`apply_patch` remains a separate structured JSON tool for multi-file add, update, delete, and move operations. Paths are resolved relative to Pi's current workspace and must remain inside it; ancestor symlinks are rejected. Updates may use one `oldText`/`newText` replacement or an `edits` array of disjoint replacements matched against the original file.
|
|
59
|
+
|
|
60
|
+
All changes are prepared before the first commit. A commit failure triggers reverse-order rollback, but filesystem rollback is necessarily best effort; callers should treat a failed result as requiring verification. Existing files are never intentionally clobbered by `add` or `move`, and invalid UTF-8 files are rejected rather than rewritten as text.
|
|
61
|
+
|
|
56
62
|
The rendering pipeline:
|
|
57
63
|
|
|
58
64
|
```
|
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
* apply_patch — Multi-file patch engine.
|
|
3
3
|
*
|
|
4
4
|
* One call can add, update, delete, or move multiple files.
|
|
5
|
-
*
|
|
5
|
+
* Updates use a conservative matcher and are committed only after every
|
|
6
|
+
* change has been prepared successfully.
|
|
6
7
|
*/
|
|
8
|
+
export interface ApplyPatchEdit {
|
|
9
|
+
oldText: string;
|
|
10
|
+
newText: string;
|
|
11
|
+
}
|
|
7
12
|
export interface ApplyPatchChange {
|
|
8
|
-
/**
|
|
13
|
+
/** Path to the file, relative to the patch workspace or absolute within it. */
|
|
9
14
|
path: string;
|
|
10
15
|
action: "add" | "update" | "delete" | "move";
|
|
11
16
|
/** Content for new files (action=add). */
|
|
@@ -14,9 +19,17 @@ export interface ApplyPatchChange {
|
|
|
14
19
|
oldText?: string;
|
|
15
20
|
/** Replacement text for updates (action=update). */
|
|
16
21
|
newText?: string;
|
|
22
|
+
/** Multiple disjoint replacements for one update target. */
|
|
23
|
+
edits?: ApplyPatchEdit[];
|
|
17
24
|
/** Destination path for moves (action=move). */
|
|
18
25
|
movePath?: string;
|
|
19
26
|
}
|
|
27
|
+
export interface ApplyPatchOptions {
|
|
28
|
+
/** Base directory for relative paths. Defaults to the process cwd. */
|
|
29
|
+
cwd?: string;
|
|
30
|
+
/** Workspace boundary. Defaults to cwd. */
|
|
31
|
+
root?: string;
|
|
32
|
+
}
|
|
20
33
|
export interface ApplyPatchResult {
|
|
21
34
|
ok: boolean;
|
|
22
35
|
applied: AppliedChange[];
|
|
@@ -36,6 +49,8 @@ export interface ApplyPatchError {
|
|
|
36
49
|
action: string;
|
|
37
50
|
error: string;
|
|
38
51
|
}
|
|
39
|
-
|
|
52
|
+
/** Decode the model-facing tool payload before it reaches the mutation core. */
|
|
53
|
+
export declare function parseApplyPatchInput(input: unknown): ApplyPatchChange[];
|
|
54
|
+
export declare function executeApplyPatch(changes: ApplyPatchChange[], options?: ApplyPatchOptions): Promise<ApplyPatchResult>;
|
|
40
55
|
export declare function formatApplyPatchResult(result: ApplyPatchResult): string;
|
|
41
56
|
//# sourceMappingURL=apply-patch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-patch.d.ts","sourceRoot":"","sources":["../../src/core/apply-patch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"apply-patch.d.ts","sourceRoot":"","sources":["../../src/core/apply-patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAChC,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC7C,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IACjC,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,MAAM,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,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