@juspay/yama 1.1.0 → 1.2.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.
- package/CHANGELOG.md +34 -1
- package/README.md +152 -120
- package/dist/cli/index.js +201 -200
- package/dist/core/ContextGatherer.d.ts +10 -5
- package/dist/core/ContextGatherer.js +176 -161
- package/dist/core/Guardian.d.ts +1 -1
- package/dist/core/Guardian.js +126 -122
- package/dist/core/providers/BitbucketProvider.d.ts +3 -3
- package/dist/core/providers/BitbucketProvider.js +129 -121
- package/dist/features/CodeReviewer.d.ts +7 -3
- package/dist/features/CodeReviewer.js +314 -222
- package/dist/features/DescriptionEnhancer.d.ts +3 -3
- package/dist/features/DescriptionEnhancer.js +115 -94
- package/dist/index.d.ts +11 -11
- package/dist/index.js +10 -48
- package/dist/types/index.d.ts +27 -21
- package/dist/types/index.js +13 -18
- package/dist/utils/Cache.d.ts +6 -1
- package/dist/utils/Cache.js +78 -68
- package/dist/utils/ConfigManager.d.ts +5 -1
- package/dist/utils/ConfigManager.js +301 -253
- package/dist/utils/Logger.d.ts +2 -2
- package/dist/utils/Logger.js +69 -67
- package/dist/utils/MemoryBankManager.d.ts +73 -0
- package/dist/utils/MemoryBankManager.js +310 -0
- package/dist/utils/ProviderLimits.d.ts +58 -0
- package/dist/utils/ProviderLimits.js +143 -0
- package/package.json +7 -6
- package/yama.config.example.yaml +37 -21
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Consolidates all interfaces and types used across the application
|
|
4
4
|
*/
|
|
5
5
|
export interface AIProviderConfig {
|
|
6
|
-
provider?:
|
|
6
|
+
provider?: "auto" | "google-ai" | "openai" | "anthropic" | "azure" | "bedrock";
|
|
7
7
|
model?: string;
|
|
8
8
|
enableFallback?: boolean;
|
|
9
9
|
enableAnalytics?: boolean;
|
|
@@ -47,7 +47,7 @@ export interface EvaluationData {
|
|
|
47
47
|
};
|
|
48
48
|
confidence: number;
|
|
49
49
|
}
|
|
50
|
-
export type GitPlatform =
|
|
50
|
+
export type GitPlatform = "bitbucket" | "github" | "gitlab" | "azure-devops";
|
|
51
51
|
export interface GitCredentials {
|
|
52
52
|
username: string;
|
|
53
53
|
token: string;
|
|
@@ -69,7 +69,7 @@ export interface PRInfo {
|
|
|
69
69
|
title: string;
|
|
70
70
|
description: string;
|
|
71
71
|
author: string;
|
|
72
|
-
state:
|
|
72
|
+
state: "OPEN" | "MERGED" | "DECLINED" | "CLOSED";
|
|
73
73
|
sourceRef: string;
|
|
74
74
|
targetRef: string;
|
|
75
75
|
createdDate: string;
|
|
@@ -85,7 +85,7 @@ export interface PRReviewer {
|
|
|
85
85
|
displayName: string;
|
|
86
86
|
};
|
|
87
87
|
approved: boolean;
|
|
88
|
-
status:
|
|
88
|
+
status: "APPROVED" | "UNAPPROVED" | "NEEDS_WORK";
|
|
89
89
|
}
|
|
90
90
|
export interface PRComment {
|
|
91
91
|
id: number;
|
|
@@ -100,7 +100,7 @@ export interface PRComment {
|
|
|
100
100
|
filePath: string;
|
|
101
101
|
lineFrom: number;
|
|
102
102
|
lineTo: number;
|
|
103
|
-
lineType:
|
|
103
|
+
lineType: "ADDED" | "REMOVED" | "CONTEXT";
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
export interface PRDiff {
|
|
@@ -111,7 +111,7 @@ export interface PRDiff {
|
|
|
111
111
|
}
|
|
112
112
|
export interface FileChange {
|
|
113
113
|
path: string;
|
|
114
|
-
changeType:
|
|
114
|
+
changeType: "ADDED" | "MODIFIED" | "DELETED" | "RENAMED";
|
|
115
115
|
additions: number;
|
|
116
116
|
deletions: number;
|
|
117
117
|
hunks: DiffHunk[];
|
|
@@ -124,14 +124,14 @@ export interface DiffHunk {
|
|
|
124
124
|
lines: DiffLine[];
|
|
125
125
|
}
|
|
126
126
|
export interface DiffLine {
|
|
127
|
-
type:
|
|
127
|
+
type: "added" | "removed" | "context";
|
|
128
128
|
content: string;
|
|
129
129
|
oldLineNumber?: number;
|
|
130
130
|
newLineNumber?: number;
|
|
131
131
|
}
|
|
132
|
-
export type ViolationSeverity =
|
|
133
|
-
export type ViolationType =
|
|
134
|
-
export type ViolationCategory =
|
|
132
|
+
export type ViolationSeverity = "CRITICAL" | "MAJOR" | "MINOR" | "SUGGESTION";
|
|
133
|
+
export type ViolationType = "inline" | "general";
|
|
134
|
+
export type ViolationCategory = "security" | "performance" | "maintainability" | "functionality" | "error_handling" | "testing" | "general";
|
|
135
135
|
export interface Violation {
|
|
136
136
|
type: ViolationType;
|
|
137
137
|
file?: string;
|
|
@@ -140,7 +140,7 @@ export interface Violation {
|
|
|
140
140
|
before: string[];
|
|
141
141
|
after: string[];
|
|
142
142
|
};
|
|
143
|
-
line_type?:
|
|
143
|
+
line_type?: "ADDED" | "REMOVED" | "CONTEXT";
|
|
144
144
|
severity: ViolationSeverity;
|
|
145
145
|
category: ViolationCategory;
|
|
146
146
|
issue: string;
|
|
@@ -233,6 +233,7 @@ export interface GuardianConfig {
|
|
|
233
233
|
securityScan?: SecurityScanConfig;
|
|
234
234
|
analytics?: AnalyticsConfig;
|
|
235
235
|
};
|
|
236
|
+
memoryBank?: MemoryBankConfig;
|
|
236
237
|
cache?: CacheConfig;
|
|
237
238
|
performance?: PerformanceConfig;
|
|
238
239
|
rules?: CustomRulesConfig;
|
|
@@ -265,23 +266,28 @@ export interface DiffStrategyConfig {
|
|
|
265
266
|
wholeDiffMaxFiles: number;
|
|
266
267
|
fileByFileMinFiles: number;
|
|
267
268
|
};
|
|
268
|
-
forceStrategy?:
|
|
269
|
+
forceStrategy?: "whole" | "file-by-file" | "auto";
|
|
269
270
|
}
|
|
270
271
|
export interface SecurityScanConfig {
|
|
271
272
|
enabled: boolean;
|
|
272
|
-
level:
|
|
273
|
+
level: "strict" | "moderate" | "basic";
|
|
273
274
|
scanTypes: string[];
|
|
274
275
|
}
|
|
275
276
|
export interface AnalyticsConfig {
|
|
276
277
|
enabled: boolean;
|
|
277
278
|
trackMetrics: boolean;
|
|
278
|
-
exportFormat:
|
|
279
|
+
exportFormat: "json" | "csv" | "yaml";
|
|
280
|
+
}
|
|
281
|
+
export interface MemoryBankConfig {
|
|
282
|
+
enabled: boolean;
|
|
283
|
+
path: string;
|
|
284
|
+
fallbackPaths?: string[];
|
|
279
285
|
}
|
|
280
286
|
export interface CacheConfig {
|
|
281
287
|
enabled: boolean;
|
|
282
288
|
ttl: string;
|
|
283
289
|
maxSize: string;
|
|
284
|
-
storage:
|
|
290
|
+
storage: "memory" | "redis" | "file";
|
|
285
291
|
}
|
|
286
292
|
export interface PerformanceConfig {
|
|
287
293
|
batch: {
|
|
@@ -314,11 +320,11 @@ export interface ReportingConfig {
|
|
|
314
320
|
export interface MonitoringConfig {
|
|
315
321
|
enabled: boolean;
|
|
316
322
|
metrics: string[];
|
|
317
|
-
exportFormat?:
|
|
323
|
+
exportFormat?: "json" | "prometheus" | "csv";
|
|
318
324
|
endpoint?: string;
|
|
319
325
|
interval?: string;
|
|
320
326
|
}
|
|
321
|
-
export type OperationType =
|
|
327
|
+
export type OperationType = "review" | "enhance-description" | "security-scan" | "analytics" | "all";
|
|
322
328
|
export interface OperationOptions {
|
|
323
329
|
workspace: string;
|
|
324
330
|
repository: string;
|
|
@@ -331,7 +337,7 @@ export interface OperationOptions {
|
|
|
331
337
|
}
|
|
332
338
|
export interface OperationResult {
|
|
333
339
|
operation: OperationType;
|
|
334
|
-
status:
|
|
340
|
+
status: "success" | "error" | "skipped";
|
|
335
341
|
data?: any;
|
|
336
342
|
error?: string;
|
|
337
343
|
duration: number;
|
|
@@ -350,7 +356,7 @@ export interface ProcessResult {
|
|
|
350
356
|
}
|
|
351
357
|
export interface StreamUpdate {
|
|
352
358
|
operation: OperationType;
|
|
353
|
-
status:
|
|
359
|
+
status: "started" | "progress" | "completed" | "error";
|
|
354
360
|
progress?: number;
|
|
355
361
|
message?: string;
|
|
356
362
|
data?: any;
|
|
@@ -361,11 +367,11 @@ export interface StreamOptions {
|
|
|
361
367
|
onError?: (error: Error) => void;
|
|
362
368
|
onComplete?: (result: ProcessResult) => void;
|
|
363
369
|
}
|
|
364
|
-
export type LogLevel =
|
|
370
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
365
371
|
export interface LoggerOptions {
|
|
366
372
|
level: LogLevel;
|
|
367
373
|
verbose: boolean;
|
|
368
|
-
format:
|
|
374
|
+
format: "simple" | "json" | "detailed";
|
|
369
375
|
colors: boolean;
|
|
370
376
|
}
|
|
371
377
|
export interface Logger {
|
package/dist/types/index.js
CHANGED
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Core TypeScript types for Yama
|
|
4
3
|
* Consolidates all interfaces and types used across the application
|
|
5
4
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ValidationError = exports.ProviderError = exports.ConfigurationError = exports.GuardianError = void 0;
|
|
8
5
|
// ============================================================================
|
|
9
6
|
// Error Types
|
|
10
7
|
// ============================================================================
|
|
11
|
-
class GuardianError extends Error {
|
|
8
|
+
export class GuardianError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
context;
|
|
12
11
|
constructor(code, message, context) {
|
|
13
12
|
super(message);
|
|
14
13
|
this.code = code;
|
|
15
14
|
this.context = context;
|
|
16
|
-
this.name =
|
|
15
|
+
this.name = "GuardianError";
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
class ConfigurationError extends GuardianError {
|
|
18
|
+
export class ConfigurationError extends GuardianError {
|
|
21
19
|
constructor(message, context) {
|
|
22
|
-
super(
|
|
23
|
-
this.name =
|
|
20
|
+
super("CONFIGURATION_ERROR", message, context);
|
|
21
|
+
this.name = "ConfigurationError";
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
class ProviderError extends GuardianError {
|
|
24
|
+
export class ProviderError extends GuardianError {
|
|
28
25
|
constructor(message, context) {
|
|
29
|
-
super(
|
|
30
|
-
this.name =
|
|
26
|
+
super("PROVIDER_ERROR", message, context);
|
|
27
|
+
this.name = "ProviderError";
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
class ValidationError extends GuardianError {
|
|
30
|
+
export class ValidationError extends GuardianError {
|
|
35
31
|
constructor(message, context) {
|
|
36
|
-
super(
|
|
37
|
-
this.name =
|
|
32
|
+
super("VALIDATION_ERROR", message, context);
|
|
33
|
+
this.name = "ValidationError";
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
|
-
exports.ValidationError = ValidationError;
|
|
41
36
|
// ============================================================================
|
|
42
37
|
// Export all types - Main file, no re-exports needed
|
|
43
38
|
// ============================================================================
|
package/dist/utils/Cache.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Enhanced Cache utility for Yama
|
|
3
3
|
* Provides intelligent caching for PR data, file contents, and AI responses
|
|
4
4
|
*/
|
|
5
|
-
import { Cache as ICache, CacheOptions } from
|
|
5
|
+
import { Cache as ICache, CacheOptions } from "../types/index.js";
|
|
6
6
|
export declare class Cache implements ICache {
|
|
7
7
|
private cache;
|
|
8
8
|
private statsData;
|
|
@@ -57,6 +57,10 @@ export declare class Cache implements ICache {
|
|
|
57
57
|
* Invalidate all keys with a specific tag
|
|
58
58
|
*/
|
|
59
59
|
invalidateTag(tag: string): number;
|
|
60
|
+
/**
|
|
61
|
+
* Invalidate all keys matching a pattern
|
|
62
|
+
*/
|
|
63
|
+
invalidatePattern(pattern: string): number;
|
|
60
64
|
/**
|
|
61
65
|
* Cache key generators for common patterns
|
|
62
66
|
*/
|
|
@@ -69,6 +73,7 @@ export declare class Cache implements ICache {
|
|
|
69
73
|
aiResponse: (prompt: string, provider: string, model: string) => string;
|
|
70
74
|
projectContext: (workspace: string, repository: string, branch: string) => string;
|
|
71
75
|
reviewResult: (workspace: string, repository: string, prId: string | number, configHash: string) => string;
|
|
76
|
+
memoryBankFiles: (workspace: string, repository: string, branch: string, path: string) => string;
|
|
72
77
|
};
|
|
73
78
|
/**
|
|
74
79
|
* Smart cache warming for common patterns
|
package/dist/utils/Cache.js
CHANGED
|
@@ -1,45 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Enhanced Cache utility for Yama
|
|
4
3
|
* Provides intelligent caching for PR data, file contents, and AI responses
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Cache {
|
|
5
|
+
import NodeCache from "node-cache";
|
|
6
|
+
import { logger } from "./Logger.js";
|
|
7
|
+
export class Cache {
|
|
8
|
+
cache;
|
|
9
|
+
statsData = {
|
|
10
|
+
hits: 0,
|
|
11
|
+
misses: 0,
|
|
12
|
+
};
|
|
15
13
|
constructor(options = {}) {
|
|
16
|
-
this.statsData = {
|
|
17
|
-
hits: 0,
|
|
18
|
-
misses: 0
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Cache with tags for group invalidation
|
|
22
|
-
*/
|
|
23
|
-
this.tags = new Map();
|
|
24
14
|
const { ttl = 3600, // 1 hour default
|
|
25
15
|
maxSize = 100, // 100 keys max
|
|
26
|
-
checkPeriod = 600 // Check every 10 minutes
|
|
16
|
+
checkPeriod = 600, // Check every 10 minutes
|
|
27
17
|
} = options;
|
|
28
|
-
this.cache = new
|
|
18
|
+
this.cache = new NodeCache({
|
|
29
19
|
stdTTL: ttl,
|
|
30
20
|
maxKeys: maxSize,
|
|
31
21
|
checkperiod: checkPeriod,
|
|
32
22
|
useClones: false,
|
|
33
|
-
deleteOnExpire: true
|
|
23
|
+
deleteOnExpire: true,
|
|
34
24
|
});
|
|
35
|
-
this.cache.on(
|
|
36
|
-
|
|
25
|
+
this.cache.on("set", (key, _value) => {
|
|
26
|
+
logger.debug(`Cache SET: ${key}`);
|
|
37
27
|
});
|
|
38
|
-
this.cache.on(
|
|
39
|
-
|
|
28
|
+
this.cache.on("expired", (key, _value) => {
|
|
29
|
+
logger.debug(`Cache EXPIRED: ${key}`);
|
|
40
30
|
});
|
|
41
|
-
this.cache.on(
|
|
42
|
-
|
|
31
|
+
this.cache.on("del", (key, _value) => {
|
|
32
|
+
logger.debug(`Cache DELETE: ${key}`);
|
|
43
33
|
});
|
|
44
34
|
}
|
|
45
35
|
/**
|
|
@@ -49,12 +39,12 @@ class Cache {
|
|
|
49
39
|
const value = this.cache.get(key);
|
|
50
40
|
if (value !== undefined) {
|
|
51
41
|
this.statsData.hits++;
|
|
52
|
-
|
|
42
|
+
logger.debug(`Cache HIT: ${key}`);
|
|
53
43
|
return value;
|
|
54
44
|
}
|
|
55
45
|
else {
|
|
56
46
|
this.statsData.misses++;
|
|
57
|
-
|
|
47
|
+
logger.debug(`Cache MISS: ${key}`);
|
|
58
48
|
return undefined;
|
|
59
49
|
}
|
|
60
50
|
}
|
|
@@ -65,15 +55,15 @@ class Cache {
|
|
|
65
55
|
try {
|
|
66
56
|
const success = this.cache.set(key, value, ttl || 0);
|
|
67
57
|
if (success) {
|
|
68
|
-
|
|
58
|
+
logger.debug(`Cache SET successful: ${key}`);
|
|
69
59
|
}
|
|
70
60
|
else {
|
|
71
|
-
|
|
61
|
+
logger.warn(`Cache SET failed: ${key}`);
|
|
72
62
|
}
|
|
73
63
|
return success;
|
|
74
64
|
}
|
|
75
65
|
catch (error) {
|
|
76
|
-
|
|
66
|
+
logger.error(`Cache SET error: ${key}`, error);
|
|
77
67
|
return false;
|
|
78
68
|
}
|
|
79
69
|
}
|
|
@@ -82,7 +72,7 @@ class Cache {
|
|
|
82
72
|
*/
|
|
83
73
|
del(key) {
|
|
84
74
|
const deleted = this.cache.del(key);
|
|
85
|
-
|
|
75
|
+
logger.debug(`Cache DELETE: ${key}, deleted: ${deleted}`);
|
|
86
76
|
return deleted;
|
|
87
77
|
}
|
|
88
78
|
/**
|
|
@@ -98,7 +88,7 @@ class Cache {
|
|
|
98
88
|
this.cache.flushAll();
|
|
99
89
|
this.statsData.hits = 0;
|
|
100
90
|
this.statsData.misses = 0;
|
|
101
|
-
|
|
91
|
+
logger.debug("Cache cleared");
|
|
102
92
|
}
|
|
103
93
|
/**
|
|
104
94
|
* Get all cache keys
|
|
@@ -114,7 +104,7 @@ class Cache {
|
|
|
114
104
|
hits: this.statsData.hits,
|
|
115
105
|
misses: this.statsData.misses,
|
|
116
106
|
keys: this.cache.keys().length,
|
|
117
|
-
size: this.cache.getStats().keys
|
|
107
|
+
size: this.cache.getStats().keys,
|
|
118
108
|
};
|
|
119
109
|
}
|
|
120
110
|
/**
|
|
@@ -132,21 +122,25 @@ class Cache {
|
|
|
132
122
|
return cached;
|
|
133
123
|
}
|
|
134
124
|
try {
|
|
135
|
-
|
|
125
|
+
logger.debug(`Cache FETCH: ${key}`);
|
|
136
126
|
const value = await fetchFn();
|
|
137
127
|
this.set(key, value, ttl);
|
|
138
128
|
return value;
|
|
139
129
|
}
|
|
140
130
|
catch (error) {
|
|
141
|
-
|
|
131
|
+
logger.error(`Cache FETCH error: ${key}`, error);
|
|
142
132
|
throw error;
|
|
143
133
|
}
|
|
144
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Cache with tags for group invalidation
|
|
137
|
+
*/
|
|
138
|
+
tags = new Map();
|
|
145
139
|
setWithTags(key, value, tags, ttl) {
|
|
146
140
|
const success = this.set(key, value, ttl);
|
|
147
141
|
if (success) {
|
|
148
142
|
// Associate key with tags
|
|
149
|
-
tags.forEach(tag => {
|
|
143
|
+
tags.forEach((tag) => {
|
|
150
144
|
if (!this.tags.has(tag)) {
|
|
151
145
|
this.tags.set(tag, new Set());
|
|
152
146
|
}
|
|
@@ -160,29 +154,63 @@ class Cache {
|
|
|
160
154
|
*/
|
|
161
155
|
invalidateTag(tag) {
|
|
162
156
|
const keys = this.tags.get(tag);
|
|
163
|
-
if (!keys)
|
|
157
|
+
if (!keys) {
|
|
164
158
|
return 0;
|
|
159
|
+
}
|
|
165
160
|
let deleted = 0;
|
|
166
|
-
keys.forEach(key => {
|
|
161
|
+
keys.forEach((key) => {
|
|
167
162
|
deleted += this.del(key);
|
|
168
163
|
});
|
|
169
164
|
// Clean up tag associations
|
|
170
165
|
this.tags.delete(tag);
|
|
171
|
-
|
|
166
|
+
logger.debug(`Invalidated tag "${tag}": ${deleted} keys`);
|
|
172
167
|
return deleted;
|
|
173
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Invalidate all keys matching a pattern
|
|
171
|
+
*/
|
|
172
|
+
invalidatePattern(pattern) {
|
|
173
|
+
const regex = new RegExp(pattern.replace(/\*/g, ".*"));
|
|
174
|
+
const allKeys = this.keys();
|
|
175
|
+
let deleted = 0;
|
|
176
|
+
allKeys.forEach((key) => {
|
|
177
|
+
if (regex.test(key)) {
|
|
178
|
+
deleted += this.del(key);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
logger.debug(`Invalidated pattern "${pattern}": ${deleted} keys`);
|
|
182
|
+
return deleted;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Cache key generators for common patterns
|
|
186
|
+
*/
|
|
187
|
+
static keys = {
|
|
188
|
+
prInfo: (workspace, repository, prId) => `pr:${workspace}:${repository}:${prId}`,
|
|
189
|
+
prDiff: (workspace, repository, prId) => `diff:${workspace}:${repository}:${prId}`,
|
|
190
|
+
fileContent: (workspace, repository, filePath, branch) => `file:${workspace}:${repository}:${branch}:${filePath}`,
|
|
191
|
+
directoryContent: (workspace, repository, path, branch) => `dir:${workspace}:${repository}:${branch}:${path}`,
|
|
192
|
+
branchInfo: (workspace, repository, branch) => `branch:${workspace}:${repository}:${branch}`,
|
|
193
|
+
aiResponse: (prompt, provider, model) => {
|
|
194
|
+
// Create a hash of the prompt for consistent keys
|
|
195
|
+
const hash = Buffer.from(prompt).toString("base64").slice(0, 16);
|
|
196
|
+
return `ai:${provider}:${model}:${hash}`;
|
|
197
|
+
},
|
|
198
|
+
projectContext: (workspace, repository, branch) => `context:${workspace}:${repository}:${branch}`,
|
|
199
|
+
reviewResult: (workspace, repository, prId, configHash) => `review:${workspace}:${repository}:${prId}:${configHash}`,
|
|
200
|
+
memoryBankFiles: (workspace, repository, branch, path) => `memory-bank:${workspace}:${repository}:${branch}:${path}`,
|
|
201
|
+
};
|
|
174
202
|
/**
|
|
175
203
|
* Smart cache warming for common patterns
|
|
176
204
|
*/
|
|
177
205
|
async warmPRCache(workspace, repository, prId) {
|
|
178
|
-
|
|
206
|
+
logger.debug(`Warming cache for PR ${workspace}/${repository}#${prId}`);
|
|
179
207
|
// Pre-generate cache keys that are likely to be needed
|
|
180
208
|
const keys = [
|
|
181
209
|
Cache.keys.prInfo(workspace, repository, prId),
|
|
182
|
-
Cache.keys.prDiff(workspace, repository, prId)
|
|
210
|
+
Cache.keys.prDiff(workspace, repository, prId),
|
|
183
211
|
];
|
|
184
212
|
// This would be implemented by the calling code to actually fetch the data
|
|
185
|
-
|
|
213
|
+
logger.debug(`Cache warming prepared for keys: ${keys.join(", ")}`);
|
|
186
214
|
}
|
|
187
215
|
/**
|
|
188
216
|
* Cleanup expired entries and optimize memory
|
|
@@ -191,17 +219,17 @@ class Cache {
|
|
|
191
219
|
// Node-cache handles TTL cleanup automatically, but we can force it
|
|
192
220
|
const beforeKeys = this.cache.keys().length;
|
|
193
221
|
// Force check for expired keys
|
|
194
|
-
this.cache.keys().forEach(key => {
|
|
222
|
+
this.cache.keys().forEach((key) => {
|
|
195
223
|
this.cache.get(key); // This triggers expiry check
|
|
196
224
|
});
|
|
197
225
|
const afterKeys = this.cache.keys().length;
|
|
198
226
|
const cleaned = beforeKeys - afterKeys;
|
|
199
227
|
if (cleaned > 0) {
|
|
200
|
-
|
|
228
|
+
logger.debug(`Cache cleanup: removed ${cleaned} expired entries`);
|
|
201
229
|
}
|
|
202
230
|
// Clean up tag associations for deleted keys
|
|
203
231
|
this.tags.forEach((keys, tag) => {
|
|
204
|
-
const validKeys = new Set([...keys].filter(key => this.cache.has(key)));
|
|
232
|
+
const validKeys = new Set([...keys].filter((key) => this.cache.has(key)));
|
|
205
233
|
if (validKeys.size !== keys.size) {
|
|
206
234
|
this.tags.set(tag, validKeys);
|
|
207
235
|
}
|
|
@@ -223,32 +251,14 @@ class Cache {
|
|
|
223
251
|
hitRatio: this.getHitRatio(),
|
|
224
252
|
detailedStats: this.getDetailedStats(),
|
|
225
253
|
keys: this.keys(),
|
|
226
|
-
tags: Object.fromEntries(this.tags.entries())
|
|
254
|
+
tags: Object.fromEntries(this.tags.entries()),
|
|
227
255
|
};
|
|
228
256
|
}
|
|
229
257
|
}
|
|
230
|
-
exports.Cache = Cache;
|
|
231
|
-
/**
|
|
232
|
-
* Cache key generators for common patterns
|
|
233
|
-
*/
|
|
234
|
-
Cache.keys = {
|
|
235
|
-
prInfo: (workspace, repository, prId) => `pr:${workspace}:${repository}:${prId}`,
|
|
236
|
-
prDiff: (workspace, repository, prId) => `diff:${workspace}:${repository}:${prId}`,
|
|
237
|
-
fileContent: (workspace, repository, filePath, branch) => `file:${workspace}:${repository}:${branch}:${filePath}`,
|
|
238
|
-
directoryContent: (workspace, repository, path, branch) => `dir:${workspace}:${repository}:${branch}:${path}`,
|
|
239
|
-
branchInfo: (workspace, repository, branch) => `branch:${workspace}:${repository}:${branch}`,
|
|
240
|
-
aiResponse: (prompt, provider, model) => {
|
|
241
|
-
// Create a hash of the prompt for consistent keys
|
|
242
|
-
const hash = Buffer.from(prompt).toString('base64').slice(0, 16);
|
|
243
|
-
return `ai:${provider}:${model}:${hash}`;
|
|
244
|
-
},
|
|
245
|
-
projectContext: (workspace, repository, branch) => `context:${workspace}:${repository}:${branch}`,
|
|
246
|
-
reviewResult: (workspace, repository, prId, configHash) => `review:${workspace}:${repository}:${prId}:${configHash}`
|
|
247
|
-
};
|
|
248
258
|
// Export singleton instance
|
|
249
|
-
|
|
259
|
+
export const cache = new Cache();
|
|
250
260
|
// Export factory function
|
|
251
|
-
function createCache(options) {
|
|
261
|
+
export function createCache(options) {
|
|
252
262
|
return new Cache(options);
|
|
253
263
|
}
|
|
254
264
|
//# sourceMappingURL=Cache.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Enhanced Configuration Manager for Yama
|
|
3
3
|
* Handles configuration loading, validation, and merging from multiple sources
|
|
4
4
|
*/
|
|
5
|
-
import { GuardianConfig } from
|
|
5
|
+
import { GuardianConfig } from "../types/index.js";
|
|
6
6
|
export declare class ConfigManager {
|
|
7
7
|
private config;
|
|
8
8
|
private configPaths;
|
|
@@ -23,6 +23,10 @@ export declare class ConfigManager {
|
|
|
23
23
|
* Load configuration from a specific file
|
|
24
24
|
*/
|
|
25
25
|
private loadConfigFile;
|
|
26
|
+
/**
|
|
27
|
+
* Apply provider-aware token limits using shared utility
|
|
28
|
+
*/
|
|
29
|
+
private applyProviderTokenLimits;
|
|
26
30
|
/**
|
|
27
31
|
* Apply environment variable overrides
|
|
28
32
|
*/
|