berget 2.2.6 → 2.2.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.
Files changed (145) hide show
  1. package/.github/workflows/publish.yml +2 -2
  2. package/.github/workflows/test.yml +10 -4
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierignore +15 -0
  5. package/.prettierrc +7 -3
  6. package/CONTRIBUTING.md +38 -0
  7. package/README.md +2 -148
  8. package/dist/index.js +10 -11
  9. package/dist/package.json +30 -2
  10. package/dist/src/agents/app.js +28 -0
  11. package/dist/src/agents/backend.js +25 -0
  12. package/dist/src/agents/devops.js +34 -0
  13. package/dist/src/agents/frontend.js +25 -0
  14. package/dist/src/agents/fullstack.js +25 -0
  15. package/dist/src/agents/index.js +61 -0
  16. package/dist/src/agents/quality.js +70 -0
  17. package/dist/src/agents/security.js +26 -0
  18. package/dist/src/agents/types.js +2 -0
  19. package/dist/src/client.js +97 -117
  20. package/dist/src/commands/api-keys.js +75 -90
  21. package/dist/src/commands/auth.js +7 -16
  22. package/dist/src/commands/autocomplete.js +1 -1
  23. package/dist/src/commands/billing.js +6 -17
  24. package/dist/src/commands/chat.js +68 -101
  25. package/dist/src/commands/clusters.js +9 -18
  26. package/dist/src/commands/code/__tests__/auth-sync.test.js +351 -0
  27. package/dist/src/commands/code/__tests__/fake-api-key-service.js +13 -0
  28. package/dist/src/commands/code/__tests__/fake-auth-service.js +47 -0
  29. package/dist/src/commands/code/__tests__/fake-command-runner.js +21 -34
  30. package/dist/src/commands/code/__tests__/fake-file-store.js +20 -33
  31. package/dist/src/commands/code/__tests__/fake-prompter.js +83 -57
  32. package/dist/src/commands/code/__tests__/setup-flow.test.js +359 -92
  33. package/dist/src/commands/code/adapters/clack-prompter.js +15 -22
  34. package/dist/src/commands/code/adapters/fs-file-store.js +26 -40
  35. package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -37
  36. package/dist/src/commands/code/auth-sync.js +270 -0
  37. package/dist/src/commands/code/errors.js +12 -9
  38. package/dist/src/commands/code/ports/auth-services.js +2 -0
  39. package/dist/src/commands/code/setup.js +387 -281
  40. package/dist/src/commands/code.js +205 -332
  41. package/dist/src/commands/index.js +5 -5
  42. package/dist/src/commands/models.js +6 -17
  43. package/dist/src/commands/users.js +5 -16
  44. package/dist/src/constants/command-structure.js +104 -104
  45. package/dist/src/services/api-key-service.js +132 -157
  46. package/dist/src/services/auth-service.js +89 -342
  47. package/dist/src/services/browser-auth.js +268 -0
  48. package/dist/src/services/chat-service.js +371 -401
  49. package/dist/src/services/cluster-service.js +47 -62
  50. package/dist/src/services/collaborator-service.js +10 -25
  51. package/dist/src/services/flux-service.js +14 -29
  52. package/dist/src/services/helm-service.js +10 -25
  53. package/dist/src/services/kubectl-service.js +16 -33
  54. package/dist/src/utils/config-checker.js +3 -3
  55. package/dist/src/utils/config-loader.js +95 -95
  56. package/dist/src/utils/default-api-key.js +124 -134
  57. package/dist/src/utils/env-manager.js +55 -66
  58. package/dist/src/utils/error-handler.js +20 -21
  59. package/dist/src/utils/logger.js +72 -65
  60. package/dist/src/utils/markdown-renderer.js +27 -27
  61. package/dist/src/utils/opencode-validator.js +63 -68
  62. package/dist/src/utils/token-manager.js +74 -45
  63. package/dist/tests/commands/chat.test.js +16 -25
  64. package/dist/tests/commands/code.test.js +95 -104
  65. package/dist/tests/utils/config-loader.test.js +48 -48
  66. package/dist/tests/utils/env-manager.test.js +43 -52
  67. package/dist/tests/utils/opencode-validator.test.js +22 -21
  68. package/dist/vitest.config.js +1 -1
  69. package/eslint.config.mjs +67 -0
  70. package/index.ts +35 -42
  71. package/package.json +30 -2
  72. package/src/agents/app.ts +27 -0
  73. package/src/agents/backend.ts +24 -0
  74. package/src/agents/devops.ts +33 -0
  75. package/src/agents/frontend.ts +24 -0
  76. package/src/agents/fullstack.ts +24 -0
  77. package/src/agents/index.ts +73 -0
  78. package/src/agents/quality.ts +69 -0
  79. package/src/agents/security.ts +26 -0
  80. package/src/agents/types.ts +17 -0
  81. package/src/client.ts +118 -152
  82. package/src/commands/api-keys.ts +241 -333
  83. package/src/commands/auth.ts +22 -27
  84. package/src/commands/autocomplete.ts +9 -9
  85. package/src/commands/billing.ts +20 -24
  86. package/src/commands/chat.ts +248 -338
  87. package/src/commands/clusters.ts +27 -26
  88. package/src/commands/code/__tests__/auth-sync.test.ts +482 -0
  89. package/src/commands/code/__tests__/fake-api-key-service.ts +13 -0
  90. package/src/commands/code/__tests__/fake-auth-service.ts +50 -0
  91. package/src/commands/code/__tests__/fake-command-runner.ts +45 -42
  92. package/src/commands/code/__tests__/fake-file-store.ts +32 -23
  93. package/src/commands/code/__tests__/fake-prompter.ts +116 -77
  94. package/src/commands/code/__tests__/setup-flow.test.ts +624 -268
  95. package/src/commands/code/adapters/clack-prompter.ts +53 -39
  96. package/src/commands/code/adapters/fs-file-store.ts +32 -27
  97. package/src/commands/code/adapters/spawn-command-runner.ts +38 -29
  98. package/src/commands/code/auth-sync.ts +329 -0
  99. package/src/commands/code/errors.ts +18 -18
  100. package/src/commands/code/ports/auth-services.ts +14 -0
  101. package/src/commands/code/ports/command-runner.ts +8 -4
  102. package/src/commands/code/ports/file-store.ts +5 -4
  103. package/src/commands/code/ports/prompter.ts +24 -18
  104. package/src/commands/code/setup.ts +570 -340
  105. package/src/commands/code.ts +338 -539
  106. package/src/commands/index.ts +20 -19
  107. package/src/commands/models.ts +28 -32
  108. package/src/commands/users.ts +15 -21
  109. package/src/constants/command-structure.ts +134 -157
  110. package/src/services/api-key-service.ts +105 -122
  111. package/src/services/auth-service.ts +99 -345
  112. package/src/services/browser-auth.ts +296 -0
  113. package/src/services/chat-service.ts +265 -299
  114. package/src/services/cluster-service.ts +42 -45
  115. package/src/services/collaborator-service.ts +14 -19
  116. package/src/services/flux-service.ts +23 -25
  117. package/src/services/helm-service.ts +19 -21
  118. package/src/services/kubectl-service.ts +17 -19
  119. package/src/types/api.d.ts +1905 -1907
  120. package/src/types/json.d.ts +2 -2
  121. package/src/utils/config-checker.ts +10 -10
  122. package/src/utils/config-loader.ts +162 -178
  123. package/src/utils/default-api-key.ts +114 -125
  124. package/src/utils/env-manager.ts +53 -57
  125. package/src/utils/error-handler.ts +61 -56
  126. package/src/utils/logger.ts +79 -73
  127. package/src/utils/markdown-renderer.ts +31 -31
  128. package/src/utils/opencode-validator.ts +85 -89
  129. package/src/utils/token-manager.ts +108 -87
  130. package/templates/agents/app.md +1 -0
  131. package/templates/agents/backend.md +1 -0
  132. package/templates/agents/devops.md +2 -0
  133. package/templates/agents/frontend.md +1 -0
  134. package/templates/agents/fullstack.md +1 -0
  135. package/templates/agents/quality.md +45 -40
  136. package/templates/agents/security.md +1 -0
  137. package/tests/commands/chat.test.ts +53 -62
  138. package/tests/commands/code.test.ts +265 -310
  139. package/tests/utils/config-loader.test.ts +189 -188
  140. package/tests/utils/env-manager.test.ts +110 -113
  141. package/tests/utils/opencode-validator.test.ts +52 -56
  142. package/tsconfig.json +4 -3
  143. package/vitest.config.ts +3 -3
  144. package/AGENTS.md +0 -374
  145. package/TODO.md +0 -19
@@ -1,8 +1,9 @@
1
- import { Command } from 'commander'
2
- import chalk from 'chalk'
3
- import { AuthService } from '../services/auth-service'
4
- import { clearAuthToken } from '../client'
5
- import { handleError } from '../utils/error-handler'
1
+ import chalk from 'chalk';
2
+ import { Command } from 'commander';
3
+
4
+ import { clearAuthToken } from '../client';
5
+ import { AuthService } from '../services/auth-service';
6
+ import { handleError } from '../utils/error-handler';
6
7
 
7
8
  /**
8
9
  * Register authentication commands
@@ -10,51 +11,45 @@ import { handleError } from '../utils/error-handler'
10
11
  export function registerAuthCommands(program: Command): void {
11
12
  const auth = program
12
13
  .command(AuthService.COMMAND_GROUP)
13
- .description('Manage authentication and authorization')
14
+ .description('Manage authentication and authorization');
14
15
 
15
16
  auth
16
17
  .command(AuthService.COMMANDS.LOGIN)
17
18
  .description('Log in to Berget')
18
19
  .action(async () => {
19
- const authService = AuthService.getInstance()
20
- await authService.login()
21
- })
20
+ const authService = AuthService.getInstance();
21
+ await authService.login();
22
+ });
22
23
 
23
24
  auth
24
25
  .command(AuthService.COMMANDS.LOGOUT)
25
26
  .description('Log out from Berget')
26
27
  .action(() => {
27
- clearAuthToken()
28
- console.log(chalk.green('You have been logged out from Berget'))
29
- })
28
+ clearAuthToken();
29
+ console.log(chalk.green('You have been logged out from Berget'));
30
+ });
30
31
 
31
32
  auth
32
33
  .command(AuthService.COMMANDS.WHOAMI)
33
34
  .description('Show information about the logged in user')
34
35
  .action(async () => {
35
36
  try {
36
- const authService = AuthService.getInstance()
37
- const profile = await authService.whoami()
37
+ const authService = AuthService.getInstance();
38
+ const profile = await authService.whoami();
38
39
 
39
40
  if (profile) {
40
- console.log(
41
- chalk.bold(`Logged in as: ${profile.name || profile.login}`),
42
- )
43
- console.log(`Email: ${chalk.cyan(profile.email || 'Not available')}`)
44
- console.log(`Role: ${chalk.cyan(profile.role || 'Not available')}`)
41
+ console.log(chalk.bold(`Logged in as: ${profile.name || profile.login}`));
42
+ console.log(`Email: ${chalk.cyan(profile.email || 'Not available')}`);
43
+ console.log(`Role: ${chalk.cyan(profile.role || 'Not available')}`);
45
44
 
46
45
  if (profile.company) {
47
- console.log(`Company: ${chalk.cyan(profile.company.name)}`)
46
+ console.log(`Company: ${chalk.cyan(profile.company.name)}`);
48
47
  }
49
48
  } else {
50
- console.log(
51
- chalk.yellow(
52
- 'You are not logged in. Use `berget login` to log in.',
53
- ),
54
- )
49
+ console.log(chalk.yellow('You are not logged in. Use `berget login` to log in.'));
55
50
  }
56
51
  } catch (error) {
57
- handleError('You are not logged in or an error occurred', error)
52
+ handleError('You are not logged in or an error occurred', error);
58
53
  }
59
- })
54
+ });
60
55
  }
@@ -1,19 +1,19 @@
1
- import { Command } from 'commander'
2
- import chalk from 'chalk'
1
+ import chalk from 'chalk';
2
+ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * Register autocomplete commands
6
6
  */
7
7
  export function registerAutocompleteCommands(program: Command): void {
8
- const autocomplete = program
8
+ program
9
9
  .command('autocomplete')
10
10
  .command('install')
11
11
  .description('Install shell autocompletion')
12
12
  .action(() => {
13
- console.log(chalk.green('✓ Berget autocomplete installed in your shell'))
14
- console.log(chalk.green('✓ Shell completion for kubectl also installed'))
15
- console.log('')
16
- console.log('Restart your shell or run:')
17
- console.log(' source ~/.bashrc')
18
- })
13
+ console.log(chalk.green('✓ Berget autocomplete installed in your shell'));
14
+ console.log(chalk.green('✓ Shell completion for kubectl also installed'));
15
+ console.log('');
16
+ console.log('Restart your shell or run:');
17
+ console.log(' source ~/.bashrc');
18
+ });
19
19
  }
@@ -1,15 +1,14 @@
1
- import { Command } from 'commander'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
3
- import { createAuthenticatedClient } from '../client'
4
- import { handleError } from '../utils/error-handler'
1
+ import { Command } from 'commander';
2
+
3
+ import { createAuthenticatedClient } from '../client';
4
+ import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure';
5
+ import { handleError } from '../utils/error-handler';
5
6
 
6
7
  /**
7
8
  * Register billing commands
8
9
  */
9
10
  export function registerBillingCommands(program: Command): void {
10
- const billing = program
11
- .command(COMMAND_GROUPS.BILLING)
12
- .description('Manage billing and usage')
11
+ const billing = program.command(COMMAND_GROUPS.BILLING).description('Manage billing and usage');
13
12
 
14
13
  billing
15
14
  .command(SUBCOMMANDS.BILLING.GET_USAGE)
@@ -17,28 +16,25 @@ export function registerBillingCommands(program: Command): void {
17
16
  .option('--model <modelId>', 'Get usage for a specific model')
18
17
  .action(async (options) => {
19
18
  try {
20
- const client = createAuthenticatedClient()
21
- let response
19
+ const client = createAuthenticatedClient();
20
+ let response;
22
21
 
23
22
  if (options.model) {
24
- const { data, error } = await client.GET(
25
- '/v1/usage/tokens/{modelId}',
26
- {
27
- params: { path: { modelId: options.model } },
28
- },
29
- )
30
- if (error) throw new Error(JSON.stringify(error))
31
- response = data
23
+ const { data, error } = await client.GET('/v1/usage/tokens/{modelId}', {
24
+ params: { path: { modelId: options.model } },
25
+ });
26
+ if (error) throw new Error(JSON.stringify(error));
27
+ response = data;
32
28
  } else {
33
- const { data, error } = await client.GET('/v1/usage/tokens')
34
- if (error) throw new Error(JSON.stringify(error))
35
- response = data
29
+ const { data, error } = await client.GET('/v1/usage/tokens');
30
+ if (error) throw new Error(JSON.stringify(error));
31
+ response = data;
36
32
  }
37
33
 
38
- console.log('Token Usage:')
39
- console.log(JSON.stringify(response, null, 2))
34
+ console.log('Token Usage:');
35
+ console.log(JSON.stringify(response, null, 2));
40
36
  } catch (error) {
41
- handleError('Failed to get token usage', error)
37
+ handleError('Failed to get token usage', error);
42
38
  }
43
- })
39
+ });
44
40
  }