@chatpanel/bridge 0.11.9 → 0.11.10
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/package.json +1 -1
- package/src/env.js +68 -0
- package/src/server.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (CLI), Codex (CLI), and Antigravity CLI (formerly Gemini CLI, which remains available for business/enterprise) — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
|
|
6
6
|
"keywords": [
|
package/src/env.js
CHANGED
|
@@ -273,6 +273,52 @@ function stripBom(s) {
|
|
|
273
273
|
|
|
274
274
|
// Version managers install CLIs under versioned bin dirs that a lazy-loaded
|
|
275
275
|
// shell (nvm/fnm) doesn't export into a non-interactive service PATH. Add them.
|
|
276
|
+
/**
|
|
277
|
+
* The node version nvm would actually give you, and only that one.
|
|
278
|
+
*
|
|
279
|
+
* WHY THIS EXISTS. PATH discovery asks a LOGIN shell, which never reads .zshrc — and .zshrc
|
|
280
|
+
* is where nvm lives. So the learned PATH has no nvm in it, and the hardcoded fallbacks
|
|
281
|
+
* below take over. Those start with /opt/homebrew/bin, so a Homebrew copy of an agent CLI
|
|
282
|
+
* beat the one the user's terminal uses.
|
|
283
|
+
*
|
|
284
|
+
* One machine had Claude Code 2.1.268 under nvm and 2.1.175 under Homebrew. Every turn
|
|
285
|
+
* through the bridge answered "Claude Code 2.1.175 does not support this model" to a user
|
|
286
|
+
* who had just updated Claude Code — twice.
|
|
287
|
+
*
|
|
288
|
+
* `versionManagerBins` cannot fix that on its own: it lists EVERY installed version, in
|
|
289
|
+
* directory order, so preferring it wholesale would pick an arbitrary old node. This picks
|
|
290
|
+
* the one nvm itself would: the `default` alias if it names a version, else the highest
|
|
291
|
+
* installed. Pure filesystem reads — no shell, so nothing can block startup.
|
|
292
|
+
*/
|
|
293
|
+
export function nvmCurrentBin(home = os.homedir(), env = process.env) {
|
|
294
|
+
const root = path.join(env.NVM_DIR || path.join(home, '.nvm'), 'versions', 'node');
|
|
295
|
+
let versions;
|
|
296
|
+
try {
|
|
297
|
+
versions = readdirSync(root).filter((v) => /^v\d+\./.test(v));
|
|
298
|
+
} catch {
|
|
299
|
+
return null; // no nvm on this machine
|
|
300
|
+
}
|
|
301
|
+
if (!versions.length) return null;
|
|
302
|
+
|
|
303
|
+
const byVersion = (a, b) => {
|
|
304
|
+
const pa = a.slice(1).split('.').map(Number);
|
|
305
|
+
const pb = b.slice(1).split('.').map(Number);
|
|
306
|
+
for (let i = 0; i < 3; i += 1) if ((pa[i] || 0) !== (pb[i] || 0)) return (pb[i] || 0) - (pa[i] || 0);
|
|
307
|
+
return 0;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// The `default` alias is what a new shell resolves to. It may name a version directly
|
|
311
|
+
// ("24.14.0"), or point at another alias ("lts/*"), which we do not chase — the highest
|
|
312
|
+
// installed is a better guess than a wrong one.
|
|
313
|
+
try {
|
|
314
|
+
const alias = readFileSync(path.join(env.NVM_DIR || path.join(home, '.nvm'), 'alias', 'default'), 'utf8').trim();
|
|
315
|
+
const want = alias.startsWith('v') ? alias : `v${alias}`;
|
|
316
|
+
if (versions.includes(want)) return path.join(root, want, 'bin');
|
|
317
|
+
} catch { /* no alias file — fall through */ }
|
|
318
|
+
|
|
319
|
+
return path.join(root, versions.sort(byVersion)[0], 'bin');
|
|
320
|
+
}
|
|
321
|
+
|
|
276
322
|
function versionManagerBins(home) {
|
|
277
323
|
const bins = [];
|
|
278
324
|
const tryDir = (dir, sub) => {
|
|
@@ -501,7 +547,12 @@ export function enrichPath() {
|
|
|
501
547
|
return;
|
|
502
548
|
}
|
|
503
549
|
|
|
550
|
+
const nvmBin = nvmCurrentBin(home);
|
|
504
551
|
const common = [
|
|
552
|
+
// BEFORE the package-manager dirs. A version manager PREPENDS itself to PATH in the
|
|
553
|
+
// user's shell, so its copy is the one their terminal runs — and the whole purpose of
|
|
554
|
+
// this list is to reproduce what the terminal would do.
|
|
555
|
+
...(nvmBin ? [nvmBin] : []),
|
|
505
556
|
'/opt/homebrew/bin',
|
|
506
557
|
'/opt/homebrew/sbin',
|
|
507
558
|
'/usr/local/bin',
|
|
@@ -523,6 +574,12 @@ export function enrichPath() {
|
|
|
523
574
|
let shellPath = '';
|
|
524
575
|
try {
|
|
525
576
|
const shell = process.env.SHELL || '/bin/zsh';
|
|
577
|
+
// `-lc`, NOT `-ilc`, and deliberately: an INTERACTIVE shell can block on a prompt and
|
|
578
|
+
// hang the daemon's own startup. tests/env-startup.test.mjs holds that line.
|
|
579
|
+
//
|
|
580
|
+
// The cost is that a login shell does not read .zshrc/.bashrc, which is where nvm and
|
|
581
|
+
// friends install themselves — so this answer arrives WITHOUT the version manager, and
|
|
582
|
+
// the merge below has to supply it. See nvmCurrentBin().
|
|
526
583
|
const r = spawnSync(shell, ['-lc', 'command -p echo "$PATH"'], {
|
|
527
584
|
encoding: 'utf8',
|
|
528
585
|
timeout: 4000,
|
|
@@ -534,6 +591,17 @@ export function enrichPath() {
|
|
|
534
591
|
|
|
535
592
|
const seen = new Set();
|
|
536
593
|
const merged = [
|
|
594
|
+
// THE VERSION MANAGER GOES FIRST, ahead even of the login shell's own answer.
|
|
595
|
+
//
|
|
596
|
+
// That looks aggressive until you see why the shell's answer is incomplete: `-lc` never
|
|
597
|
+
// reads .zshrc, which is where nvm installs itself, so the PATH we learn is the user's
|
|
598
|
+
// MINUS their version manager — while still containing /opt/homebrew/bin from .zprofile.
|
|
599
|
+
// Merging it first therefore hands Homebrew the win over a tool the user manages with
|
|
600
|
+
// nvm, which is the opposite of what their terminal does: nvm PREPENDS.
|
|
601
|
+
//
|
|
602
|
+
// So we put it back where nvm would have. `nvmCurrentBin` resolves the one version nvm
|
|
603
|
+
// itself would pick, from the filesystem, with no shell to block on.
|
|
604
|
+
...(nvmBin ? [nvmBin] : []),
|
|
537
605
|
...(shellPath ? shellPath.split(':') : []),
|
|
538
606
|
...(process.env.PATH ? process.env.PATH.split(path.delimiter) : []),
|
|
539
607
|
...common,
|
package/src/server.js
CHANGED
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
// Hardcoded (not read from package.json) so it survives Bun's single-file
|
|
68
68
|
// --compile, where package.json isn't on a readable FS. CI fails the publish if
|
|
69
69
|
// this drifts from package.json, so the two can't silently diverge.
|
|
70
|
-
const VERSION = '0.11.
|
|
70
|
+
const VERSION = '0.11.10';
|
|
71
71
|
const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
|
|
72
72
|
const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
|
|
73
73
|
|