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
|
@@ -1,55 +1,59 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats and prints error messages in a consistent way
|
|
5
5
|
*/
|
|
6
6
|
export function handleError(message: string, error: any): void {
|
|
7
|
-
console.error(chalk.red(`❌ Error: ${message}`))
|
|
7
|
+
console.error(chalk.red(`❌ Error: ${message}`));
|
|
8
8
|
|
|
9
|
-
let errorDetails = ''
|
|
10
|
-
let errorCode = ''
|
|
11
|
-
let errorType = ''
|
|
9
|
+
let errorDetails = '';
|
|
10
|
+
let errorCode = '';
|
|
11
|
+
let errorType = '';
|
|
12
12
|
|
|
13
13
|
// If the error is a string (like JSON.stringify(error))
|
|
14
14
|
if (typeof error === 'string') {
|
|
15
15
|
try {
|
|
16
16
|
// Try to parse it as JSON
|
|
17
|
-
const parsedError = JSON.parse(error)
|
|
17
|
+
const parsedError = JSON.parse(error);
|
|
18
18
|
if (parsedError.error) {
|
|
19
|
-
errorDetails = parsedError.error.message || parsedError.error
|
|
20
|
-
errorCode = parsedError.error.code || parsedError.code
|
|
21
|
-
errorType = parsedError.error.type || ''
|
|
19
|
+
errorDetails = parsedError.error.message || parsedError.error;
|
|
20
|
+
errorCode = parsedError.error.code || parsedError.code;
|
|
21
|
+
errorType = parsedError.error.type || '';
|
|
22
22
|
} else {
|
|
23
|
-
errorDetails = error
|
|
23
|
+
errorDetails = error;
|
|
24
24
|
}
|
|
25
25
|
} catch {
|
|
26
26
|
// If it's not valid JSON, just print the string
|
|
27
|
-
errorDetails = error
|
|
27
|
+
errorDetails = error;
|
|
28
28
|
}
|
|
29
29
|
} else if (error && error.message) {
|
|
30
30
|
// If it's an Error object
|
|
31
|
-
errorDetails = error.message
|
|
32
|
-
errorCode = error.code
|
|
33
|
-
errorType = error.type
|
|
31
|
+
errorDetails = error.message;
|
|
32
|
+
errorCode = error.code;
|
|
33
|
+
errorType = error.type;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Print error details
|
|
37
37
|
if (errorDetails) {
|
|
38
|
-
console.error(chalk.dim(`📝 Details: ${errorDetails}`))
|
|
38
|
+
console.error(chalk.dim(`📝 Details: ${errorDetails}`));
|
|
39
39
|
}
|
|
40
40
|
if (errorCode) {
|
|
41
|
-
console.error(chalk.dim(`🔢 Code: ${errorCode}`))
|
|
41
|
+
console.error(chalk.dim(`🔢 Code: ${errorCode}`));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Provide helpful troubleshooting based on error type
|
|
45
|
-
provideTroubleshootingTips(errorType, errorCode, errorDetails)
|
|
45
|
+
provideTroubleshootingTips(errorType, errorCode, errorDetails);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Provides helpful troubleshooting tips based on error type
|
|
50
50
|
*/
|
|
51
|
-
function provideTroubleshootingTips(
|
|
52
|
-
|
|
51
|
+
function provideTroubleshootingTips(
|
|
52
|
+
errorType: string,
|
|
53
|
+
errorCode: string,
|
|
54
|
+
errorDetails: string,
|
|
55
|
+
): void {
|
|
56
|
+
console.error(chalk.blue('\n💡 Troubleshooting tips:'));
|
|
53
57
|
|
|
54
58
|
// Authentication errors
|
|
55
59
|
if (
|
|
@@ -58,10 +62,10 @@ function provideTroubleshootingTips(errorType: string, errorCode: string, errorD
|
|
|
58
62
|
errorDetails?.includes('Unauthorized') ||
|
|
59
63
|
errorDetails?.includes('Authentication failed')
|
|
60
64
|
) {
|
|
61
|
-
console.error(chalk.yellow(' 🔐 Authentication issue detected:'))
|
|
62
|
-
console.error(chalk.white(' • Run `berget auth login` to log in'))
|
|
63
|
-
console.error(chalk.white(' • Check if your session has expired'))
|
|
64
|
-
console.error(chalk.white(' • Verify you have the correct permissions'))
|
|
65
|
+
console.error(chalk.yellow(' 🔐 Authentication issue detected:'));
|
|
66
|
+
console.error(chalk.white(' • Run `berget auth login` to log in'));
|
|
67
|
+
console.error(chalk.white(' • Check if your session has expired'));
|
|
68
|
+
console.error(chalk.white(' • Verify you have the correct permissions'));
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// Network/connection errors
|
|
@@ -71,11 +75,11 @@ function provideTroubleshootingTips(errorType: string, errorCode: string, errorD
|
|
|
71
75
|
errorDetails?.includes('ENOTFOUND') ||
|
|
72
76
|
errorDetails?.includes('network')
|
|
73
77
|
) {
|
|
74
|
-
console.error(chalk.yellow(' 🌐 Network issue detected:'))
|
|
75
|
-
console.error(chalk.white(' • Check your internet connection'))
|
|
76
|
-
console.error(chalk.white(' • Verify you can reach api.berget.ai'))
|
|
77
|
-
console.error(chalk.white(' • Try again in a few minutes'))
|
|
78
|
-
console.error(chalk.white(' • Check if any firewall is blocking the request'))
|
|
78
|
+
console.error(chalk.yellow(' 🌐 Network issue detected:'));
|
|
79
|
+
console.error(chalk.white(' • Check your internet connection'));
|
|
80
|
+
console.error(chalk.white(' • Verify you can reach api.berget.ai'));
|
|
81
|
+
console.error(chalk.white(' • Try again in a few minutes'));
|
|
82
|
+
console.error(chalk.white(' • Check if any firewall is blocking the request'));
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// API key errors
|
|
@@ -84,11 +88,13 @@ function provideTroubleshootingTips(errorType: string, errorCode: string, errorD
|
|
|
84
88
|
errorDetails?.includes('API key') ||
|
|
85
89
|
errorType === 'invalid_request_error'
|
|
86
90
|
) {
|
|
87
|
-
console.error(chalk.yellow(' 🔑 API key issue detected:'))
|
|
88
|
-
console.error(chalk.white(' • Run `berget api-keys list` to check your keys'))
|
|
89
|
-
console.error(
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
console.error(chalk.yellow(' 🔑 API key issue detected:'));
|
|
92
|
+
console.error(chalk.white(' • Run `berget api-keys list` to check your keys'));
|
|
93
|
+
console.error(
|
|
94
|
+
chalk.white(' • Create a new key with `berget api-keys create --name "My Key"`'),
|
|
95
|
+
);
|
|
96
|
+
console.error(chalk.white(' • Set a default key with `berget api-keys set-default <id>`'));
|
|
97
|
+
console.error(chalk.white(' • Check if your API key has expired'));
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
// Rate limiting
|
|
@@ -97,34 +103,31 @@ function provideTroubleshootingTips(errorType: string, errorCode: string, errorD
|
|
|
97
103
|
errorDetails?.includes('rate limit') ||
|
|
98
104
|
errorDetails?.includes('too many requests')
|
|
99
105
|
) {
|
|
100
|
-
console.error(chalk.yellow(' ⏱️ Rate limit exceeded:'))
|
|
101
|
-
console.error(chalk.white(' • Wait a few minutes before trying again'))
|
|
102
|
-
console.error(chalk.white(' • Consider upgrading your plan for higher limits'))
|
|
103
|
-
console.error(chalk.white(' • Use `berget billing get-usage` to check your usage'))
|
|
106
|
+
console.error(chalk.yellow(' ⏱️ Rate limit exceeded:'));
|
|
107
|
+
console.error(chalk.white(' • Wait a few minutes before trying again'));
|
|
108
|
+
console.error(chalk.white(' • Consider upgrading your plan for higher limits'));
|
|
109
|
+
console.error(chalk.white(' • Use `berget billing get-usage` to check your usage'));
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
// Server errors
|
|
107
113
|
if (
|
|
108
114
|
errorCode?.includes('SERVER_ERROR') ||
|
|
109
115
|
errorType === 'server_error' ||
|
|
110
|
-
(errorCode && parseInt(errorCode) >= 500)
|
|
116
|
+
(errorCode && Number.parseInt(errorCode) >= 500)
|
|
111
117
|
) {
|
|
112
|
-
console.error(chalk.yellow(' 🖥️ Server issue detected:'))
|
|
113
|
-
console.error(chalk.white(' • This is a temporary problem on our end'))
|
|
114
|
-
console.error(chalk.white(' • Try again in a few minutes'))
|
|
115
|
-
console.error(chalk.white(' • Check status.berget.ai for service status'))
|
|
116
|
-
console.error(chalk.white(' • Contact support if the problem persists'))
|
|
118
|
+
console.error(chalk.yellow(' 🖥️ Server issue detected:'));
|
|
119
|
+
console.error(chalk.white(' • This is a temporary problem on our end'));
|
|
120
|
+
console.error(chalk.white(' • Try again in a few minutes'));
|
|
121
|
+
console.error(chalk.white(' • Check status.berget.ai for service status'));
|
|
122
|
+
console.error(chalk.white(' • Contact support if the problem persists'));
|
|
117
123
|
}
|
|
118
124
|
|
|
119
125
|
// Cluster errors
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.error(chalk.
|
|
125
|
-
console.error(chalk.white(' • Clusters may be temporarily unavailable'))
|
|
126
|
-
console.error(chalk.white(' • Try again later or contact support'))
|
|
127
|
-
console.error(chalk.white(' • Check your cluster permissions'))
|
|
126
|
+
if (errorCode?.includes('CLUSTERS') || errorDetails?.includes('cluster')) {
|
|
127
|
+
console.error(chalk.yellow(' 🏗️ Cluster issue detected:'));
|
|
128
|
+
console.error(chalk.white(' • Clusters may be temporarily unavailable'));
|
|
129
|
+
console.error(chalk.white(' • Try again later or contact support'));
|
|
130
|
+
console.error(chalk.white(' • Check your cluster permissions'));
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
// Generic fallback
|
|
@@ -136,11 +139,13 @@ function provideTroubleshootingTips(errorType: string, errorCode: string, errorD
|
|
|
136
139
|
!errorCode?.includes('SERVER_ERROR') &&
|
|
137
140
|
!errorCode?.includes('CLUSTERS')
|
|
138
141
|
) {
|
|
139
|
-
console.error(chalk.yellow(' ❓ General issue:'))
|
|
140
|
-
console.error(chalk.white(' • Try running the command with --debug for more info'))
|
|
141
|
-
console.error(chalk.white(' • Check your configuration with `berget auth whoami`'))
|
|
142
|
-
console.error(chalk.white(' • Contact support if the problem persists'))
|
|
142
|
+
console.error(chalk.yellow(' ❓ General issue:'));
|
|
143
|
+
console.error(chalk.white(' • Try running the command with --debug for more info'));
|
|
144
|
+
console.error(chalk.white(' • Check your configuration with `berget auth whoami`'));
|
|
145
|
+
console.error(chalk.white(' • Contact support if the problem persists'));
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
console.error(
|
|
148
|
+
console.error(
|
|
149
|
+
chalk.dim('\nNeed more help? Visit https://docs.berget.ai or contact support@berget.ai'),
|
|
150
|
+
);
|
|
146
151
|
}
|
package/src/utils/logger.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Log levels in order of increasing verbosity
|
|
@@ -15,145 +15,151 @@ export enum LogLevel {
|
|
|
15
15
|
* Logger class for centralized logging with configurable log levels
|
|
16
16
|
*/
|
|
17
17
|
export class Logger {
|
|
18
|
-
private static instance: Logger
|
|
19
|
-
private logLevel: LogLevel = LogLevel.INFO // Default log level
|
|
18
|
+
private static instance: Logger;
|
|
19
|
+
private logLevel: LogLevel = LogLevel.INFO; // Default log level
|
|
20
20
|
|
|
21
21
|
private constructor() {
|
|
22
22
|
// Set log level from environment variable or command line argument
|
|
23
23
|
if (process.env.LOG_LEVEL) {
|
|
24
|
-
this.setLogLevelFromString(process.env.LOG_LEVEL)
|
|
24
|
+
this.setLogLevelFromString(process.env.LOG_LEVEL);
|
|
25
25
|
} else if (process.argv.includes('--debug')) {
|
|
26
|
-
this.logLevel = LogLevel.DEBUG
|
|
26
|
+
this.logLevel = LogLevel.DEBUG;
|
|
27
27
|
} else if (process.argv.includes('--quiet')) {
|
|
28
|
-
this.logLevel = LogLevel.ERROR
|
|
28
|
+
this.logLevel = LogLevel.ERROR;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
public static getInstance(): Logger {
|
|
33
33
|
if (!Logger.instance) {
|
|
34
|
-
Logger.instance = new Logger()
|
|
34
|
+
Logger.instance = new Logger();
|
|
35
35
|
}
|
|
36
|
-
return Logger.instance
|
|
36
|
+
return Logger.instance;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Log a debug message (only shown at DEBUG level)
|
|
41
41
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
break
|
|
50
|
-
case 'warn':
|
|
51
|
-
this.logLevel = LogLevel.WARN
|
|
52
|
-
break
|
|
53
|
-
case 'info':
|
|
54
|
-
this.logLevel = LogLevel.INFO
|
|
55
|
-
break
|
|
56
|
-
case 'debug':
|
|
57
|
-
this.logLevel = LogLevel.DEBUG
|
|
58
|
-
break
|
|
59
|
-
default:
|
|
60
|
-
// Invalid log level, keep default
|
|
61
|
-
console.warn(`Invalid log level: ${level}. Using default (INFO).`)
|
|
42
|
+
public debug(message: string, ...arguments_: any[]): void {
|
|
43
|
+
if (this.logLevel >= LogLevel.DEBUG) {
|
|
44
|
+
if (arguments_.length > 0) {
|
|
45
|
+
console.log(chalk.yellow(`DEBUG: ${message}`), ...arguments_);
|
|
46
|
+
} else {
|
|
47
|
+
console.log(chalk.yellow(`DEBUG: ${message}`));
|
|
48
|
+
}
|
|
62
49
|
}
|
|
63
50
|
}
|
|
64
51
|
|
|
65
52
|
/**
|
|
66
|
-
*
|
|
53
|
+
* Log an error message (shown at ERROR level and above)
|
|
67
54
|
*/
|
|
68
|
-
public
|
|
69
|
-
this.logLevel
|
|
55
|
+
public error(message: string, ...arguments_: any[]): void {
|
|
56
|
+
if (this.logLevel >= LogLevel.ERROR) {
|
|
57
|
+
if (arguments_.length > 0) {
|
|
58
|
+
console.error(chalk.red(message), ...arguments_);
|
|
59
|
+
} else {
|
|
60
|
+
console.error(chalk.red(message));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
/**
|
|
73
66
|
* Get the current log level
|
|
74
67
|
*/
|
|
75
68
|
public getLogLevel(): LogLevel {
|
|
76
|
-
return this.logLevel
|
|
69
|
+
return this.logLevel;
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
/**
|
|
80
|
-
* Log
|
|
73
|
+
* Log an info message (shown at INFO level and above)
|
|
81
74
|
*/
|
|
82
|
-
public
|
|
83
|
-
if (this.logLevel >= LogLevel.
|
|
84
|
-
if (
|
|
85
|
-
console.log(chalk.
|
|
75
|
+
public info(message: string, ...arguments_: any[]): void {
|
|
76
|
+
if (this.logLevel >= LogLevel.INFO) {
|
|
77
|
+
if (arguments_.length > 0) {
|
|
78
|
+
console.log(chalk.blue(message), ...arguments_);
|
|
86
79
|
} else {
|
|
87
|
-
console.log(chalk.
|
|
80
|
+
console.log(chalk.blue(message));
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
/**
|
|
93
|
-
* Log
|
|
86
|
+
* Log a plain message without color (shown at INFO level and above)
|
|
94
87
|
*/
|
|
95
|
-
public
|
|
88
|
+
public log(message: string, ...arguments_: any[]): void {
|
|
96
89
|
if (this.logLevel >= LogLevel.INFO) {
|
|
97
|
-
if (
|
|
98
|
-
console.log(
|
|
90
|
+
if (arguments_.length > 0) {
|
|
91
|
+
console.log(message, ...arguments_);
|
|
99
92
|
} else {
|
|
100
|
-
console.log(
|
|
93
|
+
console.log(message);
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
}
|
|
104
97
|
|
|
105
98
|
/**
|
|
106
|
-
*
|
|
99
|
+
* Set the log level
|
|
107
100
|
*/
|
|
108
|
-
public
|
|
109
|
-
|
|
110
|
-
if (args.length > 0) {
|
|
111
|
-
console.log(chalk.yellow(message), ...args)
|
|
112
|
-
} else {
|
|
113
|
-
console.log(chalk.yellow(message))
|
|
114
|
-
}
|
|
115
|
-
}
|
|
101
|
+
public setLogLevel(level: LogLevel): void {
|
|
102
|
+
this.logLevel = level;
|
|
116
103
|
}
|
|
117
104
|
|
|
118
105
|
/**
|
|
119
|
-
* Log
|
|
106
|
+
* Log a success message (shown at INFO level and above)
|
|
120
107
|
*/
|
|
121
|
-
public
|
|
122
|
-
if (this.logLevel >= LogLevel.
|
|
123
|
-
if (
|
|
124
|
-
console.
|
|
108
|
+
public success(message: string, ...arguments_: any[]): void {
|
|
109
|
+
if (this.logLevel >= LogLevel.INFO) {
|
|
110
|
+
if (arguments_.length > 0) {
|
|
111
|
+
console.log(chalk.green(message), ...arguments_);
|
|
125
112
|
} else {
|
|
126
|
-
console.
|
|
113
|
+
console.log(chalk.green(message));
|
|
127
114
|
}
|
|
128
115
|
}
|
|
129
116
|
}
|
|
130
117
|
|
|
131
118
|
/**
|
|
132
|
-
* Log a
|
|
119
|
+
* Log a warning message (shown at WARN level and above)
|
|
133
120
|
*/
|
|
134
|
-
public
|
|
135
|
-
if (this.logLevel >= LogLevel.
|
|
136
|
-
if (
|
|
137
|
-
console.log(chalk.
|
|
121
|
+
public warn(message: string, ...arguments_: any[]): void {
|
|
122
|
+
if (this.logLevel >= LogLevel.WARN) {
|
|
123
|
+
if (arguments_.length > 0) {
|
|
124
|
+
console.log(chalk.yellow(message), ...arguments_);
|
|
138
125
|
} else {
|
|
139
|
-
console.log(chalk.
|
|
126
|
+
console.log(chalk.yellow(message));
|
|
140
127
|
}
|
|
141
128
|
}
|
|
142
129
|
}
|
|
143
130
|
|
|
144
131
|
/**
|
|
145
|
-
*
|
|
132
|
+
* Set the log level from a string
|
|
146
133
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
134
|
+
private setLogLevelFromString(level: string): void {
|
|
135
|
+
switch (level.toLowerCase()) {
|
|
136
|
+
case 'debug': {
|
|
137
|
+
this.logLevel = LogLevel.DEBUG;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'error': {
|
|
141
|
+
this.logLevel = LogLevel.ERROR;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'info': {
|
|
145
|
+
this.logLevel = LogLevel.INFO;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case 'none': {
|
|
149
|
+
this.logLevel = LogLevel.NONE;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'warn': {
|
|
153
|
+
this.logLevel = LogLevel.WARN;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default: {
|
|
157
|
+
// Invalid log level, keep default
|
|
158
|
+
console.warn(`Invalid log level: ${level}. Using default (INFO).`);
|
|
153
159
|
}
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
// Export a singleton instance for easy import
|
|
159
|
-
export const logger = Logger.getInstance()
|
|
165
|
+
export const logger = Logger.getInstance();
|
|
@@ -1,44 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { marked } from 'marked';
|
|
3
|
+
import TerminalRenderer from 'marked-terminal';
|
|
4
4
|
|
|
5
5
|
// Configure marked to use the terminal renderer
|
|
6
6
|
marked.setOptions({
|
|
7
7
|
renderer: new TerminalRenderer({
|
|
8
|
+
blockquote: chalk.gray.italic,
|
|
8
9
|
// Customize the rendering options
|
|
9
10
|
code: chalk.cyan,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
listitem: chalk.yellow,
|
|
13
|
-
strong: chalk.bold,
|
|
11
|
+
// Customize code block rendering
|
|
12
|
+
codespan: chalk.cyan,
|
|
14
13
|
em: chalk.italic,
|
|
15
14
|
heading: chalk.bold.blueBright,
|
|
16
15
|
hr: chalk.gray,
|
|
17
16
|
link: chalk.blue.underline,
|
|
17
|
+
listitem: chalk.yellow,
|
|
18
|
+
strong: chalk.bold,
|
|
19
|
+
table: chalk.white,
|
|
18
20
|
// Adjust the width to fit the terminal
|
|
19
21
|
width: process.stdout.columns || 80,
|
|
20
|
-
// Customize code block rendering
|
|
21
|
-
codespan: chalk.cyan,
|
|
22
22
|
}),
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Render markdown text to terminal-friendly formatted text
|
|
27
|
-
* @param markdown The markdown text to render
|
|
28
|
-
* @returns Formatted text for terminal display
|
|
29
|
-
*/
|
|
30
|
-
export function renderMarkdown(markdown: string): string {
|
|
31
|
-
if (!markdown) return ''
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
// Convert markdown to terminal-friendly text
|
|
35
|
-
return marked(markdown)
|
|
36
|
-
} catch (error) {
|
|
37
|
-
// If rendering fails, return the original text
|
|
38
|
-
console.error(`Error rendering markdown: ${error}`)
|
|
39
|
-
return markdown
|
|
40
|
-
}
|
|
41
|
-
}
|
|
23
|
+
});
|
|
42
24
|
|
|
43
25
|
/**
|
|
44
26
|
* Check if a string contains markdown formatting
|
|
@@ -46,7 +28,7 @@ export function renderMarkdown(markdown: string): string {
|
|
|
46
28
|
* @returns True if the text contains markdown formatting
|
|
47
29
|
*/
|
|
48
30
|
export function containsMarkdown(text: string): boolean {
|
|
49
|
-
if (!text) return false
|
|
31
|
+
if (!text) return false;
|
|
50
32
|
|
|
51
33
|
// Check for common markdown patterns
|
|
52
34
|
const markdownPatterns = [
|
|
@@ -62,7 +44,25 @@ export function containsMarkdown(text: string): boolean {
|
|
|
62
44
|
/\|.*\|.*\|/, // Tables
|
|
63
45
|
/^---+$/m, // Horizontal rules
|
|
64
46
|
/^===+$/m, // Alternative headers
|
|
65
|
-
]
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
return markdownPatterns.some((pattern) => pattern.test(text));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Render markdown text to terminal-friendly formatted text
|
|
54
|
+
* @param markdown The markdown text to render
|
|
55
|
+
* @returns Formatted text for terminal display
|
|
56
|
+
*/
|
|
57
|
+
export function renderMarkdown(markdown: string): string {
|
|
58
|
+
if (!markdown) return '';
|
|
66
59
|
|
|
67
|
-
|
|
60
|
+
try {
|
|
61
|
+
// Convert markdown to terminal-friendly text
|
|
62
|
+
return marked(markdown);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// If rendering fails, return the original text
|
|
65
|
+
console.error(`Error rendering markdown: ${error}`);
|
|
66
|
+
return markdown;
|
|
67
|
+
}
|
|
68
68
|
}
|