berget 2.1.0 → 2.1.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.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -357,9 +357,8 @@ function loadLatestAgentConfig() {
357
357
  */
358
358
  function checkOpencodeInstalled() {
359
359
  return new Promise((resolve) => {
360
- const child = (0, child_process_1.spawn)('opencode', ['--version'], {
360
+ const child = (0, child_process_1.spawn)('which', ['opencode'], {
361
361
  stdio: 'pipe',
362
- shell: true,
363
362
  });
364
363
  child.on('close', (code) => {
365
364
  resolve(code === 0);
@@ -475,12 +474,9 @@ function registerCodeCommands(program) {
475
474
  }
476
475
  else {
477
476
  // Only require authentication if we don't have an API key
478
- try {
479
- const authService = auth_service_1.AuthService.getInstance();
480
- // This will throw if not authenticated
481
- yield authService.whoami();
482
- }
483
- catch (error) {
477
+ const authService = auth_service_1.AuthService.getInstance();
478
+ const profile = yield authService.whoami();
479
+ if (!profile) {
484
480
  console.log(chalk_1.default.red('āŒ Not authenticated with Berget AI.'));
485
481
  console.log(chalk_1.default.blue('To get started, you have two options:'));
486
482
  console.log('');
@@ -504,62 +500,35 @@ function registerCodeCommands(program) {
504
500
  let keyName;
505
501
  try {
506
502
  const apiKeyService = api_key_service_1.ApiKeyService.getInstance();
507
- // Check for environment variable first (regardless of automation mode)
508
503
  if (process.env.BERGET_API_KEY) {
509
- console.log(chalk_1.default.blue('šŸ”‘ Using BERGET_API_KEY from environment'));
510
- apiKey = process.env.BERGET_API_KEY;
511
- keyName = `env-key-${projectName}`;
512
- }
513
- else {
514
- // List existing API keys
515
- if (!options.yes) {
516
- console.log(chalk_1.default.blue('\nšŸ“‹ Checking existing API keys...'));
504
+ if (options.yes) {
505
+ console.log(chalk_1.default.blue('šŸ”‘ Using BERGET_API_KEY from environment'));
506
+ apiKey = process.env.BERGET_API_KEY;
507
+ keyName = `env-key-${projectName}`;
517
508
  }
518
- const existingKeys = yield apiKeyService.list();
519
- if (existingKeys.length > 0 && !options.yes) {
520
- console.log(chalk_1.default.blue('Found existing API keys:'));
509
+ else {
510
+ console.log(chalk_1.default.blue('\nšŸ“‹ API key setup:'));
521
511
  console.log(chalk_1.default.dim('─'.repeat(60)));
522
- existingKeys.forEach((key, index) => {
523
- console.log(`${chalk_1.default.cyan((index + 1).toString())}. ${chalk_1.default.bold(key.name)} (${key.prefix}...)`);
524
- console.log(chalk_1.default.dim(` Created: ${new Date(key.created).toLocaleDateString('sv-SE')}`));
525
- console.log(chalk_1.default.dim(` Last used: ${key.lastUsed
526
- ? new Date(key.lastUsed).toLocaleDateString('sv-SE')
527
- : 'Never'}`));
528
- if (index < existingKeys.length - 1)
529
- console.log();
530
- });
512
+ console.log(`${chalk_1.default.cyan('1')} ${chalk_1.default.bold('Use existing API key')}`);
513
+ console.log(chalk_1.default.dim(' Uses BERGET_API_KEY from environment'));
514
+ console.log(`${chalk_1.default.cyan('2')} ${chalk_1.default.bold('Create a new API key')}`);
531
515
  console.log(chalk_1.default.dim('─'.repeat(60)));
532
- console.log(chalk_1.default.cyan(`${existingKeys.length + 1}. Create a new API key`));
533
- // Get user choice
534
516
  const choice = yield new Promise((resolve) => {
535
517
  const rl = readline_1.default.createInterface({
536
518
  input: process.stdin,
537
519
  output: process.stdout,
538
520
  });
539
- rl.question(chalk_1.default.blue('\nSelect an option (1-' + (existingKeys.length + 1) + '): '), (answer) => {
521
+ rl.question(chalk_1.default.blue('\nSelect an option (1-2, default: 1): '), (answer) => {
540
522
  rl.close();
541
- resolve(answer.trim());
523
+ resolve(answer.trim() || '1');
542
524
  });
543
525
  });
544
- const choiceIndex = parseInt(choice) - 1;
545
- if (choiceIndex >= 0 && choiceIndex < existingKeys.length) {
546
- // Use existing key
547
- const selectedKey = existingKeys[choiceIndex];
548
- keyName = selectedKey.name;
549
- // We need to rotate the key to get the actual key value
550
- console.log(chalk_1.default.yellow(`\nšŸ”„ Rotating API key "${selectedKey.name}" to get the key value...`));
551
- if (yield confirm(chalk_1.default.yellow('This will invalidate the current key. Continue? (Y/n): '), options.yes)) {
552
- const rotatedKey = yield apiKeyService.rotate(selectedKey.id.toString());
553
- apiKey = rotatedKey.key;
554
- console.log(chalk_1.default.green(`āœ“ API key rotated successfully`));
555
- }
556
- else {
557
- console.log(chalk_1.default.yellow('Cancelled. Please select a different option or create a new key.'));
558
- return;
559
- }
526
+ if (choice === '1') {
527
+ console.log(chalk_1.default.blue('šŸ”‘ Using BERGET_API_KEY from environment'));
528
+ apiKey = process.env.BERGET_API_KEY;
529
+ keyName = `env-key-${projectName}`;
560
530
  }
561
- else if (choiceIndex === existingKeys.length) {
562
- // Create new key
531
+ else if (choice === '2') {
563
532
  console.log(chalk_1.default.blue('\nšŸ”‘ Creating new API key...'));
564
533
  const defaultKeyName = `opencode-${projectName}-${Date.now()}`;
565
534
  const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
@@ -574,20 +543,21 @@ function registerCodeCommands(program) {
574
543
  return;
575
544
  }
576
545
  }
577
- else {
578
- // No existing keys or automation mode - create new one
579
- if (!options.yes) {
580
- console.log(chalk_1.default.yellow('No existing API keys found.'));
581
- console.log(chalk_1.default.blue('Creating a new API key...'));
582
- }
583
- const defaultKeyName = `opencode-${projectName}-${Date.now()}`;
584
- const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
585
- keyName = customName;
586
- const createOptions = { name: keyName };
587
- const keyData = yield apiKeyService.create(createOptions);
588
- apiKey = keyData.key;
589
- console.log(chalk_1.default.green(`āœ“ Created new API key: ${keyName}`));
546
+ }
547
+ else {
548
+ if (!options.yes) {
549
+ console.log(chalk_1.default.yellow('No BERGET_API_KEY environment variable found.'));
550
+ console.log(chalk_1.default.blue('Creating a new API key...'));
551
+ console.log(chalk_1.default.dim('\nšŸ’” Tip: Set BERGET_API_KEY environment variable to reuse an existing key:'));
552
+ console.log(chalk_1.default.dim(' export BERGET_API_KEY=your_api_key_here'));
590
553
  }
554
+ const defaultKeyName = `opencode-${projectName}-${Date.now()}`;
555
+ const customName = yield getInput(chalk_1.default.blue(`Enter key name (default: ${defaultKeyName}): `), defaultKeyName, options.yes);
556
+ keyName = customName;
557
+ const createOptions = { name: keyName };
558
+ const keyData = yield apiKeyService.create(createOptions);
559
+ apiKey = keyData.key;
560
+ console.log(chalk_1.default.green(`āœ“ Created new API key: ${keyName}`));
591
561
  }
592
562
  }
593
563
  catch (error) {
@@ -1050,7 +1020,6 @@ All agents follow these principles:
1050
1020
  const opencode = (0, child_process_1.spawn)('opencode', opencodeArgs, {
1051
1021
  stdio: 'inherit',
1052
1022
  env: env,
1053
- shell: true,
1054
1023
  });
1055
1024
  opencode.on('close', (code) => {
1056
1025
  if (code !== 0) {
@@ -1090,7 +1059,6 @@ All agents follow these principles:
1090
1059
  // Spawn opencode serve process
1091
1060
  const opencode = (0, child_process_1.spawn)('opencode', serveArgs, {
1092
1061
  stdio: 'inherit',
1093
- shell: true,
1094
1062
  });
1095
1063
  opencode.on('close', (code) => {
1096
1064
  if (code !== 0) {
@@ -60,12 +60,11 @@ class AuthService {
60
60
  try {
61
61
  const { data: profile, error } = yield this.client.GET('/v1/users/me');
62
62
  if (error) {
63
- throw new Error(error ? JSON.stringify(error) : 'Failed to get user profile');
63
+ return null;
64
64
  }
65
65
  return profile;
66
66
  }
67
67
  catch (error) {
68
- (0, error_handler_1.handleError)('Failed to get user profile', error);
69
68
  return null;
70
69
  }
71
70
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -376,9 +376,8 @@ async function loadLatestAgentConfig(): Promise<any> {
376
376
  */
377
377
  function checkOpencodeInstalled(): Promise<boolean> {
378
378
  return new Promise((resolve) => {
379
- const child = spawn('opencode', ['--version'], {
379
+ const child = spawn('which', ['opencode'], {
380
380
  stdio: 'pipe',
381
- shell: true,
382
381
  })
383
382
 
384
383
  child.on('close', (code) => {
@@ -530,11 +529,10 @@ export function registerCodeCommands(program: Command): void {
530
529
  )
531
530
  } else {
532
531
  // Only require authentication if we don't have an API key
533
- try {
534
- const authService = AuthService.getInstance()
535
- // This will throw if not authenticated
536
- await authService.whoami()
537
- } catch (error) {
532
+ const authService = AuthService.getInstance()
533
+ const profile = await authService.whoami()
534
+
535
+ if (!profile) {
538
536
  console.log(chalk.red('āŒ Not authenticated with Berget AI.'))
539
537
  console.log(chalk.blue('To get started, you have two options:'))
540
538
  console.log('')
@@ -578,104 +576,39 @@ export function registerCodeCommands(program: Command): void {
578
576
  try {
579
577
  const apiKeyService = ApiKeyService.getInstance()
580
578
 
581
- // Check for environment variable first (regardless of automation mode)
582
579
  if (process.env.BERGET_API_KEY) {
583
- console.log(chalk.blue('šŸ”‘ Using BERGET_API_KEY from environment'))
584
- apiKey = process.env.BERGET_API_KEY
585
- keyName = `env-key-${projectName}`
586
- } else {
587
- // List existing API keys
588
- if (!options.yes) {
589
- console.log(chalk.blue('\nšŸ“‹ Checking existing API keys...'))
590
- }
591
- const existingKeys = await apiKeyService.list()
592
-
593
- if (existingKeys.length > 0 && !options.yes) {
594
- console.log(chalk.blue('Found existing API keys:'))
595
- console.log(chalk.dim('─'.repeat(60)))
596
- existingKeys.forEach((key, index) => {
597
- console.log(
598
- `${chalk.cyan((index + 1).toString())}. ${chalk.bold(
599
- key.name
600
- )} (${key.prefix}...)`
601
- )
602
- console.log(
603
- chalk.dim(
604
- ` Created: ${new Date(key.created).toLocaleDateString(
605
- 'sv-SE'
606
- )}`
607
- )
608
- )
609
- console.log(
610
- chalk.dim(
611
- ` Last used: ${
612
- key.lastUsed
613
- ? new Date(key.lastUsed).toLocaleDateString('sv-SE')
614
- : 'Never'
615
- }`
616
- )
617
- )
618
- if (index < existingKeys.length - 1) console.log()
619
- })
580
+ if (options.yes) {
581
+ console.log(chalk.blue('šŸ”‘ Using BERGET_API_KEY from environment'))
582
+ apiKey = process.env.BERGET_API_KEY
583
+ keyName = `env-key-${projectName}`
584
+ } else {
585
+ console.log(chalk.blue('\nšŸ“‹ API key setup:'))
620
586
  console.log(chalk.dim('─'.repeat(60)))
621
587
  console.log(
622
- chalk.cyan(`${existingKeys.length + 1}. Create a new API key`)
588
+ `${chalk.cyan('1')} ${chalk.bold('Use existing API key')}`
589
+ )
590
+ console.log(chalk.dim(' Uses BERGET_API_KEY from environment'))
591
+ console.log(
592
+ `${chalk.cyan('2')} ${chalk.bold('Create a new API key')}`
623
593
  )
594
+ console.log(chalk.dim('─'.repeat(60)))
624
595
 
625
- // Get user choice
626
596
  const choice = await new Promise<string>((resolve) => {
627
597
  const rl = readline.createInterface({
628
598
  input: process.stdin,
629
599
  output: process.stdout,
630
600
  })
631
- rl.question(
632
- chalk.blue(
633
- '\nSelect an option (1-' + (existingKeys.length + 1) + '): '
634
- ),
635
- (answer) => {
636
- rl.close()
637
- resolve(answer.trim())
638
- }
639
- )
601
+ rl.question(chalk.blue('\nSelect an option (1-2, default: 1): '), (answer) => {
602
+ rl.close()
603
+ resolve(answer.trim() || '1')
604
+ })
640
605
  })
641
606
 
642
- const choiceIndex = parseInt(choice) - 1
643
-
644
- if (choiceIndex >= 0 && choiceIndex < existingKeys.length) {
645
- // Use existing key
646
- const selectedKey = existingKeys[choiceIndex]
647
- keyName = selectedKey.name
648
-
649
- // We need to rotate the key to get the actual key value
650
- console.log(
651
- chalk.yellow(
652
- `\nšŸ”„ Rotating API key "${selectedKey.name}" to get the key value...`
653
- )
654
- )
655
-
656
- if (
657
- await confirm(
658
- chalk.yellow(
659
- 'This will invalidate the current key. Continue? (Y/n): '
660
- ),
661
- options.yes
662
- )
663
- ) {
664
- const rotatedKey = await apiKeyService.rotate(
665
- selectedKey.id.toString()
666
- )
667
- apiKey = rotatedKey.key
668
- console.log(chalk.green(`āœ“ API key rotated successfully`))
669
- } else {
670
- console.log(
671
- chalk.yellow(
672
- 'Cancelled. Please select a different option or create a new key.'
673
- )
674
- )
675
- return
676
- }
677
- } else if (choiceIndex === existingKeys.length) {
678
- // Create new key
607
+ if (choice === '1') {
608
+ console.log(chalk.blue('šŸ”‘ Using BERGET_API_KEY from environment'))
609
+ apiKey = process.env.BERGET_API_KEY
610
+ keyName = `env-key-${projectName}`
611
+ } else if (choice === '2') {
679
612
  console.log(chalk.blue('\nšŸ”‘ Creating new API key...'))
680
613
 
681
614
  const defaultKeyName = `opencode-${projectName}-${Date.now()}`
@@ -694,26 +627,27 @@ export function registerCodeCommands(program: Command): void {
694
627
  console.log(chalk.red('Invalid selection.'))
695
628
  return
696
629
  }
697
- } else {
698
- // No existing keys or automation mode - create new one
699
- if (!options.yes) {
700
- console.log(chalk.yellow('No existing API keys found.'))
701
- console.log(chalk.blue('Creating a new API key...'))
702
- }
630
+ }
631
+ } else {
632
+ if (!options.yes) {
633
+ console.log(chalk.yellow('No BERGET_API_KEY environment variable found.'))
634
+ console.log(chalk.blue('Creating a new API key...'))
635
+ console.log(chalk.dim('\nšŸ’” Tip: Set BERGET_API_KEY environment variable to reuse an existing key:'))
636
+ console.log(chalk.dim(' export BERGET_API_KEY=your_api_key_here'))
637
+ }
703
638
 
704
- const defaultKeyName = `opencode-${projectName}-${Date.now()}`
705
- const customName = await getInput(
706
- chalk.blue(`Enter key name (default: ${defaultKeyName}): `),
707
- defaultKeyName,
708
- options.yes
709
- )
639
+ const defaultKeyName = `opencode-${projectName}-${Date.now()}`
640
+ const customName = await getInput(
641
+ chalk.blue(`Enter key name (default: ${defaultKeyName}): `),
642
+ defaultKeyName,
643
+ options.yes
644
+ )
710
645
 
711
- keyName = customName
712
- const createOptions: CreateApiKeyOptions = { name: keyName }
713
- const keyData = await apiKeyService.create(createOptions)
714
- apiKey = keyData.key
715
- console.log(chalk.green(`āœ“ Created new API key: ${keyName}`))
716
- }
646
+ keyName = customName
647
+ const createOptions: CreateApiKeyOptions = { name: keyName }
648
+ const keyData = await apiKeyService.create(createOptions)
649
+ apiKey = keyData.key
650
+ console.log(chalk.green(`āœ“ Created new API key: ${keyName}`))
717
651
  }
718
652
  } catch (error) {
719
653
  if (process.env.BERGET_API_KEY) {
@@ -1269,7 +1203,6 @@ All agents follow these principles:
1269
1203
  const opencode = spawn('opencode', opencodeArgs, {
1270
1204
  stdio: 'inherit',
1271
1205
  env: env,
1272
- shell: true,
1273
1206
  })
1274
1207
 
1275
1208
  opencode.on('close', (code) => {
@@ -1322,7 +1255,6 @@ All agents follow these principles:
1322
1255
  // Spawn opencode serve process
1323
1256
  const opencode = spawn('opencode', serveArgs, {
1324
1257
  stdio: 'inherit',
1325
- shell: true,
1326
1258
  })
1327
1259
 
1328
1260
  opencode.on('close', (code) => {
@@ -36,13 +36,10 @@ export class AuthService {
36
36
  try {
37
37
  const { data: profile, error } = await this.client.GET('/v1/users/me')
38
38
  if (error) {
39
- throw new Error(
40
- error ? JSON.stringify(error) : 'Failed to get user profile',
41
- )
39
+ return null
42
40
  }
43
41
  return profile
44
42
  } catch (error) {
45
- handleError('Failed to get user profile', error)
46
43
  return null
47
44
  }
48
45
  }