pi-powerline 0.6.0 → 0.6.1

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.
Files changed (2) hide show
  1. package/header.ts +44 -16
  2. package/package.json +1 -1
package/header.ts CHANGED
@@ -52,6 +52,10 @@ function gradientLine(line: string): string {
52
52
 
53
53
  const ANSI_PATTERN = /\x1b\[[0-9;]*m/g;
54
54
 
55
+ function getHomeDir(): string {
56
+ return process.env.HOME ?? homedir();
57
+ }
58
+
55
59
  function visibleLength(line: string): number {
56
60
  return line.replace(ANSI_PATTERN, '').length;
57
61
  }
@@ -251,7 +255,7 @@ function formatRelativePath(cwd: string, filePath: string): string {
251
255
  }
252
256
 
253
257
  function formatDisplayPath(cwd: string, filePath: string): string {
254
- const home = homedir();
258
+ const home = getHomeDir();
255
259
  const rel = relative(cwd, filePath);
256
260
  if (!rel || !rel.startsWith('..')) return rel || '.';
257
261
  if (filePath === home) return '~';
@@ -334,7 +338,7 @@ function getNpmRoot(): string | undefined {
334
338
  if (_npmRootResolved) return _npmRoot;
335
339
  _npmRootResolved = true;
336
340
 
337
- const home = homedir();
341
+ const home = getHomeDir();
338
342
 
339
343
  // NVM: ~/.nvm/versions/node/<version>/lib/node_modules
340
344
  if (process.env.NVM_DIR) {
@@ -394,7 +398,12 @@ interface PackageSource {
394
398
  scope: 'project' | 'user';
395
399
  }
396
400
 
397
- function readPackageSources(cwd: string, home = homedir()): PackageSource[] {
401
+ interface ExtensionSource {
402
+ source: string;
403
+ baseDir: string;
404
+ }
405
+
406
+ function readPackageSources(cwd: string, home = getHomeDir()): PackageSource[] {
398
407
  const globalPkgs = readSettingsArray(join(home, '.pi', 'agent', 'settings.json'), 'packages');
399
408
  const projectPkgs = readSettingsArray(join(cwd, '.pi', 'settings.json'), 'packages');
400
409
 
@@ -416,7 +425,7 @@ function readPackageSources(cwd: string, home = homedir()): PackageSource[] {
416
425
 
417
426
  // ── resolve a package source to its directory path ──
418
427
 
419
- function resolvePackageDir(source: string, cwd: string, home = homedir()): string | undefined {
428
+ function resolvePackageDir(source: string, cwd: string, home = getHomeDir()): string | undefined {
420
429
  if (source.startsWith('npm:')) {
421
430
  const name = source.slice(4);
422
431
  const npmRoot = getNpmRoot();
@@ -441,7 +450,7 @@ function resolvePackageDir(source: string, cwd: string, home = homedir()): strin
441
450
 
442
451
  // ── getPackages: name+version from each configured package ──
443
452
 
444
- function getPackages(cwd: string, home = homedir()): string[] {
453
+ function getPackages(cwd: string, home = getHomeDir()): string[] {
445
454
  const sources = readPackageSources(cwd, home);
446
455
  const results: string[] = [];
447
456
 
@@ -463,16 +472,37 @@ function getPackages(cwd: string, home = homedir()): string[] {
463
472
 
464
473
  // ── getExtensionItems: scan .ts files from settings.json extensions dirs ──
465
474
 
466
- function getExtensionItems(cwd: string, home = homedir()): string[] {
475
+ function readExtensionSources(cwd: string, home = getHomeDir()): ExtensionSource[] {
476
+ const projectBaseDir = join(cwd, '.pi');
477
+ const globalBaseDir = join(home, '.pi', 'agent');
478
+ const projectExts = readSettingsArray(join(projectBaseDir, 'settings.json'), 'extensions');
479
+ const globalExts = readSettingsArray(join(globalBaseDir, 'settings.json'), 'extensions');
480
+
481
+ return [
482
+ ...projectExts.map((source) => ({ source, baseDir: projectBaseDir })),
483
+ ...globalExts.map((source) => ({ source, baseDir: globalBaseDir })),
484
+ ];
485
+ }
486
+
487
+ function resolveSettingsSource(source: string, baseDir: string, home = getHomeDir()): string {
488
+ return source.startsWith('~')
489
+ ? join(home, source.slice(source.startsWith('~/') ? 2 : 1))
490
+ : resolve(baseDir, source);
491
+ }
492
+
493
+ function getExtensionItems(cwd: string, home = getHomeDir()): string[] {
467
494
  const results: string[] = [];
495
+ const seenFiles = new Set<string>();
468
496
 
469
- const globalExts = readSettingsArray(join(home, '.pi', 'agent', 'settings.json'), 'extensions');
470
- const projectExts = readSettingsArray(join(cwd, '.pi', 'settings.json'), 'extensions');
497
+ function addFile(filePath: string) {
498
+ const key = resolve(filePath);
499
+ if (seenFiles.has(key)) return;
500
+ seenFiles.add(key);
501
+ results.push(formatDisplayPath(cwd, filePath));
502
+ }
471
503
 
472
- for (const ext of [...projectExts, ...globalExts]) {
473
- const resolved = ext.startsWith('~')
474
- ? join(home, ext.slice(ext.startsWith('~/') ? 2 : 1))
475
- : resolve(cwd, ext);
504
+ for (const { source, baseDir } of readExtensionSources(cwd, home)) {
505
+ const resolved = resolveSettingsSource(source, baseDir, home);
476
506
 
477
507
  if (!existsSync(resolved)) continue;
478
508
 
@@ -480,12 +510,10 @@ function getExtensionItems(cwd: string, home = homedir()): string[] {
480
510
  const s = statSync(resolved);
481
511
  if (s.isDirectory()) {
482
512
  for (const f of readdirSync(resolved).sort()) {
483
- if (f.endsWith('.ts')) {
484
- results.push(formatDisplayPath(cwd, join(resolved, f)));
485
- }
513
+ if (f.endsWith('.ts')) addFile(join(resolved, f));
486
514
  }
487
515
  } else {
488
- results.push(formatDisplayPath(cwd, resolved));
516
+ addFile(resolved);
489
517
  }
490
518
  } catch {
491
519
  // ignore unreadable paths
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-powerline",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Powerline-style UI extensions for pi coding agent (custom editor, breadcrumb, footer, header)",
5
5
  "homepage": "https://github.com/jwu/pi-powerline#readme",
6
6
  "repository": {