@juspay/yama 1.1.0

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.
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ /**
3
+ * Enhanced Logger utility - Optimized from both pr-police.js and pr-describe.js
4
+ * Provides consistent logging across all Guardian operations
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.logger = exports.Logger = void 0;
11
+ exports.createLogger = createLogger;
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const YAMA_BADGE = `
14
+ ⚔️ ═══════════════════════════════════════════════════════════ ⚔️
15
+ ██╗ ██╗ █████╗ ███╗ ███╗ █████╗
16
+ ╚██╗ ██╔╝██╔══██╗████╗ ████║██╔══██╗
17
+ ╚████╔╝ ███████║██╔████╔██║███████║
18
+ ╚██╔╝ ██╔══██║██║╚██╔╝██║██╔══██║
19
+ ██║ ██║ ██║██║ ╚═╝ ██║██║ ██║
20
+ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝
21
+ ⚔️ ═══════════════════════════════════════════════════════════ ⚔️
22
+ AI-Powered PR Automation • Enterprise Security • Code Quality Yama
23
+ `;
24
+ class Logger {
25
+ constructor(options = {}) {
26
+ this.options = {
27
+ level: 'info',
28
+ verbose: false,
29
+ format: 'simple',
30
+ colors: true,
31
+ ...options
32
+ };
33
+ }
34
+ shouldLog(level) {
35
+ const levels = {
36
+ debug: 0,
37
+ info: 1,
38
+ warn: 2,
39
+ error: 3
40
+ };
41
+ return levels[level] >= levels[this.options.level];
42
+ }
43
+ formatMessage(level, message, ...args) {
44
+ const timestamp = new Date().toISOString();
45
+ const formattedArgs = args.length > 0 ? ` ${args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')}` : '';
46
+ switch (this.options.format) {
47
+ case 'json':
48
+ return JSON.stringify({
49
+ timestamp,
50
+ level: level.toUpperCase(),
51
+ message: message + formattedArgs,
52
+ args: args.length > 0 ? args : undefined
53
+ });
54
+ case 'detailed':
55
+ return `[${timestamp}] [${level.toUpperCase().padEnd(5)}] ${message}${formattedArgs}`;
56
+ default: // simple
57
+ return `${message}${formattedArgs}`;
58
+ }
59
+ }
60
+ colorize(level, text) {
61
+ if (!this.options.colors)
62
+ return text;
63
+ switch (level) {
64
+ case 'debug':
65
+ return chalk_1.default.gray(text);
66
+ case 'info':
67
+ return chalk_1.default.blue(text);
68
+ case 'warn':
69
+ return chalk_1.default.yellow(text);
70
+ case 'error':
71
+ return chalk_1.default.red(text);
72
+ default:
73
+ return text;
74
+ }
75
+ }
76
+ debug(message, ...args) {
77
+ if (!this.shouldLog('debug') || !this.options.verbose)
78
+ return;
79
+ const formatted = this.formatMessage('debug', `🔍 ${message}`, ...args);
80
+ console.log(this.colorize('debug', formatted));
81
+ }
82
+ info(message, ...args) {
83
+ if (!this.shouldLog('info'))
84
+ return;
85
+ const formatted = this.formatMessage('info', `ℹ️ ${message}`, ...args);
86
+ console.log(this.colorize('info', formatted));
87
+ }
88
+ warn(message, ...args) {
89
+ if (!this.shouldLog('warn'))
90
+ return;
91
+ const formatted = this.formatMessage('warn', `⚠️ ${message}`, ...args);
92
+ console.warn(this.colorize('warn', formatted));
93
+ }
94
+ error(message, ...args) {
95
+ if (!this.shouldLog('error'))
96
+ return;
97
+ const formatted = this.formatMessage('error', `❌ ${message}`, ...args);
98
+ console.error(this.colorize('error', formatted));
99
+ }
100
+ badge() {
101
+ console.log(chalk_1.default.cyan(YAMA_BADGE));
102
+ }
103
+ phase(message) {
104
+ const formatted = `\n🔄 ${message}`;
105
+ console.log(this.options.colors ? chalk_1.default.magenta(formatted) : formatted);
106
+ }
107
+ success(message) {
108
+ const formatted = `✅ ${message}`;
109
+ console.log(this.options.colors ? chalk_1.default.green(formatted) : formatted);
110
+ }
111
+ operation(operation, status) {
112
+ const emoji = status === 'started' ? '🚀' : status === 'completed' ? '✅' : '❌';
113
+ const color = status === 'started' ? 'blue' : status === 'completed' ? 'green' : 'red';
114
+ const message = `${emoji} ${operation.toUpperCase()}: ${status}`;
115
+ if (this.options.colors) {
116
+ console.log(chalk_1.default[color](message));
117
+ }
118
+ else {
119
+ console.log(message);
120
+ }
121
+ }
122
+ violation(severity, message, file) {
123
+ const emoji = {
124
+ 'CRITICAL': '🚨',
125
+ 'MAJOR': '⚠️',
126
+ 'MINOR': '📝',
127
+ 'SUGGESTION': '💡'
128
+ }[severity] || '📋';
129
+ const color = {
130
+ 'CRITICAL': 'red',
131
+ 'MAJOR': 'yellow',
132
+ 'MINOR': 'blue',
133
+ 'SUGGESTION': 'cyan'
134
+ }[severity] || 'white';
135
+ const location = file ? ` in ${file}` : '';
136
+ const formatted = `${emoji} ${severity}: ${message}${location}`;
137
+ if (this.options.colors) {
138
+ console.log(chalk_1.default[color](formatted));
139
+ }
140
+ else {
141
+ console.log(formatted);
142
+ }
143
+ }
144
+ progress(current, total, operation) {
145
+ const percentage = Math.round((current / total) * 100);
146
+ const progressBar = this.createProgressBar(percentage);
147
+ const message = `🔄 ${operation}: ${progressBar} ${current}/${total} (${percentage}%)`;
148
+ // Use carriage return to overwrite the line
149
+ process.stdout.write(`\r${message}`);
150
+ // Add newline when complete
151
+ if (current === total) {
152
+ process.stdout.write('\n');
153
+ }
154
+ }
155
+ createProgressBar(percentage) {
156
+ const width = 20;
157
+ const filled = Math.round((percentage / 100) * width);
158
+ const empty = width - filled;
159
+ if (this.options.colors) {
160
+ return chalk_1.default.green('█'.repeat(filled)) + chalk_1.default.gray('░'.repeat(empty));
161
+ }
162
+ else {
163
+ return '█'.repeat(filled) + '░'.repeat(empty);
164
+ }
165
+ }
166
+ // Method to create child logger with context
167
+ child(context) {
168
+ const childLogger = new Logger(this.options);
169
+ // Override methods to include context
170
+ const originalMethods = ['debug', 'info', 'warn', 'error'];
171
+ originalMethods.forEach(method => {
172
+ const original = childLogger[method].bind(childLogger);
173
+ childLogger[method] = (message, ...args) => {
174
+ const contextStr = Object.entries(context)
175
+ .map(([k, v]) => `${k}=${v}`)
176
+ .join(' ');
177
+ original(`[${contextStr}] ${message}`, ...args);
178
+ };
179
+ });
180
+ return childLogger;
181
+ }
182
+ // Method to update log level dynamically
183
+ setLevel(level) {
184
+ this.options.level = level;
185
+ }
186
+ // Method to toggle verbose mode
187
+ setVerbose(verbose) {
188
+ this.options.verbose = verbose;
189
+ }
190
+ // Method to get current configuration
191
+ getConfig() {
192
+ return { ...this.options };
193
+ }
194
+ }
195
+ exports.Logger = Logger;
196
+ // Export singleton instance for convenience with environment-aware defaults
197
+ const loggerOptions = {};
198
+ // Check environment variables for debug mode
199
+ if (process.env.YAMA_DEBUG === 'true') {
200
+ loggerOptions.level = 'debug';
201
+ loggerOptions.verbose = true;
202
+ }
203
+ exports.logger = new Logger(loggerOptions);
204
+ // Export factory function
205
+ function createLogger(options) {
206
+ return new Logger(options);
207
+ }
208
+ //# sourceMappingURL=Logger.js.map
package/package.json ADDED
@@ -0,0 +1,137 @@
1
+ {
2
+ "name": "@juspay/yama",
3
+ "version": "1.1.0",
4
+ "description": "Enterprise-grade Pull Request automation toolkit with AI-powered code review and description enhancement",
5
+ "keywords": [
6
+ "pr",
7
+ "pull-request",
8
+ "code-review",
9
+ "ai",
10
+ "automation",
11
+ "bitbucket",
12
+ "github",
13
+ "gitlab",
14
+ "security",
15
+ "quality"
16
+ ],
17
+ "homepage": "https://github.com/juspay/yama#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/juspay/yama/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+ssh://git@github.com/juspay/yama.git"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Juspay Technologies <support@juspay.in> (https://juspay.io)",
27
+ "type": "module",
28
+ "main": "dist/index.js",
29
+ "types": "dist/index.d.ts",
30
+ "bin": {
31
+ "yama": "dist/cli/index.js",
32
+ "pr-guardian": "dist/cli/index.js",
33
+ "pr-police": "dist/cli/index.js",
34
+ "pr-scribe": "dist/cli/index.js"
35
+ },
36
+ "directories": {
37
+ "test": "tests"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "!dist/**/*.test.*",
42
+ "!dist/**/*.spec.*",
43
+ "!dist/**/*.map",
44
+ "!dist/**/tests",
45
+ "!dist/**/test-*",
46
+ "README.md",
47
+ "CHANGELOG.md",
48
+ "LICENSE",
49
+ "yama.config.example.yaml"
50
+ ],
51
+ "scripts": {
52
+ "build": "tsc && tsc-alias",
53
+ "dev": "ts-node-dev --respawn --transpile-only src/cli/index.ts",
54
+ "test": "jest",
55
+ "lint": "eslint src/**/*.ts",
56
+ "type-check": "tsc --noEmit",
57
+ "format": "prettier --write .",
58
+ "format:check": "prettier --check .",
59
+ "docs": "typedoc src",
60
+ "clean": "rimraf dist",
61
+ "prepare": "npm run build",
62
+ "prepack": "npm run build && npm run test",
63
+ "changeset": "changeset",
64
+ "changeset:version": "changeset version && git add --all",
65
+ "release": "npm run build && npm run test && changeset publish",
66
+ "release:check": "npm run build && publint && size-limit",
67
+ "release:dry": "npm publish --dry-run",
68
+ "release:github": "npm publish --registry https://npm.pkg.github.com",
69
+ "version:check": "npm version --no-git-tag-version",
70
+ "pack:verify": "npm pack && tar -tzf *.tgz | head -20"
71
+ },
72
+ "dependencies": {
73
+ "@juspay/neurolink": "^5.1.0",
74
+ "@nexus2520/bitbucket-mcp-server": "^0.10.0",
75
+ "chalk": "^4.1.2",
76
+ "commander": "^11.0.0",
77
+ "debug": "^4.3.4",
78
+ "dotenv": "^16.3.0",
79
+ "fast-glob": "^3.3.1",
80
+ "inquirer": "^8.2.6",
81
+ "lodash": "^4.17.21",
82
+ "node-cache": "^5.1.2",
83
+ "ora": "^5.4.1",
84
+ "yaml": "^2.3.0"
85
+ },
86
+ "devDependencies": {
87
+ "@types/commander": "^2.12.5",
88
+ "@types/inquirer": "^9.0.8",
89
+ "@types/jest": "^29.0.0",
90
+ "@types/lodash": "^4.14.0",
91
+ "@types/node": "^20.0.0",
92
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
93
+ "@typescript-eslint/parser": "^6.0.0",
94
+ "eslint": "^8.0.0",
95
+ "jest": "^29.0.0",
96
+ "rimraf": "^5.0.0",
97
+ "ts-jest": "^29.0.0",
98
+ "ts-node": "^10.0.0",
99
+ "ts-node-dev": "^2.0.0",
100
+ "tsc-alias": "^1.8.0",
101
+ "typedoc": "^0.25.0",
102
+ "typescript": "^5.0.0",
103
+ "@changesets/changelog-github": "^0.5.1",
104
+ "@changesets/cli": "^2.26.2",
105
+ "@semantic-release/changelog": "^6.0.3",
106
+ "@semantic-release/commit-analyzer": "^13.0.0",
107
+ "@semantic-release/git": "^10.0.1",
108
+ "@semantic-release/github": "^11.0.0",
109
+ "@semantic-release/npm": "^12.0.1",
110
+ "@semantic-release/release-notes-generator": "^14.0.1",
111
+ "semantic-release": "^24.0.0",
112
+ "prettier": "^3.0.0",
113
+ "publint": "^0.3.0"
114
+ },
115
+ "peerDependencies": {
116
+ "typescript": ">=4.5.0"
117
+ },
118
+ "engines": {
119
+ "node": ">=18.0.0",
120
+ "npm": ">=8.0.0",
121
+ "pnpm": ">=8.0.0"
122
+ },
123
+ "os": [
124
+ "darwin",
125
+ "linux",
126
+ "win32"
127
+ ],
128
+ "publishConfig": {
129
+ "access": "public",
130
+ "registry": "https://registry.npmjs.org/"
131
+ },
132
+ "pnpm": {
133
+ "onlyBuiltDependencies": [
134
+ "esbuild"
135
+ ]
136
+ }
137
+ }
@@ -0,0 +1,136 @@
1
+ # Yama Configuration Example
2
+ # This file contains all available configuration options with explanations
3
+
4
+ # AI Provider Configuration
5
+ providers:
6
+ ai:
7
+ provider: "auto" # Options: auto, google-ai, openai, anthropic, azure, bedrock
8
+ model: "best" # Model name or "best" for auto-selection
9
+ temperature: 0.3 # Lower = more focused (0.0-1.0)
10
+ maxTokens: 2000000 # Maximum tokens for response
11
+ timeout: "15m" # Timeout for AI operations
12
+ enableAnalytics: true
13
+ enableEvaluation: false
14
+
15
+ # Git Platform Configuration
16
+ git:
17
+ platform: "bitbucket" # Options: bitbucket, github, gitlab, azure-devops
18
+ credentials:
19
+ username: "${BITBUCKET_USERNAME}" # Environment variable
20
+ token: "${BITBUCKET_TOKEN}" # Environment variable
21
+ baseUrl: "${BITBUCKET_BASE_URL}" # Your Bitbucket server URL
22
+
23
+ # Feature Configuration
24
+ features:
25
+ # Code Review Configuration
26
+ codeReview:
27
+ enabled: true
28
+ severityLevels: ["CRITICAL", "MAJOR", "MINOR", "SUGGESTION"]
29
+ categories: ["security", "performance", "maintainability", "functionality", "error_handling"]
30
+ excludePatterns:
31
+ - "*.lock"
32
+ - "*.svg"
33
+ - "*.png"
34
+ - "*.jpg"
35
+ - "*.gif"
36
+ - "*.min.js"
37
+ - "*.min.css"
38
+ - "dist/**"
39
+ - "build/**"
40
+ - "vendor/**"
41
+ contextLines: 3 # Lines of context around changes
42
+ focusAreas:
43
+ - "Security vulnerabilities"
44
+ - "Performance bottlenecks"
45
+ - "Error handling"
46
+ - "Code quality"
47
+
48
+ # Description Enhancement Configuration
49
+ descriptionEnhancement:
50
+ enabled: true
51
+ preserveContent: true # Always preserve existing content
52
+ autoFormat: true
53
+ requiredSections:
54
+ - key: "changelog"
55
+ name: "Changelog (Modules Modified)"
56
+ required: true
57
+ - key: "testcases"
58
+ name: "Test Cases (What to be tested)"
59
+ required: true
60
+ - key: "config_changes"
61
+ name: "CAC Config Or Service Config Changes"
62
+ required: true
63
+
64
+ # NEW: Diff Strategy Configuration
65
+ diffStrategy:
66
+ enabled: true
67
+ thresholds:
68
+ wholeDiffMaxFiles: 2 # Use whole diff for ≤2 files
69
+ fileByFileMinFiles: 3 # Use file-by-file for ≥3 files
70
+ # Optional: Force a specific strategy regardless of file count
71
+ # forceStrategy: "file-by-file" # Options: whole, file-by-file, auto
72
+
73
+ # Security Scan Configuration (Future)
74
+ securityScan:
75
+ enabled: false
76
+ level: "strict" # Options: strict, moderate, basic
77
+ scanTypes: ["dependencies", "secrets", "vulnerabilities"]
78
+
79
+ # Analytics Configuration (Future)
80
+ analytics:
81
+ enabled: false
82
+ trackMetrics: true
83
+ exportFormat: "json" # Options: json, csv, yaml
84
+
85
+ # Cache Configuration
86
+ cache:
87
+ enabled: true
88
+ ttl: "30m" # Time to live for cache entries
89
+ maxSize: "100MB"
90
+ storage: "memory" # Options: memory, redis, file
91
+
92
+ # Performance Configuration
93
+ performance:
94
+ batch:
95
+ enabled: true
96
+ maxConcurrent: 5 # Max concurrent API calls
97
+ delayBetween: "1s" # Delay between batches
98
+ optimization:
99
+ reuseConnections: true
100
+ compressRequests: false
101
+ enableHttp2: true
102
+
103
+ # Custom Rules Configuration
104
+ rules:
105
+ security:
106
+ - name: "No hardcoded secrets"
107
+ pattern: "(password|secret|key)\\s*=\\s*[\"'][^\"']+[\"']"
108
+ severity: "CRITICAL"
109
+ message: "Hardcoded secrets detected"
110
+ suggestion: "Use environment variables or secure configuration"
111
+
112
+ - name: "SQL injection prevention"
113
+ pattern: "query\\([^?]+\\+.*\\)"
114
+ severity: "CRITICAL"
115
+ message: "Potential SQL injection vulnerability"
116
+ suggestion: "Use parameterized queries"
117
+
118
+ performance:
119
+ - name: "Avoid N+1 queries"
120
+ pattern: "forEach.*await.*query"
121
+ severity: "MAJOR"
122
+ message: "Potential N+1 query pattern detected"
123
+ suggestion: "Consider batch loading or joins"
124
+
125
+ # Reporting Configuration
126
+ reporting:
127
+ formats: ["markdown", "json"]
128
+ includeAnalytics: true
129
+ includeMetrics: true
130
+
131
+ # Monitoring Configuration (Future)
132
+ monitoring:
133
+ enabled: false
134
+ metrics: ["api_calls", "cache_hits", "processing_time"]
135
+ exportFormat: "prometheus"
136
+ interval: "1m"