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
package/AGENTS.md DELETED
@@ -1,374 +0,0 @@
1
- # Berget Code Agents
2
-
3
- This document describes the specialized agents available in this project for use with OpenCode.
4
-
5
- ## Available Agents
6
-
7
- ### Primary Agents
8
-
9
- #### fullstack
10
-
11
- Router/coordinator agent for full-stack development with schema-driven architecture. Handles routing between different personas based on file paths and task requirements.
12
-
13
- **Use when:**
14
-
15
- - Working across multiple parts of a monorepo
16
- - Need to coordinate between frontend, backend, devops, and app
17
- - Starting new projects and need to determine tech stack
18
-
19
- **Key features:**
20
-
21
- - Schema-driven development (database → OpenAPI → types)
22
- - Automatic routing to appropriate persona
23
- - Tech stack discovery and recommendations
24
-
25
- #### frontend
26
-
27
- Builds Scandinavian, type-safe UIs with React, Tailwind, and Shadcn.
28
-
29
- **Use when:**
30
-
31
- - Working with React components (.tsx files)
32
- - Frontend development in /apps/frontend
33
- - UI/UX implementation
34
-
35
- **Key features:**
36
-
37
- - Design system integration
38
- - Semantic tokens and accessibility
39
- - Props-first component architecture
40
-
41
- #### backend
42
-
43
- Functional, modular Koa + TypeScript services with schema-first approach and code quality focus.
44
-
45
- **Use when:**
46
-
47
- - Working with Koa routers and services
48
- - Backend development in /services
49
- - API development and database work
50
-
51
- **Key features:**
52
-
53
- - Zod validation and OpenAPI generation
54
- - Code quality and refactoring principles
55
- - PR workflow integration
56
-
57
- #### devops
58
-
59
- # ⚠️ ABSOLUTE RULE: kubectl apply NEVER
60
-
61
- **THIS RULE HAS NO EXCEPTIONS - APPLIES TO ALL ENVIRONMENTS: DEV, STAGING, PRODUCTION**
62
-
63
- Declarative GitOps infrastructure with FluxCD, Kustomize, Helm, and operators.
64
-
65
- **Use when:**
66
-
67
- - Working with Kubernetes manifests
68
- - Infrastructure in /infra or /k8s
69
- - CI/CD and deployment configurations
70
-
71
- **Key features:**
72
-
73
- - GitOps workflows
74
- - Operator-first approach
75
- - SemVer with release candidates
76
-
77
- ## 🚨 CRITICAL: WHY kubectl apply DESTROYS GITOPS
78
-
79
- **kubectl apply is fundamentally incompatible with GitOps because it:**
80
-
81
- 1. **Overwrites FluxCD metadata** - The `kubectl.kubernetes.io/last-applied-configuration` annotation gets replaced with kubectl's version, breaking FluxCD's tracking
82
- 2. **Breaks the single source of truth** - Your cluster state diverges from Git state, making Git no longer authoritative
83
- 3. **Creates synchronization conflicts** - FluxCD cannot reconcile differences between Git and cluster state
84
- 4. **Makes debugging impossible** - Manual changes are invisible in Git history
85
- 5. **Undermines the entire GitOps model** - The promise of "Git as source of truth" is broken
86
-
87
- ## 📋 EXACTLY WHAT GETS DESTROYED
88
-
89
- When you run `kubectl apply`, these critical metadata fields are corrupted:
90
-
91
- ```yaml
92
- # BEFORE: FluxCD-managed resource
93
- metadata:
94
- annotations:
95
- kubectl.kubernetes.io/last-applied-configuration: |
96
- {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"app","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"nginx:1.21","name":"nginx"}]}}}}
97
- kustomize.toolkit.fluxcd.io/checksum: a1b2c3d4e5f6
98
- kustomize.toolkit.fluxcd.io/ssa: Merge
99
-
100
- # AFTER: kubectl apply destroys this
101
- metadata:
102
- annotations:
103
- kubectl.kubernetes.io/last-applied-configuration: |
104
- {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"app","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"nginx:1.22","name":"nginx"}]}}}}
105
- # kustomize.toolkit.fluxcd.io/checksum: GONE!
106
- # kustomize.toolkit.fluxcd.io/ssa: GONE!
107
- ```
108
-
109
- ## 🔥 CONSEQUENCES OF USING kubectl apply
110
-
111
- **Immediate Impact:**
112
- - FluxCD loses track of the resource
113
- - Future Git commits may not apply correctly
114
- - Resource becomes "orphaned" from GitOps control
115
-
116
- **Long-term Damage:**
117
- - Cluster drift becomes undetectable
118
- - Rollback capabilities are compromised
119
- - Audit trail is broken
120
- - Team loses trust in GitOps process
121
-
122
- **Recovery Required:**
123
- - Manual intervention to restore FluxCD metadata
124
- - Potential resource recreation
125
- - Downtime during recovery
126
- - Complete audit of affected resources
127
-
128
- ## 🚨 KRITISKA REGLER FÖR FLUXCD-kluster
129
-
130
- # ⚠️ ABSOLUT ALDRIG: kubectl apply
131
-
132
- **DENNA REGLER HAR INGA UNDTAG - GÄLLER ALLTID: DEV, STAGING, PRODUCTION**
133
-
134
- **ABSOLUT ALDRIG använd `kubectl apply` i FluxCD-hanterade kluster!**
135
-
136
- ### ❌ FORBUDNA OPERATIONER
137
-
138
- ```bash
139
- # ❌ ALDRIG GÖR DETTA!
140
- kubectl apply -f deployment.yaml
141
- kubectl apply -f kustomization.yaml
142
- kubectl apply -f flux-system/ # SPECIELT INTE FLUXCD-MANIFEST!
143
- kubectl create -f ...
144
- kubectl replace -f ...
145
- kubectl edit deployment/...
146
- kubectl patch deployment/...
147
- ```
148
-
149
- ### ✅ TILLÅTNA OPERATIONER (Read-Only)
150
-
151
- ```bash
152
- # ✅ SÄKERT FÖR DIAGNOSTIK
153
- kubectl get pods
154
- kubectl describe deployment/app
155
- kubectl logs -f pod/name
156
- kubectl get events
157
- kubectl top nodes
158
- ```
159
-
160
- ### 🔄 RÄTT SÄTT ATT GÖRA ÄNDRINGAR
161
-
162
- 1. **Git är sanningens källa** - alla ändringar måste gå via Git repository
163
- 2. **FluxCD synkroniserar automatiskt** - ändra YAML-filer, inte klustret direkt
164
- 3. **Använd PR workflow** - commit ändringar, skapa PR, låt FluxCD hantera deployment
165
-
166
- ### 🚨 VAD HÄNDER OM DU ÄNDÅ ANVÄNDER kubectl apply?
167
-
168
- **DET HÄNDER OM DU ANVÄNDER kubectl apply:**
169
-
170
- - **Förstör FluxCD-metadata** - `kubectl.kubernetes.io/last-applied-configuration` skrivs över
171
- - **Breakar GitOps-modellen** - klustret divergerar från Git-repository
172
- - **FluxCD kan inte synkronisera** - konflikter mellan Git-state och kluster-state
173
- - **Svår att diagnostisera** - manuella ändringar är osynliga i Git-historiken
174
-
175
- **RESULTATET: FluxCD FÖRLORAR KONTROLLEN OCH KLUSTRET BLIR O-SYNKRONISERAT FRÅN GIT!**
176
-
177
- ### 🆘 NÖDSITUATIONER
178
-
179
- ```bash
180
- # Pausa FluxCD temporärt
181
- flux suspend kustomization app-name
182
-
183
- # Gör nödvändiga ändringar i Git
184
- git commit -m "emergency fix"
185
- git push
186
-
187
- # Återuppta FluxCD
188
- flux resume kustomization app-name
189
- ```
190
-
191
- ### 💡 MINNESREGEL
192
-
193
- > **"Git first, kubectl never"**
194
- >
195
- > Om du måste använda `kubectl apply` - gör det inte. Gör en ändring i Git istället.
196
-
197
- ### 📋 CHECKLIST FÖR ÄNDRINGAR
198
-
199
- - [ ] Ändring gjord i Git repository?
200
- - [ ] PR skapad och granskad?
201
- - [ ] FluxCD synkroniserar korrekt?
202
- - [ ] Ingen `kubectl apply` använd?
203
- - [ ] Kluster-state matchar Git-state?
204
-
205
- **VIKTIGT:** Dessa regler gäller ALLTID, även i utvecklingsmiljöer och tester!
206
-
207
- ### 💡 MINNESREGEL
208
-
209
- > **"Git first, kubectl never"**
210
- >
211
- > Om du måste använda `kubectl apply` - gör det inte. Gör en ändring i Git istället.
212
-
213
- ### 📋 CHECKLIST FÖR ÄNDRINGAR
214
-
215
- - [ ] Ändring gjord i Git repository?
216
- - [ ] PR skapad och granskad?
217
- - [ ] FluxCD synkroniserar korrekt?
218
- - [ ] Ingen `kubectl apply` använd?
219
- - [ ] Kluster-state matchar Git-state?
220
-
221
- **VIKTIGT:** Dessa regler gäller ALLTID, även i utvecklingsmiljöer och tester!
222
-
223
- ---
224
-
225
- ## ⚠️ ABSOLUT SLUTREGEL: INGA UNDTAG
226
-
227
- **kubectl apply är FÖRBJUDET i ALLA FluxCD-kluster, ALLTID, utan undantag.**
228
- **Detta inkluderar: dev, staging, production, testmiljöer, lokala kluster, ALLT.**
229
-
230
- **Helm Values Configuration Process:**
231
-
232
- 1. **Documentation First Approach:**
233
- - Always fetch official documentation for the specific chart version before writing values
234
- - Search Artifact Hub for the exact chart version documentation
235
- - Check the chart's GitHub repository for official docs and examples
236
- - Verify the exact version being used in the deployment
237
-
238
- 2. **Validation Requirements:**
239
- - Check for available validation schemas before committing YAML files
240
- - Use Helm's built-in validation tools (`helm lint`, `helm template`)
241
- - Validate against JSON schema if available for the chart
242
- - Ensure YAML syntax correctness with linters
243
-
244
- 3. **Standard Workflow:**
245
- - Identify chart name and exact version
246
- - Fetch official documentation from Artifact Hub/GitHub
247
- - Check for available schemas and validation tools
248
- - Write values according to official documentation
249
- - Validate against schema (if available)
250
- - Test with `helm template` or `helm lint`
251
- - Commit validated YAML files
252
-
253
- 4. **Quality Assurance:**
254
- - Never commit unvalidated Helm values
255
- - Use `helm dependency update` when adding new charts
256
- - Test rendering with `helm template --dry-run` before deployment
257
- - Document any custom values with comments referencing official docs
258
-
259
- #### app
260
-
261
- Expo + React Native applications with props-first architecture and offline awareness.
262
-
263
- **Use when:**
264
-
265
- - Mobile app development with Expo
266
- - React Native projects in /apps/app
267
- - Cross-platform mobile development
268
-
269
- **Key features:**
270
-
271
- - Shared design tokens with frontend
272
- - Offline-first architecture
273
- - Expo integration
274
-
275
- ### Subagents
276
-
277
- #### security
278
-
279
- Security specialist for penetration testing, OWASP compliance, and vulnerability assessments.
280
-
281
- **Use when:**
282
-
283
- - Need security review of code changes
284
- - OWASP Top 10 compliance checks
285
- - Vulnerability assessments
286
-
287
- **Key features:**
288
-
289
- - OWASP standards compliance
290
- - Security best practices
291
- - Actionable remediation strategies
292
-
293
- #### quality
294
-
295
- Quality assurance specialist for testing, building, and PR management.
296
-
297
- **Use when:**
298
-
299
- - Need to run test suites and build processes
300
- - Creating or updating pull requests
301
- - Monitoring GitHub for reviewer comments
302
- - Ensuring code quality standards
303
-
304
- **Key features:**
305
-
306
- - Comprehensive testing and building workflows
307
- - PR creation and management
308
- - GitHub integration for reviewer feedback
309
- - CLI command expertise for quality assurance
310
-
311
- ## Usage
312
-
313
- ### Switching Agents
314
-
315
- Use the `<tab>` key to cycle through primary agents during a session.
316
-
317
- ### Manual Agent Selection
318
-
319
- Use commands to switch to specific agents:
320
-
321
- - `/fullstack` - Switch to Fullstack agent
322
- - `/frontend` - Switch to Frontend agent
323
- - `/backend` - Switch to Backend agent
324
- - `/devops` - Switch to DevOps agent
325
- - `/app` - Switch to App agent
326
- - `/quality` - Switch to Quality agent for testing and PR management
327
-
328
- ### Using Subagents
329
-
330
- Mention subagents with `@` symbol:
331
-
332
- ```
333
- @security review this authentication implementation
334
- @quality run tests and create PR for these changes
335
- ```
336
-
337
- ## Routing Rules
338
-
339
- The fullstack agent automatically routes tasks based on file patterns:
340
-
341
- - `/apps/frontend` or `.tsx` files → frontend
342
- - `/apps/app` or Expo/React Native → app
343
- - `/infra`, `/k8s`, FluxCD, Helm → devops
344
- - `/services`, Koa routers → backend
345
-
346
- ## Configuration
347
-
348
- All agents are configured in `opencode.json` with:
349
-
350
- - Specialized prompts and temperature settings
351
- - Appropriate tool permissions
352
- - Model optimizations for their specific tasks
353
-
354
- ## Environment Setup
355
-
356
- Copy `.env.example` to `.env` and configure:
357
-
358
- ```
359
- BERGET_API_KEY=your_api_key_here
360
- ```
361
-
362
- ## Workflow
363
-
364
- All agents follow these principles:
365
-
366
- - **NEVER work directly in main branch** - ALWAYS use pull requests
367
- - **NEVER use 'git add .'** - ALWAYS add specific files with 'git add path/to/file'
368
- - **ALWAYS clean up test files, documentation files, and temporary artifacts before committing**
369
- - **ALWAYS ensure git history maintains production quality** - no test commits, no debugging code
370
- - **ALWAYS create descriptive commit messages following project conventions**
371
- - **ALWAYS run tests and build before creating PR**
372
- - Follow branch strategy and commit conventions
373
- - Create PRs for new functionality
374
- - Address reviewer feedback promptly
package/TODO.md DELETED
@@ -1,19 +0,0 @@
1
- # Berget CLI - TODO
2
-
3
- ## Implementerade funktioner
4
-
5
- - [x] Inloggning med BankID
6
- - [x] Skapa och hantera API-nycklar
7
-
8
- ## Kommande funktioner
9
-
10
- - [ ] Implementera riktiga API-anrop för klusterhantering
11
- - [ ] Implementera riktiga API-anrop för Flux-integration
12
- - [ ] Implementera riktiga API-anrop för Helm-kommandon
13
- - [ ] Implementera riktiga API-anrop för Kubectl-kommandon
14
- - [ ] Implementera riktiga API-anrop för samarbetsfunktioner
15
- - [ ] Förbättra felhantering och återhämtning
16
- - [ ] Lägg till enhetstester
17
- - [ ] Implementera lokal konfigurationshantering
18
- - [ ] Lägg till stöd för olika miljöer (dev, staging, prod)
19
- - [ ] Förbättra dokumentation och hjälptexter