pi-bridge 0.1.5 → 0.1.9

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 +23 -45
  2. package/package.json +1 -1
package/bin/pii.js CHANGED
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- /**
5
- * pii — pi-bridge entry point installed as a global binary.
6
- *
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
- *
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.
12
- */
13
-
14
4
  const { spawnSync, execFileSync } = require('child_process');
15
5
  const path = require('path');
16
6
  const fs = require('fs');
@@ -18,50 +8,38 @@ const os = require('os');
18
8
 
19
9
  const preload = path.join(__dirname, '..', 'src', 'local', 'preload.js');
20
10
 
21
- function findPiCli() {
11
+ function findCli() {
12
+ // 1. Standard npm global: pi-bridge and pi share the same node_modules prefix
13
+ const shared = path.resolve(__dirname, '..', '..', '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
14
+ if (fs.existsSync(shared)) return shared;
15
+
16
+ // 2. Windows bundled/custom install: pi.js sits next to pi.ps1 (no node_modules structure)
22
17
  if (os.platform() === 'win32') {
23
- // On Windows: resolve from the pi.ps1 wrapper's basedir.
24
- // npm puts binaries and node_modules in the same directory on Windows.
25
- const wrapper = execFileSync(
26
- 'powershell',
27
- ['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
28
- { encoding: 'utf8' }
29
- ).trim();
30
- const basedir = path.dirname(wrapper);
31
- const cli = path.join(basedir, 'node_modules', '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
32
- if (!fs.existsSync(cli)) {
33
- throw new Error(
34
- 'Could not find pi CLI at ' + cli + '\n' +
35
- 'Make sure pi is installed: npm install -g @mariozechner/pi-coding-agent'
36
- );
37
- }
38
- // Prefer the Node binary bundled alongside pi if present
39
- const localNode = path.join(basedir, 'node.exe');
40
- return { cli, nodeExe: fs.existsSync(localNode) ? localNode : process.execPath };
18
+ try {
19
+ const wrapper = execFileSync(
20
+ 'powershell',
21
+ ['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
22
+ { encoding: 'utf8' }
23
+ ).trim();
24
+ const sibling = wrapper.replace(/\.(ps1|cmd)$/i, '.js');
25
+ if (fs.existsSync(sibling)) return sibling;
26
+ } catch (_) {}
41
27
  }
42
28
 
43
- // Unix/macOS: npm puts packages in lib/node_modules, use npm root -g
44
- const npmRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim();
45
- const cli = path.join(npmRoot, '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
46
- if (!fs.existsSync(cli)) {
47
- throw new Error(
48
- 'Could not find pi CLI at ' + cli + '\n' +
49
- 'Make sure pi is installed: npm install -g @mariozechner/pi-coding-agent'
50
- );
51
- }
52
- return { cli, nodeExe: process.execPath };
29
+ return null;
53
30
  }
54
31
 
55
- let cli, nodeExe;
56
- try {
57
- ({ cli, nodeExe } = findPiCli());
58
- } catch (err) {
59
- process.stderr.write('pii: ' + err.message + '\n');
32
+ const cli = findCli();
33
+ if (!cli) {
34
+ process.stderr.write(
35
+ 'pii: Could not find pi.\n' +
36
+ 'Install it with: npm install -g @mariozechner/pi-coding-agent\n'
37
+ );
60
38
  process.exit(1);
61
39
  }
62
40
 
63
41
  const result = spawnSync(
64
- nodeExe,
42
+ process.execPath,
65
43
  ['--require', preload, cli, ...process.argv.slice(2)],
66
44
  { stdio: 'inherit' }
67
45
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bridge",
3
- "version": "0.1.5",
3
+ "version": "0.1.9",
4
4
  "description": "Transparent filesystem bridge that makes pi run natively on a remote machine over SSH",
5
5
  "type": "commonjs",
6
6
  "bin": {