pi-bridge 0.2.0 → 0.2.4

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 +39 -17
  2. package/package.json +1 -1
package/bin/pii.js CHANGED
@@ -14,26 +14,48 @@ if (process.argv.includes('--version') || process.argv.includes('-v') || process
14
14
  process.exit(0);
15
15
  }
16
16
 
17
- function findCli() {
18
- // 1. Standard npm global: pi-bridge and pi share the same node_modules prefix
17
+ function findPi() {
18
+ // 1. Standard npm global: both packages share the same node_modules prefix
19
19
  const shared = path.resolve(__dirname, '..', '..', '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
20
- if (fs.existsSync(shared)) return shared;
21
-
22
- // 2. GitHub clone / bundled install: pi.js sits next to the pi wrapper in PATH
23
- // Use `where` (Windows built-in) — more reliable than spawning PowerShell
24
- const whereCmd = os.platform() === 'win32' ? 'where' : 'which';
25
- try {
26
- const wrapper = execFileSync(whereCmd, ['pi'], { encoding: 'utf8' })
27
- .trim().split('\n')[0].trim();
28
- const sibling = wrapper.replace(/\.(ps1|cmd)$/i, '.js');
29
- if (fs.existsSync(sibling)) return sibling;
30
- } catch (_) {}
20
+ if (fs.existsSync(shared)) {
21
+ return { cli: shared, nodeExe: process.execPath };
22
+ }
23
+
24
+ // 2. Unix GitHub clone: which pi returns the JS file directly
25
+ if (os.platform() !== 'win32') {
26
+ try {
27
+ const wrapper = execFileSync('which', ['pi'], { encoding: 'utf8' }).trim();
28
+ if (fs.existsSync(wrapper)) return { cli: wrapper, nodeExe: process.execPath };
29
+ } catch (_) {}
30
+ }
31
+
32
+ // 3. Fallback: PowerShell Get-Command — handles custom/bundled Windows installs
33
+ // where pi lives outside the standard npm prefix. Also picks up the bundled
34
+ // node.exe that shipped alongside pi (required for version-matched execution).
35
+ if (os.platform() === 'win32') {
36
+ try {
37
+ const wrapper = execFileSync(
38
+ 'powershell',
39
+ ['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
40
+ { encoding: 'utf8' }
41
+ ).trim();
42
+ const basedir = path.dirname(wrapper);
43
+ const cli = wrapper.replace(/\.(ps1|cmd)$/i, '.js');
44
+ const localNode = path.join(basedir, 'node.exe');
45
+ const nodeExe = fs.existsSync(localNode) ? localNode : process.execPath;
46
+ if (fs.existsSync(cli)) return { cli, nodeExe };
47
+ } catch (_) {}
48
+ }
31
49
 
32
50
  return null;
33
51
  }
34
52
 
35
- const cli = findCli();
36
- if (!cli) {
53
+ let pi;
54
+ try {
55
+ pi = findPi();
56
+ } catch (_) {}
57
+
58
+ if (!pi) {
37
59
  process.stderr.write(
38
60
  'pii: Could not find pi.\n' +
39
61
  'Install it with: npm install -g @mariozechner/pi-coding-agent\n'
@@ -42,8 +64,8 @@ if (!cli) {
42
64
  }
43
65
 
44
66
  const result = spawnSync(
45
- process.execPath,
46
- ['--require', preload, cli, ...process.argv.slice(2)],
67
+ pi.nodeExe,
68
+ ['--require', preload, pi.cli, ...process.argv.slice(2)],
47
69
  { stdio: 'inherit' }
48
70
  );
49
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bridge",
3
- "version": "0.2.0",
3
+ "version": "0.2.4",
4
4
  "description": "Transparent filesystem bridge that makes pi run natively on a remote machine over SSH",
5
5
  "type": "commonjs",
6
6
  "bin": {