pi-bridge 0.1.1 → 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.
Files changed (2) hide show
  1. package/bin/pii.js +22 -28
  2. package/package.json +1 -1
package/bin/pii.js CHANGED
@@ -4,15 +4,11 @@
4
4
  /**
5
5
  * pii — pi-bridge entry point installed as a global binary.
6
6
  *
7
- * Locates the `pi` CLI JS file and its bundled Node binary (if any), then
8
- * respawns with --require preload.js so the bridge is active before pi loads.
7
+ * Locates the pi CLI via `npm root -g` (cross-platform), then respawns
8
+ * Node with --require preload.js so the bridge is active before pi loads.
9
9
  *
10
- * Resolution strategy (same on all platforms):
11
- * 1. Get the wrapper script path from the system (which pi / Get-Command pi)
12
- * 2. Derive basedir from the wrapper path
13
- * 3. Find the actual CLI JS at basedir/node_modules/@mariozechner/pi-coding-agent/dist/cli.js
14
- * 4. Use basedir/node.exe if present (pi ships its own Node on some installs),
15
- * otherwise fall back to the current Node binary
10
+ * On Windows, also checks for a node.exe bundled alongside the pi wrapper
11
+ * (some installs ship their own Node binary) and prefers it if present.
16
12
  */
17
13
 
18
14
  const { spawnSync, execFileSync } = require('child_process');
@@ -22,24 +18,11 @@ const os = require('os');
22
18
 
23
19
  const preload = path.join(__dirname, '..', 'src', 'local', 'preload.js');
24
20
 
25
- const PI_CLI_REL = path.join('node_modules', '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
26
-
27
- function getWrapperPath() {
28
- if (os.platform() === 'win32') {
29
- return execFileSync(
30
- 'powershell',
31
- ['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
32
- { encoding: 'utf8' }
33
- ).trim();
34
- }
35
- return execFileSync('which', ['pi'], { encoding: 'utf8' }).trim();
36
- }
37
-
38
21
  function findPiCli() {
39
- const wrapper = getWrapperPath();
40
- const basedir = path.dirname(wrapper);
22
+ // npm root -g gives the exact global node_modules dir on all platforms
23
+ const npmRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim();
24
+ const cli = path.join(npmRoot, '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
41
25
 
42
- const cli = path.join(basedir, PI_CLI_REL);
43
26
  if (!fs.existsSync(cli)) {
44
27
  throw new Error(
45
28
  'Could not find pi CLI at ' + cli + '\n' +
@@ -47,11 +30,22 @@ function findPiCli() {
47
30
  );
48
31
  }
49
32
 
50
- // Prefer the Node binary bundled alongside pi (some installs ship node.exe)
51
- const localNode = path.join(basedir, 'node.exe');
52
- const nodeExe = fs.existsSync(localNode) ? localNode : process.execPath;
33
+ // On Windows, prefer the node.exe bundled alongside the pi wrapper if present
34
+ if (os.platform() === 'win32') {
35
+ try {
36
+ const wrapper = execFileSync(
37
+ 'powershell',
38
+ ['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
39
+ { encoding: 'utf8' }
40
+ ).trim();
41
+ const localNode = path.join(path.dirname(wrapper), 'node.exe');
42
+ if (fs.existsSync(localNode)) {
43
+ return { cli, nodeExe: localNode };
44
+ }
45
+ } catch (_) {}
46
+ }
53
47
 
54
- return { cli, nodeExe };
48
+ return { cli, nodeExe: process.execPath };
55
49
  }
56
50
 
57
51
  let cli, nodeExe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bridge",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Transparent filesystem bridge that makes pi run natively on a remote machine over SSH",
5
5
  "type": "commonjs",
6
6
  "bin": {