pi-bridge 0.2.2 → 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.
- package/bin/pii.js +22 -11
- package/package.json +1 -1
package/bin/pii.js
CHANGED
|
@@ -14,20 +14,24 @@ if (process.argv.includes('--version') || process.argv.includes('-v') || process
|
|
|
14
14
|
process.exit(0);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
// 1. Standard npm global:
|
|
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))
|
|
20
|
+
if (fs.existsSync(shared)) {
|
|
21
|
+
return { cli: shared, nodeExe: process.execPath };
|
|
22
|
+
}
|
|
21
23
|
|
|
22
24
|
// 2. Unix GitHub clone: which pi returns the JS file directly
|
|
23
25
|
if (os.platform() !== 'win32') {
|
|
24
26
|
try {
|
|
25
27
|
const wrapper = execFileSync('which', ['pi'], { encoding: 'utf8' }).trim();
|
|
26
|
-
if (fs.existsSync(wrapper)) return wrapper;
|
|
28
|
+
if (fs.existsSync(wrapper)) return { cli: wrapper, nodeExe: process.execPath };
|
|
27
29
|
} catch (_) {}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
// 3.
|
|
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).
|
|
31
35
|
if (os.platform() === 'win32') {
|
|
32
36
|
try {
|
|
33
37
|
const wrapper = execFileSync(
|
|
@@ -35,16 +39,23 @@ function findCli() {
|
|
|
35
39
|
['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
|
|
36
40
|
{ encoding: 'utf8' }
|
|
37
41
|
).trim();
|
|
38
|
-
const
|
|
39
|
-
|
|
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 };
|
|
40
47
|
} catch (_) {}
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
return null;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
let pi;
|
|
54
|
+
try {
|
|
55
|
+
pi = findPi();
|
|
56
|
+
} catch (_) {}
|
|
57
|
+
|
|
58
|
+
if (!pi) {
|
|
48
59
|
process.stderr.write(
|
|
49
60
|
'pii: Could not find pi.\n' +
|
|
50
61
|
'Install it with: npm install -g @mariozechner/pi-coding-agent\n'
|
|
@@ -53,8 +64,8 @@ if (!cli) {
|
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
const result = spawnSync(
|
|
56
|
-
|
|
57
|
-
['--require', preload, cli, ...process.argv.slice(2)],
|
|
67
|
+
pi.nodeExe,
|
|
68
|
+
['--require', preload, pi.cli, ...process.argv.slice(2)],
|
|
58
69
|
{ stdio: 'inherit' }
|
|
59
70
|
);
|
|
60
71
|
|