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.
- package/bin/pii.js +23 -45
- 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
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
42
|
+
process.execPath,
|
|
65
43
|
['--require', preload, cli, ...process.argv.slice(2)],
|
|
66
44
|
{ stdio: 'inherit' }
|
|
67
45
|
);
|