pi-bridge 0.1.5 → 0.1.8
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 +9 -52
- package/package.json +1 -1
package/bin/pii.js
CHANGED
|
@@ -1,67 +1,24 @@
|
|
|
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
|
-
const { spawnSync, execFileSync } = require('child_process');
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
15
5
|
const path = require('path');
|
|
16
|
-
const fs = require('fs');
|
|
17
|
-
const os = require('os');
|
|
18
6
|
|
|
19
7
|
const preload = path.join(__dirname, '..', 'src', 'local', 'preload.js');
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
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 };
|
|
41
|
-
}
|
|
42
|
-
|
|
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 };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let cli, nodeExe;
|
|
9
|
+
let cli;
|
|
56
10
|
try {
|
|
57
|
-
|
|
58
|
-
} catch (
|
|
59
|
-
process.stderr.write(
|
|
11
|
+
cli = require.resolve('@mariozechner/pi-coding-agent');
|
|
12
|
+
} catch (_) {
|
|
13
|
+
process.stderr.write(
|
|
14
|
+
'pii: pi not found.\n' +
|
|
15
|
+
'Install it with: npm install -g @mariozechner/pi-coding-agent\n'
|
|
16
|
+
);
|
|
60
17
|
process.exit(1);
|
|
61
18
|
}
|
|
62
19
|
|
|
63
20
|
const result = spawnSync(
|
|
64
|
-
|
|
21
|
+
process.execPath,
|
|
65
22
|
['--require', preload, cli, ...process.argv.slice(2)],
|
|
66
23
|
{ stdio: 'inherit' }
|
|
67
24
|
);
|