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.
- package/.github/workflows/publish.yml +2 -2
- package/.github/workflows/test.yml +10 -4
- package/.husky/pre-commit +1 -0
- package/.prettierignore +15 -0
- package/.prettierrc +7 -3
- package/CONTRIBUTING.md +38 -0
- package/README.md +2 -148
- package/dist/index.js +10 -11
- package/dist/package.json +30 -2
- package/dist/src/agents/app.js +28 -0
- package/dist/src/agents/backend.js +25 -0
- package/dist/src/agents/devops.js +34 -0
- package/dist/src/agents/frontend.js +25 -0
- package/dist/src/agents/fullstack.js +25 -0
- package/dist/src/agents/index.js +61 -0
- package/dist/src/agents/quality.js +70 -0
- package/dist/src/agents/security.js +26 -0
- package/dist/src/agents/types.js +2 -0
- package/dist/src/client.js +97 -117
- package/dist/src/commands/api-keys.js +75 -90
- package/dist/src/commands/auth.js +7 -16
- package/dist/src/commands/autocomplete.js +1 -1
- package/dist/src/commands/billing.js +6 -17
- package/dist/src/commands/chat.js +68 -101
- package/dist/src/commands/clusters.js +9 -18
- package/dist/src/commands/code/__tests__/auth-sync.test.js +351 -0
- package/dist/src/commands/code/__tests__/fake-api-key-service.js +13 -0
- package/dist/src/commands/code/__tests__/fake-auth-service.js +47 -0
- package/dist/src/commands/code/__tests__/fake-command-runner.js +21 -34
- package/dist/src/commands/code/__tests__/fake-file-store.js +20 -33
- package/dist/src/commands/code/__tests__/fake-prompter.js +83 -57
- package/dist/src/commands/code/__tests__/setup-flow.test.js +359 -92
- package/dist/src/commands/code/adapters/clack-prompter.js +15 -22
- package/dist/src/commands/code/adapters/fs-file-store.js +26 -40
- package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -37
- package/dist/src/commands/code/auth-sync.js +270 -0
- package/dist/src/commands/code/errors.js +12 -9
- package/dist/src/commands/code/ports/auth-services.js +2 -0
- package/dist/src/commands/code/setup.js +387 -281
- package/dist/src/commands/code.js +205 -332
- package/dist/src/commands/index.js +5 -5
- package/dist/src/commands/models.js +6 -17
- package/dist/src/commands/users.js +5 -16
- package/dist/src/constants/command-structure.js +104 -104
- package/dist/src/services/api-key-service.js +132 -157
- package/dist/src/services/auth-service.js +89 -342
- package/dist/src/services/browser-auth.js +268 -0
- package/dist/src/services/chat-service.js +371 -401
- package/dist/src/services/cluster-service.js +47 -62
- package/dist/src/services/collaborator-service.js +10 -25
- package/dist/src/services/flux-service.js +14 -29
- package/dist/src/services/helm-service.js +10 -25
- package/dist/src/services/kubectl-service.js +16 -33
- package/dist/src/utils/config-checker.js +3 -3
- package/dist/src/utils/config-loader.js +95 -95
- package/dist/src/utils/default-api-key.js +124 -134
- package/dist/src/utils/env-manager.js +55 -66
- package/dist/src/utils/error-handler.js +20 -21
- package/dist/src/utils/logger.js +72 -65
- package/dist/src/utils/markdown-renderer.js +27 -27
- package/dist/src/utils/opencode-validator.js +63 -68
- package/dist/src/utils/token-manager.js +74 -45
- package/dist/tests/commands/chat.test.js +16 -25
- package/dist/tests/commands/code.test.js +95 -104
- package/dist/tests/utils/config-loader.test.js +48 -48
- package/dist/tests/utils/env-manager.test.js +43 -52
- package/dist/tests/utils/opencode-validator.test.js +22 -21
- package/dist/vitest.config.js +1 -1
- package/eslint.config.mjs +67 -0
- package/index.ts +35 -42
- package/package.json +30 -2
- package/src/agents/app.ts +27 -0
- package/src/agents/backend.ts +24 -0
- package/src/agents/devops.ts +33 -0
- package/src/agents/frontend.ts +24 -0
- package/src/agents/fullstack.ts +24 -0
- package/src/agents/index.ts +73 -0
- package/src/agents/quality.ts +69 -0
- package/src/agents/security.ts +26 -0
- package/src/agents/types.ts +17 -0
- package/src/client.ts +118 -152
- package/src/commands/api-keys.ts +241 -333
- package/src/commands/auth.ts +22 -27
- package/src/commands/autocomplete.ts +9 -9
- package/src/commands/billing.ts +20 -24
- package/src/commands/chat.ts +248 -338
- package/src/commands/clusters.ts +27 -26
- package/src/commands/code/__tests__/auth-sync.test.ts +482 -0
- package/src/commands/code/__tests__/fake-api-key-service.ts +13 -0
- package/src/commands/code/__tests__/fake-auth-service.ts +50 -0
- package/src/commands/code/__tests__/fake-command-runner.ts +45 -42
- package/src/commands/code/__tests__/fake-file-store.ts +32 -23
- package/src/commands/code/__tests__/fake-prompter.ts +116 -77
- package/src/commands/code/__tests__/setup-flow.test.ts +624 -268
- package/src/commands/code/adapters/clack-prompter.ts +53 -39
- package/src/commands/code/adapters/fs-file-store.ts +32 -27
- package/src/commands/code/adapters/spawn-command-runner.ts +38 -29
- package/src/commands/code/auth-sync.ts +329 -0
- package/src/commands/code/errors.ts +18 -18
- package/src/commands/code/ports/auth-services.ts +14 -0
- package/src/commands/code/ports/command-runner.ts +8 -4
- package/src/commands/code/ports/file-store.ts +5 -4
- package/src/commands/code/ports/prompter.ts +24 -18
- package/src/commands/code/setup.ts +570 -340
- package/src/commands/code.ts +338 -539
- package/src/commands/index.ts +20 -19
- package/src/commands/models.ts +28 -32
- package/src/commands/users.ts +15 -21
- package/src/constants/command-structure.ts +134 -157
- package/src/services/api-key-service.ts +105 -122
- package/src/services/auth-service.ts +99 -345
- package/src/services/browser-auth.ts +296 -0
- package/src/services/chat-service.ts +265 -299
- package/src/services/cluster-service.ts +42 -45
- package/src/services/collaborator-service.ts +14 -19
- package/src/services/flux-service.ts +23 -25
- package/src/services/helm-service.ts +19 -21
- package/src/services/kubectl-service.ts +17 -19
- package/src/types/api.d.ts +1905 -1907
- package/src/types/json.d.ts +2 -2
- package/src/utils/config-checker.ts +10 -10
- package/src/utils/config-loader.ts +162 -178
- package/src/utils/default-api-key.ts +114 -125
- package/src/utils/env-manager.ts +53 -57
- package/src/utils/error-handler.ts +61 -56
- package/src/utils/logger.ts +79 -73
- package/src/utils/markdown-renderer.ts +31 -31
- package/src/utils/opencode-validator.ts +85 -89
- package/src/utils/token-manager.ts +108 -87
- package/templates/agents/app.md +1 -0
- package/templates/agents/backend.md +1 -0
- package/templates/agents/devops.md +2 -0
- package/templates/agents/frontend.md +1 -0
- package/templates/agents/fullstack.md +1 -0
- package/templates/agents/quality.md +45 -40
- package/templates/agents/security.md +1 -0
- package/tests/commands/chat.test.ts +53 -62
- package/tests/commands/code.test.ts +265 -310
- package/tests/utils/config-loader.test.ts +189 -188
- package/tests/utils/env-manager.test.ts +110 -113
- package/tests/utils/opencode-validator.test.ts +52 -56
- package/tsconfig.json +4 -3
- package/vitest.config.ts +3 -3
- package/AGENTS.md +0 -374
- package/TODO.md +0 -19
|
@@ -12,6 +12,7 @@ permission:
|
|
|
12
12
|
Voice: Scandinavian calm—precise, concise, confident. You are Berget Code Security agent. Expert in application security, penetration testing, and OWASP standards. Core responsibilities: Conduct security assessments and penetration tests, Validate OWASP Top 10 compliance, Review code for security vulnerabilities, Implement security headers and Content Security Policy (CSP), Audit API security, Check for sensitive data exposure, Validate input sanitization and output encoding, Assess dependency security and supply chain risks. Tools and techniques: OWASP ZAP, Burp Suite, security linters, dependency scanners, manual code review. Always provide specific, actionable security recommendations with priority levels.
|
|
13
13
|
|
|
14
14
|
GIT WORKFLOW RULES (CRITICAL):
|
|
15
|
+
|
|
15
16
|
- NEVER push directly to main branch - ALWAYS use pull requests
|
|
16
17
|
- NEVER use 'git add .' - ALWAYS add specific files with 'git add path/to/file'
|
|
17
18
|
- ALWAYS clean up test files, documentation files, and temporary artifacts before committing
|
|
@@ -1,83 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { registerChatCommands } from '../../src/commands/chat';
|
|
5
|
+
import { ChatService } from '../../src/services/chat-service';
|
|
6
|
+
import { DefaultApiKeyManager } from '../../src/utils/default-api-key';
|
|
6
7
|
|
|
7
8
|
// Mock dependencies
|
|
8
|
-
vi.mock('../../src/services/chat-service')
|
|
9
|
-
vi.mock('../../src/utils/default-api-key')
|
|
9
|
+
vi.mock('../../src/services/chat-service');
|
|
10
|
+
vi.mock('../../src/utils/default-api-key');
|
|
10
11
|
vi.mock('readline', () => ({
|
|
11
12
|
createInterface: vi.fn(() => ({
|
|
12
|
-
question: vi.fn(),
|
|
13
13
|
close: vi.fn(),
|
|
14
|
+
question: vi.fn(),
|
|
14
15
|
})),
|
|
15
|
-
}))
|
|
16
|
+
}));
|
|
16
17
|
|
|
17
18
|
describe('Chat Commands', () => {
|
|
18
|
-
let program: Command
|
|
19
|
-
let mockChatService: any
|
|
20
|
-
let mockDefaultApiKeyManager: any
|
|
19
|
+
let program: Command;
|
|
20
|
+
let mockChatService: any;
|
|
21
|
+
let mockDefaultApiKeyManager: any;
|
|
21
22
|
|
|
22
23
|
beforeEach(() => {
|
|
23
|
-
program = new Command()
|
|
24
|
+
program = new Command();
|
|
24
25
|
|
|
25
26
|
// Mock ChatService
|
|
26
27
|
mockChatService = {
|
|
27
28
|
createCompletion: vi.fn(),
|
|
28
29
|
listModels: vi.fn(),
|
|
29
|
-
}
|
|
30
|
-
vi.mocked(ChatService.getInstance).mockReturnValue(mockChatService)
|
|
30
|
+
};
|
|
31
|
+
vi.mocked(ChatService.getInstance).mockReturnValue(mockChatService);
|
|
31
32
|
|
|
32
33
|
// Mock DefaultApiKeyManager
|
|
33
34
|
mockDefaultApiKeyManager = {
|
|
34
35
|
getDefaultApiKeyData: vi.fn(),
|
|
35
36
|
promptForDefaultApiKey: vi.fn(),
|
|
36
|
-
}
|
|
37
|
-
vi.mocked(DefaultApiKeyManager.getInstance).mockReturnValue(
|
|
38
|
-
mockDefaultApiKeyManager,
|
|
39
|
-
)
|
|
37
|
+
};
|
|
38
|
+
vi.mocked(DefaultApiKeyManager.getInstance).mockReturnValue(mockDefaultApiKeyManager);
|
|
40
39
|
|
|
41
|
-
registerChatCommands(program)
|
|
42
|
-
})
|
|
40
|
+
registerChatCommands(program);
|
|
41
|
+
});
|
|
43
42
|
|
|
44
43
|
afterEach(() => {
|
|
45
|
-
vi.clearAllMocks()
|
|
46
|
-
})
|
|
44
|
+
vi.clearAllMocks();
|
|
45
|
+
});
|
|
47
46
|
|
|
48
47
|
describe('chat run command', () => {
|
|
49
48
|
it('should use berget/glm-4.7 as default model', () => {
|
|
50
|
-
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat')
|
|
51
|
-
const runCommand = chatCommand?.commands.find(
|
|
52
|
-
(cmd) => cmd.name() === 'run',
|
|
53
|
-
)
|
|
49
|
+
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat');
|
|
50
|
+
const runCommand = chatCommand?.commands.find((cmd) => cmd.name() === 'run');
|
|
54
51
|
|
|
55
|
-
expect(runCommand).toBeDefined()
|
|
52
|
+
expect(runCommand).toBeDefined();
|
|
56
53
|
|
|
57
54
|
// Check the help text which contains the default model
|
|
58
|
-
const helpText = runCommand?.helpInformation()
|
|
59
|
-
expect(helpText).toContain('glm-4.7')
|
|
60
|
-
})
|
|
55
|
+
const helpText = runCommand?.helpInformation();
|
|
56
|
+
expect(helpText).toContain('glm-4.7');
|
|
57
|
+
});
|
|
61
58
|
|
|
62
59
|
it('should have streaming enabled by default', () => {
|
|
63
|
-
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat')
|
|
64
|
-
const runCommand = chatCommand?.commands.find(
|
|
65
|
-
(cmd) => cmd.name() === 'run',
|
|
66
|
-
)
|
|
60
|
+
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat');
|
|
61
|
+
const runCommand = chatCommand?.commands.find((cmd) => cmd.name() === 'run');
|
|
67
62
|
|
|
68
|
-
expect(runCommand).toBeDefined()
|
|
63
|
+
expect(runCommand).toBeDefined();
|
|
69
64
|
|
|
70
65
|
// Check that the option is --no-stream (meaning streaming is default)
|
|
71
|
-
const streamOption = runCommand?.options.find(
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
expect(streamOption?.description).toContain('Disable streaming')
|
|
76
|
-
})
|
|
66
|
+
const streamOption = runCommand?.options.find((opt) => opt.long === '--no-stream');
|
|
67
|
+
expect(streamOption).toBeDefined();
|
|
68
|
+
expect(streamOption?.description).toContain('Disable streaming');
|
|
69
|
+
});
|
|
77
70
|
|
|
78
71
|
it('should create completion with correct default options', async () => {
|
|
79
72
|
// Mock API key
|
|
80
|
-
process.env.BERGET_API_KEY = 'test-key'
|
|
73
|
+
process.env.BERGET_API_KEY = 'test-key';
|
|
81
74
|
|
|
82
75
|
// Mock successful completion
|
|
83
76
|
mockChatService.createCompletion.mockResolvedValue({
|
|
@@ -86,44 +79,42 @@ describe('Chat Commands', () => {
|
|
|
86
79
|
message: { content: 'Test response' },
|
|
87
80
|
},
|
|
88
81
|
],
|
|
89
|
-
})
|
|
82
|
+
});
|
|
90
83
|
|
|
91
84
|
// This would normally test the actual command execution
|
|
92
85
|
// but since it involves readline interaction, we just verify
|
|
93
86
|
// that the service would be called with correct defaults
|
|
94
|
-
expect(mockChatService.createCompletion).not.toHaveBeenCalled()
|
|
87
|
+
expect(mockChatService.createCompletion).not.toHaveBeenCalled();
|
|
95
88
|
|
|
96
89
|
// Clean up
|
|
97
|
-
delete process.env.BERGET_API_KEY
|
|
98
|
-
})
|
|
99
|
-
})
|
|
90
|
+
delete process.env.BERGET_API_KEY;
|
|
91
|
+
});
|
|
92
|
+
});
|
|
100
93
|
|
|
101
94
|
describe('chat list command', () => {
|
|
102
95
|
it('should list available models', async () => {
|
|
103
96
|
const mockModels = {
|
|
104
97
|
data: [
|
|
105
98
|
{
|
|
106
|
-
id: 'gpt-oss',
|
|
107
|
-
owned_by: 'openai',
|
|
108
99
|
active: true,
|
|
109
100
|
capabilities: {
|
|
110
|
-
vision: false,
|
|
111
101
|
function_calling: true,
|
|
112
102
|
json_mode: true,
|
|
103
|
+
vision: false,
|
|
113
104
|
},
|
|
105
|
+
id: 'gpt-oss',
|
|
106
|
+
owned_by: 'openai',
|
|
114
107
|
},
|
|
115
108
|
],
|
|
116
|
-
}
|
|
109
|
+
};
|
|
117
110
|
|
|
118
|
-
mockChatService.listModels.mockResolvedValue(mockModels)
|
|
111
|
+
mockChatService.listModels.mockResolvedValue(mockModels);
|
|
119
112
|
|
|
120
|
-
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat')
|
|
121
|
-
const listCommand = chatCommand?.commands.find(
|
|
122
|
-
(cmd) => cmd.name() === 'list',
|
|
123
|
-
)
|
|
113
|
+
const chatCommand = program.commands.find((cmd) => cmd.name() === 'chat');
|
|
114
|
+
const listCommand = chatCommand?.commands.find((cmd) => cmd.name() === 'list');
|
|
124
115
|
|
|
125
|
-
expect(listCommand).toBeDefined()
|
|
126
|
-
expect(listCommand?.description()).toBe('List available chat models')
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
})
|
|
116
|
+
expect(listCommand).toBeDefined();
|
|
117
|
+
expect(listCommand?.description()).toBe('List available chat models');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|