berget 2.2.5 → 2.2.7

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 (148) hide show
  1. package/.github/workflows/publish.yml +8 -8
  2. package/.github/workflows/test.yml +12 -6
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierignore +15 -0
  5. package/.prettierrc +5 -3
  6. package/CONTRIBUTING.md +38 -0
  7. package/README.md +2 -148
  8. package/dist/index.js +21 -21
  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 +54 -62
  20. package/dist/src/commands/api-keys.js +132 -140
  21. package/dist/src/commands/auth.js +9 -9
  22. package/dist/src/commands/autocomplete.js +9 -9
  23. package/dist/src/commands/billing.js +7 -9
  24. package/dist/src/commands/chat.js +90 -92
  25. package/dist/src/commands/clusters.js +12 -12
  26. package/dist/src/commands/code/__tests__/auth-sync.test.js +348 -0
  27. package/dist/src/commands/code/__tests__/fake-api-key-service.js +23 -0
  28. package/dist/src/commands/code/__tests__/fake-auth-service.js +55 -0
  29. package/dist/src/commands/code/__tests__/fake-command-runner.js +50 -0
  30. package/dist/src/commands/code/__tests__/fake-file-store.js +55 -0
  31. package/dist/src/commands/code/__tests__/fake-prompter.js +133 -0
  32. package/dist/src/commands/code/__tests__/setup-flow.test.js +505 -0
  33. package/dist/src/commands/code/adapters/clack-prompter.js +81 -0
  34. package/dist/src/commands/code/adapters/fs-file-store.js +80 -0
  35. package/dist/src/commands/code/adapters/spawn-command-runner.js +53 -0
  36. package/dist/src/commands/code/auth-sync.js +283 -0
  37. package/dist/src/commands/code/errors.js +27 -0
  38. package/dist/src/commands/code/ports/auth-services.js +2 -0
  39. package/dist/src/commands/code/ports/command-runner.js +2 -0
  40. package/dist/src/commands/code/ports/file-store.js +2 -0
  41. package/dist/src/commands/code/ports/prompter.js +2 -0
  42. package/dist/src/commands/code/setup.js +533 -0
  43. package/dist/src/commands/code.js +223 -779
  44. package/dist/src/commands/models.js +13 -15
  45. package/dist/src/commands/users.js +6 -8
  46. package/dist/src/constants/command-structure.js +116 -114
  47. package/dist/src/services/api-key-service.js +43 -48
  48. package/dist/src/services/auth-service.js +60 -299
  49. package/dist/src/services/browser-auth.js +278 -0
  50. package/dist/src/services/chat-service.js +78 -91
  51. package/dist/src/services/cluster-service.js +6 -6
  52. package/dist/src/services/collaborator-service.js +5 -8
  53. package/dist/src/services/flux-service.js +5 -8
  54. package/dist/src/services/helm-service.js +5 -8
  55. package/dist/src/services/kubectl-service.js +7 -10
  56. package/dist/src/utils/config-checker.js +5 -5
  57. package/dist/src/utils/config-loader.js +25 -25
  58. package/dist/src/utils/default-api-key.js +23 -23
  59. package/dist/src/utils/env-manager.js +7 -7
  60. package/dist/src/utils/error-handler.js +60 -61
  61. package/dist/src/utils/logger.js +7 -7
  62. package/dist/src/utils/markdown-renderer.js +2 -2
  63. package/dist/src/utils/opencode-validator.js +17 -20
  64. package/dist/src/utils/token-manager.js +38 -11
  65. package/dist/tests/commands/chat.test.js +24 -24
  66. package/dist/tests/commands/code.test.js +169 -138
  67. package/dist/tests/utils/config-loader.test.js +114 -114
  68. package/dist/tests/utils/env-manager.test.js +57 -57
  69. package/dist/tests/utils/opencode-validator.test.js +44 -43
  70. package/dist/vitest.config.js +1 -1
  71. package/eslint.config.mjs +47 -0
  72. package/index.ts +42 -48
  73. package/package.json +30 -2
  74. package/src/agents/app.ts +27 -0
  75. package/src/agents/backend.ts +24 -0
  76. package/src/agents/devops.ts +33 -0
  77. package/src/agents/frontend.ts +24 -0
  78. package/src/agents/fullstack.ts +24 -0
  79. package/src/agents/index.ts +71 -0
  80. package/src/agents/quality.ts +69 -0
  81. package/src/agents/security.ts +26 -0
  82. package/src/agents/types.ts +17 -0
  83. package/src/client.ts +125 -167
  84. package/src/commands/api-keys.ts +261 -358
  85. package/src/commands/auth.ts +24 -30
  86. package/src/commands/autocomplete.ts +12 -12
  87. package/src/commands/billing.ts +22 -27
  88. package/src/commands/chat.ts +230 -323
  89. package/src/commands/clusters.ts +33 -33
  90. package/src/commands/code/__tests__/auth-sync.test.ts +481 -0
  91. package/src/commands/code/__tests__/fake-api-key-service.ts +13 -0
  92. package/src/commands/code/__tests__/fake-auth-service.ts +50 -0
  93. package/src/commands/code/__tests__/fake-command-runner.ts +44 -0
  94. package/src/commands/code/__tests__/fake-file-store.ts +44 -0
  95. package/src/commands/code/__tests__/fake-prompter.ts +121 -0
  96. package/src/commands/code/__tests__/setup-flow.test.ts +628 -0
  97. package/src/commands/code/adapters/clack-prompter.ts +55 -0
  98. package/src/commands/code/adapters/fs-file-store.ts +37 -0
  99. package/src/commands/code/adapters/spawn-command-runner.ts +40 -0
  100. package/src/commands/code/auth-sync.ts +329 -0
  101. package/src/commands/code/errors.ts +23 -0
  102. package/src/commands/code/ports/auth-services.ts +14 -0
  103. package/src/commands/code/ports/command-runner.ts +10 -0
  104. package/src/commands/code/ports/file-store.ts +7 -0
  105. package/src/commands/code/ports/prompter.ts +29 -0
  106. package/src/commands/code/setup.ts +630 -0
  107. package/src/commands/code.ts +335 -1074
  108. package/src/commands/index.ts +19 -19
  109. package/src/commands/models.ts +32 -37
  110. package/src/commands/users.ts +15 -22
  111. package/src/constants/command-structure.ts +120 -140
  112. package/src/services/api-key-service.ts +96 -113
  113. package/src/services/auth-service.ts +92 -339
  114. package/src/services/browser-auth.ts +296 -0
  115. package/src/services/chat-service.ts +246 -279
  116. package/src/services/cluster-service.ts +29 -32
  117. package/src/services/collaborator-service.ts +13 -18
  118. package/src/services/flux-service.ts +16 -18
  119. package/src/services/helm-service.ts +16 -18
  120. package/src/services/kubectl-service.ts +12 -14
  121. package/src/types/api.d.ts +924 -926
  122. package/src/types/json.d.ts +3 -3
  123. package/src/utils/config-checker.ts +10 -10
  124. package/src/utils/config-loader.ts +110 -127
  125. package/src/utils/default-api-key.ts +81 -93
  126. package/src/utils/env-manager.ts +36 -40
  127. package/src/utils/error-handler.ts +83 -78
  128. package/src/utils/logger.ts +41 -41
  129. package/src/utils/markdown-renderer.ts +11 -11
  130. package/src/utils/opencode-validator.ts +51 -56
  131. package/src/utils/token-manager.ts +84 -64
  132. package/templates/agents/app.md +23 -0
  133. package/templates/agents/backend.md +23 -0
  134. package/templates/agents/devops.md +30 -0
  135. package/templates/agents/frontend.md +25 -0
  136. package/templates/agents/fullstack.md +23 -0
  137. package/templates/agents/quality.md +69 -0
  138. package/templates/agents/security.md +21 -0
  139. package/tests/commands/chat.test.ts +60 -70
  140. package/tests/commands/code.test.ts +346 -345
  141. package/tests/utils/config-loader.test.ts +260 -260
  142. package/tests/utils/env-manager.test.ts +127 -134
  143. package/tests/utils/opencode-validator.test.ts +65 -69
  144. package/tsconfig.json +2 -2
  145. package/vitest.config.ts +3 -3
  146. package/AGENTS.md +0 -374
  147. package/TODO.md +0 -19
  148. package/opencode.json +0 -146
@@ -1,12 +1,12 @@
1
- import { createAuthenticatedClient } from '../client'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
1
+ import { createAuthenticatedClient } from "../client";
2
+ import { COMMAND_GROUPS, SUBCOMMANDS } from "../constants/command-structure";
3
3
 
4
4
  export interface Cluster {
5
- id: string
6
- name: string
7
- status: string
8
- nodes: number
9
- created: string
5
+ id: string;
6
+ name: string;
7
+ status: string;
8
+ nodes: number;
9
+ created: string;
10
10
  }
11
11
 
12
12
  /**
@@ -14,22 +14,22 @@ export interface Cluster {
14
14
  * Command group: clusters
15
15
  */
16
16
  export class ClusterService {
17
- private static instance: ClusterService
18
- private client = createAuthenticatedClient()
17
+ private static instance: ClusterService;
18
+ private client = createAuthenticatedClient();
19
19
 
20
20
  // Command group name for this service
21
- public static readonly COMMAND_GROUP = COMMAND_GROUPS.CLUSTERS
21
+ public static readonly COMMAND_GROUP = COMMAND_GROUPS.CLUSTERS;
22
22
 
23
23
  // Subcommands for this service
24
- public static readonly COMMANDS = SUBCOMMANDS.CLUSTERS
24
+ public static readonly COMMANDS = SUBCOMMANDS.CLUSTERS;
25
25
 
26
26
  private constructor() {}
27
27
 
28
28
  public static getInstance(): ClusterService {
29
29
  if (!ClusterService.instance) {
30
- ClusterService.instance = new ClusterService()
30
+ ClusterService.instance = new ClusterService();
31
31
  }
32
- return ClusterService.instance
32
+ return ClusterService.instance;
33
33
  }
34
34
 
35
35
  /**
@@ -38,17 +38,14 @@ export class ClusterService {
38
38
  */
39
39
  public async getUsage(clusterId: string): Promise<any> {
40
40
  try {
41
- const { data, error } = await this.client.GET(
42
- '/v1/clusters/{clusterId}/usage',
43
- {
44
- params: { path: { clusterId } },
45
- },
46
- )
47
- if (error) throw new Error(JSON.stringify(error))
48
- return data
41
+ const { data, error } = await this.client.GET("/v1/clusters/{clusterId}/usage", {
42
+ params: { path: { clusterId } },
43
+ });
44
+ if (error) throw new Error(JSON.stringify(error));
45
+ return data;
49
46
  } catch (error) {
50
- console.error('Failed to get cluster usage:', error)
51
- throw error
47
+ console.error("Failed to get cluster usage:", error);
48
+ throw error;
52
49
  }
53
50
  }
54
51
 
@@ -58,12 +55,12 @@ export class ClusterService {
58
55
  */
59
56
  public async list(): Promise<Cluster[]> {
60
57
  try {
61
- const { data, error } = await this.client.GET('/v1/clusters')
62
- if (error) throw new Error(JSON.stringify(error))
63
- return data?.data || []
58
+ const { data, error } = await this.client.GET("/v1/clusters");
59
+ if (error) throw new Error(JSON.stringify(error));
60
+ return data?.data || [];
64
61
  } catch (error) {
65
- console.error('Failed to list clusters:', error)
66
- throw error
62
+ console.error("Failed to list clusters:", error);
63
+ throw error;
67
64
  }
68
65
  }
69
66
 
@@ -75,11 +72,11 @@ export class ClusterService {
75
72
  try {
76
73
  // This is a placeholder since the API doesn't have a specific endpoint
77
74
  // In a real implementation, this would call a specific endpoint
78
- const clusters = await this.list()
79
- return clusters.find((cluster) => cluster.id === clusterId) || null
75
+ const clusters = await this.list();
76
+ return clusters.find(cluster => cluster.id === clusterId) || null;
80
77
  } catch (error) {
81
- console.error('Failed to describe cluster:', error)
82
- throw error
78
+ console.error("Failed to describe cluster:", error);
79
+ throw error;
83
80
  }
84
81
  }
85
82
  }
@@ -1,10 +1,9 @@
1
- import { createAuthenticatedClient } from '../client'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
1
+ import { COMMAND_GROUPS, SUBCOMMANDS } from "../constants/command-structure";
3
2
 
4
3
  export interface Collaborator {
5
- username: string
6
- role: string
7
- status: string
4
+ username: string;
5
+ role: string;
6
+ status: string;
8
7
  }
9
8
 
10
9
  /**
@@ -12,22 +11,21 @@ export interface Collaborator {
12
11
  * Command group: users
13
12
  */
14
13
  export class CollaboratorService {
15
- private static instance: CollaboratorService
16
- private client = createAuthenticatedClient()
14
+ private static instance: CollaboratorService;
17
15
 
18
16
  // Command group name for this service
19
- public static readonly COMMAND_GROUP = COMMAND_GROUPS.USERS
17
+ public static readonly COMMAND_GROUP = COMMAND_GROUPS.USERS;
20
18
 
21
19
  // Subcommands for this service
22
- public static readonly COMMANDS = SUBCOMMANDS.USERS
20
+ public static readonly COMMANDS = SUBCOMMANDS.USERS;
23
21
 
24
22
  private constructor() {}
25
23
 
26
24
  public static getInstance(): CollaboratorService {
27
25
  if (!CollaboratorService.instance) {
28
- CollaboratorService.instance = new CollaboratorService()
26
+ CollaboratorService.instance = new CollaboratorService();
29
27
  }
30
- return CollaboratorService.instance
28
+ return CollaboratorService.instance;
31
29
  }
32
30
 
33
31
  /**
@@ -35,11 +33,8 @@ export class CollaboratorService {
35
33
  * Command: berget users invite
36
34
  * This endpoint is not available in the API
37
35
  */
38
- public async invite(
39
- clusterId: string,
40
- githubUsername: string,
41
- ): Promise<Collaborator[]> {
42
- throw new Error('This functionality is not available in the API')
36
+ public async invite(_clusterId: string, _githubUsername: string): Promise<Collaborator[]> {
37
+ throw new Error("This functionality is not available in the API");
43
38
  }
44
39
 
45
40
  /**
@@ -47,7 +42,7 @@ export class CollaboratorService {
47
42
  * Command: berget users list
48
43
  * This endpoint is not available in the API
49
44
  */
50
- public async list(clusterId: string): Promise<Collaborator[]> {
51
- throw new Error('This functionality is not available in the API')
45
+ public async list(_clusterId: string): Promise<Collaborator[]> {
46
+ throw new Error("This functionality is not available in the API");
52
47
  }
53
48
  }
@@ -1,16 +1,15 @@
1
- import { createAuthenticatedClient } from '../client'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
1
+ import { COMMAND_GROUPS, SUBCOMMANDS } from "../constants/command-structure";
3
2
 
4
3
  export interface FluxInstallOptions {
5
- cluster: string
4
+ cluster: string;
6
5
  }
7
6
 
8
7
  export interface FluxBootstrapOptions {
9
- provider: string
10
- owner?: string
11
- repository?: string
12
- path?: string
13
- personal?: boolean
8
+ provider: string;
9
+ owner?: string;
10
+ repository?: string;
11
+ path?: string;
12
+ personal?: boolean;
14
13
  }
15
14
 
16
15
  /**
@@ -18,22 +17,21 @@ export interface FluxBootstrapOptions {
18
17
  * Command group: flux
19
18
  */
20
19
  export class FluxService {
21
- private static instance: FluxService
22
- private client = createAuthenticatedClient()
20
+ private static instance: FluxService;
23
21
 
24
22
  // Command group name for this service
25
- public static readonly COMMAND_GROUP = COMMAND_GROUPS.FLUX
23
+ public static readonly COMMAND_GROUP = COMMAND_GROUPS.FLUX;
26
24
 
27
25
  // Subcommands for this service
28
- public static readonly COMMANDS = SUBCOMMANDS.FLUX
26
+ public static readonly COMMANDS = SUBCOMMANDS.FLUX;
29
27
 
30
28
  private constructor() {}
31
29
 
32
30
  public static getInstance(): FluxService {
33
31
  if (!FluxService.instance) {
34
- FluxService.instance = new FluxService()
32
+ FluxService.instance = new FluxService();
35
33
  }
36
- return FluxService.instance
34
+ return FluxService.instance;
37
35
  }
38
36
 
39
37
  /**
@@ -41,8 +39,8 @@ export class FluxService {
41
39
  * Command: berget flux install
42
40
  * This endpoint is not available in the API
43
41
  */
44
- public async install(options: FluxInstallOptions): Promise<boolean> {
45
- throw new Error('This functionality is not available in the API')
42
+ public async install(_options: FluxInstallOptions): Promise<boolean> {
43
+ throw new Error("This functionality is not available in the API");
46
44
  }
47
45
 
48
46
  /**
@@ -50,7 +48,7 @@ export class FluxService {
50
48
  * Command: berget flux bootstrap
51
49
  * This endpoint is not available in the API
52
50
  */
53
- public async bootstrap(options: FluxBootstrapOptions): Promise<boolean> {
54
- throw new Error('This functionality is not available in the API')
51
+ public async bootstrap(_options: FluxBootstrapOptions): Promise<boolean> {
52
+ throw new Error("This functionality is not available in the API");
55
53
  }
56
54
  }
@@ -1,16 +1,15 @@
1
- import { createAuthenticatedClient } from '../client'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
1
+ import { COMMAND_GROUPS, SUBCOMMANDS } from "../constants/command-structure";
3
2
 
4
3
  export interface HelmRepoAddOptions {
5
- name: string
6
- url: string
4
+ name: string;
5
+ url: string;
7
6
  }
8
7
 
9
8
  export interface HelmInstallOptions {
10
- name: string
11
- chart: string
12
- namespace?: string
13
- values?: Record<string, string>
9
+ name: string;
10
+ chart: string;
11
+ namespace?: string;
12
+ values?: Record<string, string>;
14
13
  }
15
14
 
16
15
  /**
@@ -18,22 +17,21 @@ export interface HelmInstallOptions {
18
17
  * Command group: helm
19
18
  */
20
19
  export class HelmService {
21
- private static instance: HelmService
22
- private client = createAuthenticatedClient()
20
+ private static instance: HelmService;
23
21
 
24
22
  // Command group name for this service
25
- public static readonly COMMAND_GROUP = COMMAND_GROUPS.HELM
23
+ public static readonly COMMAND_GROUP = COMMAND_GROUPS.HELM;
26
24
 
27
25
  // Subcommands for this service
28
- public static readonly COMMANDS = SUBCOMMANDS.HELM
26
+ public static readonly COMMANDS = SUBCOMMANDS.HELM;
29
27
 
30
28
  private constructor() {}
31
29
 
32
30
  public static getInstance(): HelmService {
33
31
  if (!HelmService.instance) {
34
- HelmService.instance = new HelmService()
32
+ HelmService.instance = new HelmService();
35
33
  }
36
- return HelmService.instance
34
+ return HelmService.instance;
37
35
  }
38
36
 
39
37
  /**
@@ -41,8 +39,8 @@ export class HelmService {
41
39
  * Command: berget helm add-repo
42
40
  * This endpoint is not available in the API
43
41
  */
44
- public async addRepo(options: HelmRepoAddOptions): Promise<boolean> {
45
- throw new Error('This functionality is not available in the API')
42
+ public async addRepo(_options: HelmRepoAddOptions): Promise<boolean> {
43
+ throw new Error("This functionality is not available in the API");
46
44
  }
47
45
 
48
46
  /**
@@ -50,7 +48,7 @@ export class HelmService {
50
48
  * Command: berget helm install
51
49
  * This endpoint is not available in the API
52
50
  */
53
- public async install(options: HelmInstallOptions): Promise<any> {
54
- throw new Error('This functionality is not available in the API')
51
+ public async install(_options: HelmInstallOptions): Promise<any> {
52
+ throw new Error("This functionality is not available in the API");
55
53
  }
56
54
  }
@@ -1,27 +1,25 @@
1
- import { createAuthenticatedClient } from '../client'
2
- import { COMMAND_GROUPS, SUBCOMMANDS } from '../constants/command-structure'
1
+ import { COMMAND_GROUPS, SUBCOMMANDS } from "../constants/command-structure";
3
2
 
4
3
  /**
5
4
  * Service for managing Kubernetes resources
6
5
  * Command group: kubectl
7
6
  */
8
7
  export class KubectlService {
9
- private static instance: KubectlService
10
- private client = createAuthenticatedClient()
8
+ private static instance: KubectlService;
11
9
 
12
10
  // Command group name for this service
13
- public static readonly COMMAND_GROUP = COMMAND_GROUPS.KUBECTL
11
+ public static readonly COMMAND_GROUP = COMMAND_GROUPS.KUBECTL;
14
12
 
15
13
  // Subcommands for this service
16
- public static readonly COMMANDS = SUBCOMMANDS.KUBECTL
14
+ public static readonly COMMANDS = SUBCOMMANDS.KUBECTL;
17
15
 
18
16
  private constructor() {}
19
17
 
20
18
  public static getInstance(): KubectlService {
21
19
  if (!KubectlService.instance) {
22
- KubectlService.instance = new KubectlService()
20
+ KubectlService.instance = new KubectlService();
23
21
  }
24
- return KubectlService.instance
22
+ return KubectlService.instance;
25
23
  }
26
24
 
27
25
  /**
@@ -29,8 +27,8 @@ export class KubectlService {
29
27
  * Command: berget kubectl create-namespace
30
28
  * This endpoint is not available in the API
31
29
  */
32
- public async createNamespace(name: string): Promise<boolean> {
33
- throw new Error('This functionality is not available in the API')
30
+ public async createNamespace(_name: string): Promise<boolean> {
31
+ throw new Error("This functionality is not available in the API");
34
32
  }
35
33
 
36
34
  /**
@@ -38,8 +36,8 @@ export class KubectlService {
38
36
  * Command: berget kubectl apply
39
37
  * This endpoint is not available in the API
40
38
  */
41
- public async apply(filename: string): Promise<boolean> {
42
- throw new Error('This functionality is not available in the API')
39
+ public async apply(_filename: string): Promise<boolean> {
40
+ throw new Error("This functionality is not available in the API");
43
41
  }
44
42
 
45
43
  /**
@@ -47,7 +45,7 @@ export class KubectlService {
47
45
  * Command: berget kubectl get
48
46
  * This endpoint is not available in the API
49
47
  */
50
- public async get(resource: string, namespace?: string): Promise<any[]> {
51
- throw new Error('This functionality is not available in the API')
48
+ public async get(_resource: string, _namespace?: string): Promise<any[]> {
49
+ throw new Error("This functionality is not available in the API");
52
50
  }
53
51
  }