@polderlabs/bizar 5.6.0-beta.12 → 5.6.0-beta.13

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/cli/provision.mjs CHANGED
@@ -40,7 +40,16 @@ import chalk from 'chalk';
40
40
  import { execSync, spawn, spawnSync } from 'node:child_process';
41
41
  import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync, mkdirSync, statSync, copyFileSync } from 'node:fs';
42
42
  import { homedir } from 'node:os';
43
- import { join, dirname, sep } from 'node:path';
43
+ import { join as _origJoin, dirname, sep } from 'node:path';
44
+ // Debug: throw with stack trace if a Dirent sneaks into path.join
45
+ function join(...args) {
46
+ for (const a of args) {
47
+ if (a && typeof a === 'object' && a.constructor && a.constructor.name === 'Dirent') {
48
+ console.error('Dirent passed to join:', a.name, 'stack:', new Error().stack.split('\n').slice(0, 8).join('\n '));
49
+ }
50
+ }
51
+ return _origJoin(...args);
52
+ }
44
53
  import { fileURLToPath } from 'node:url';
45
54
  import { bizarConfigDir } from './utils.mjs';
46
55
 
@@ -259,11 +268,40 @@ export function writeInstallMarker({ version, repoPath, serviceUnit }) {
259
268
  */
260
269
  export function detectState({ cwd = process.cwd() } = {}) {
261
270
  // ── npm-global package location ─────────────────────────────────────
271
+ // Try multiple strategies because `npm root -g` doesn't always
272
+ // respect NPM_CONFIG_PREFIX (notably when npm is installed by the
273
+ // system package manager on Debian/Ubuntu).
262
274
  let globalRoot = null;
275
+ const npmRootCandidates = [];
276
+
277
+ // 1. Honour the user's explicit env override first.
278
+ if (process.env.NPM_CONFIG_PREFIX) {
279
+ npmRootCandidates.push(join(process.env.NPM_CONFIG_PREFIX, 'lib', 'node_modules'));
280
+ }
281
+ // 2. Honour NPM_CONFIG_GLOBAL_PREFIX (set by `npm -g`).
282
+ if (process.env.NPM_CONFIG_GLOBAL_PREFIX) {
283
+ npmRootCandidates.push(join(process.env.NPM_CONFIG_GLOBAL_PREFIX, 'lib', 'node_modules'));
284
+ }
285
+ // 3. The classic `npm root -g` query (works on most distros).
263
286
  try {
264
- globalRoot = execSync('npm root -g', { stdio: ['ignore', 'pipe', 'ignore'] })
287
+ const r = execSync('npm root -g', { stdio: ['ignore', 'pipe', 'ignore'] })
265
288
  .toString().trim();
289
+ if (r) npmRootCandidates.push(r);
266
290
  } catch { /* ignore */ }
291
+ // 4. Common distro defaults.
292
+ npmRootCandidates.push('/usr/local/lib/node_modules');
293
+ npmRootCandidates.push('/usr/lib/node_modules');
294
+
295
+ // Pick the first candidate that actually has @polderlabs/bizar.
296
+ for (const candidate of npmRootCandidates) {
297
+ if (existsSync(join(candidate, '@polderlabs', 'bizar'))) {
298
+ globalRoot = candidate;
299
+ break;
300
+ }
301
+ }
302
+ // Fall back to the first candidate (even if it doesn't have the
303
+ // package) so downstream code can produce a clean error message.
304
+ if (!globalRoot) globalRoot = npmRootCandidates[0] ?? null;
267
305
 
268
306
  const pkgRoot = globalRoot ? join(globalRoot, '@polderlabs', 'bizar') : null;
269
307
  const pkgVersion = globalRoot ? currentVersion(PKG_MAIN) : null;
@@ -515,7 +553,11 @@ export async function ensureNpmPackage(pkg, { mode, dryRun, force }) {
515
553
  // processes are reading files inside the npm-global install dir. We
516
554
  // can't replace those files atomically while they're open. The caller
517
555
  // is expected to have already killed them via ensureInstancesKilled().
518
- const r = spawnSync('npm', ['install', '-g', `${pkg}@latest`], { stdio: 'inherit', timeout: 600000 });
556
+ const npmArgs = ['install', '-g', `${pkg}@latest`];
557
+ if (process.env.NPM_CONFIG_PREFIX) {
558
+ npmArgs.push('--prefix', process.env.NPM_CONFIG_PREFIX);
559
+ }
560
+ const r = spawnSync('npm', npmArgs, { stdio: 'inherit', timeout: 600000 });
519
561
  if (r.status === null && r.error?.code === 'ETIMEDOUT') {
520
562
  return { ok: false, message: `${pkg} install timed out after 10 minutes`, installed: current };
521
563
  }
@@ -543,7 +585,11 @@ export async function updateClineCli({ dryRun, force }) {
543
585
  return { ok: true, message: 'cline updated via `cline upgrade`' };
544
586
  }
545
587
  console.log(chalk.dim(' cline upgrade not available; falling back to npm'));
546
- const r2 = spawnSync('npm', ['install', '-g', 'cline@latest'], { stdio: 'inherit', timeout: 600000 });
588
+ const npm2Args = ['install', '-g', 'cline@latest'];
589
+ if (process.env.NPM_CONFIG_PREFIX) {
590
+ npm2Args.push('--prefix', process.env.NPM_CONFIG_PREFIX);
591
+ }
592
+ const r2 = spawnSync('npm', npm2Args, { stdio: 'inherit', timeout: 600000 });
547
593
  if (r2.status === null && r2.error?.code === 'ETIMEDOUT') {
548
594
  return { ok: false, message: 'cline install timed out after 10 minutes' };
549
595
  }
@@ -683,9 +729,9 @@ function pluginContentMatches(src, dest) {
683
729
  if (!sEntries) return false;
684
730
  // src should not have files missing from dest
685
731
  for (const e of sEntries) {
686
- if (skipDirs.has(e)) continue;
687
- const sFull = join(s, e);
688
- const dFull = join(d, e);
732
+ if (skipDirs.has(e.name)) continue;
733
+ const sFull = join(s, e.name);
734
+ const dFull = join(d, e.name);
689
735
  try {
690
736
  const sSt = statSync(sFull);
691
737
  if (sSt.isDirectory()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polderlabs/bizar",
3
- "version": "5.6.0-beta.12",
3
+ "version": "5.6.0-beta.13",
4
4
  "description": "Norse-pantheon multi-agent system for cline — 13 agents across 4 cost tiers with cost-aware routing, plans, and a configurable agent harness. v4 ships as a single npm package bundling the dashboard server, cline plugin, and typed SDK.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polderlabs/bizar-sdk",
3
- "version": "0.2.0-beta.12",
3
+ "version": "0.2.0-beta.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",