@xynogen/pix-edit 0.1.0 → 0.1.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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # pix-edit
2
+
3
+ Pi tool — precise text replacement edit with diff rendering.
4
+
5
+ ## What it does
6
+
7
+ Replaces Pi's default `edit` tool with an enhanced version that renders a side-by-side split diff after every edit. The diff is syntax-highlighted with gutter markers, line numbers, and a change summary produced by `pix-pretty`'s diff engine. Batched edits (multiple `{oldText, newText}` pairs in one call) each render their own diff block. Call labels show the target file path and the number of edits being applied. Depends on `@xynogen/pix-pretty`, installed automatically as a dependency.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pi install npm:@xynogen/pix-edit
13
+ ```
14
+
15
+ ## Full distro
16
+
17
+ To install the complete pix suite (all packages + Pi itself):
18
+
19
+ ```bash
20
+ curl -fsSL https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.sh | sh
21
+ ```
22
+
23
+ ## License
24
+
25
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-edit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Pi tool — precise text replacement edit with diff rendering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/extension.ts CHANGED
@@ -9,42 +9,44 @@ import type {
9
9
  TextComponentCtor,
10
10
  } from "@xynogen/pix-pretty/types";
11
11
  import { shortPath } from "@xynogen/pix-pretty/utils";
12
-
13
12
  import { registerEditTool } from "./edit.js";
13
+ import { once } from "./once.ts";
14
14
 
15
15
  export default function pixEditExtension(pi: PiPrettyApi): void {
16
- let sdk: PiPrettySdk;
17
- try {
18
- sdk = require("@earendil-works/pi-coding-agent");
19
- } catch {
20
- return;
21
- }
16
+ once("pix-edit", () => {
17
+ let sdk: PiPrettySdk;
18
+ try {
19
+ sdk = require("@earendil-works/pi-coding-agent");
20
+ } catch {
21
+ return;
22
+ }
22
23
 
23
- const createEditTool = sdk.createEditToolDefinition ?? sdk.createEditTool;
24
- if (!createEditTool) return;
24
+ const createEditTool = sdk.createEditToolDefinition ?? sdk.createEditTool;
25
+ if (!createEditTool) return;
25
26
 
26
- let TextComponent: TextComponentCtor;
27
- try {
28
- TextComponent = require("@earendil-works/pi-tui").Text;
29
- } catch {
30
- return;
31
- }
27
+ let TextComponent: TextComponentCtor;
28
+ try {
29
+ TextComponent = require("@earendil-works/pi-tui").Text;
30
+ } catch {
31
+ return;
32
+ }
32
33
 
33
- const cwd = process.cwd();
34
- const home = process.env.HOME ?? "";
34
+ const cwd = process.cwd();
35
+ const home = process.env.HOME ?? "";
35
36
 
36
- attachResizeListener();
37
+ attachResizeListener();
37
38
 
38
- registerEditTool(
39
- pi,
40
- createEditTool,
41
- {
42
- cwd,
43
- sp: (p: string) => shortPath(cwd, home, p),
44
- TextComponent,
45
- fffState,
46
- cursorStore: new CursorStore(),
47
- },
48
- trackInvalidator,
49
- );
39
+ registerEditTool(
40
+ pi,
41
+ createEditTool,
42
+ {
43
+ cwd,
44
+ sp: (p: string) => shortPath(cwd, home, p),
45
+ TextComponent,
46
+ fffState,
47
+ cursorStore: new CursorStore(),
48
+ },
49
+ trackInvalidator,
50
+ );
51
+ });
50
52
  }
package/src/once.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Idempotency guard for extension activation.
3
+ *
4
+ * pix-core (the meta-package) invokes this package's factory in addition to a
5
+ * possible direct install. Pi's loader uses jiti with `moduleCache: false`, so
6
+ * each load pass re-evaluates modules — a plain module-level flag would not be
7
+ * shared. The dedupe key therefore lives on `globalThis`, which persists for
8
+ * the lifetime of the process across all load passes.
9
+ */
10
+ export function once(key: string, fn: () => void): void {
11
+ const g = globalThis as { __pixLoaded?: Set<string> };
12
+ const loaded = (g.__pixLoaded ??= new Set<string>());
13
+ if (loaded.has(key)) return;
14
+ loaded.add(key);
15
+ fn();
16
+ }