@juspay/yama 1.6.0 → 2.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.
Files changed (79) hide show
  1. package/.mcp-config.example.json +26 -0
  2. package/CHANGELOG.md +46 -0
  3. package/README.md +311 -685
  4. package/dist/cli/v2.cli.d.ts +13 -0
  5. package/dist/cli/v2.cli.js +359 -0
  6. package/dist/index.d.ts +12 -13
  7. package/dist/index.js +18 -19
  8. package/dist/v2/config/ConfigLoader.d.ts +50 -0
  9. package/dist/v2/config/ConfigLoader.js +205 -0
  10. package/dist/v2/config/DefaultConfig.d.ts +9 -0
  11. package/dist/v2/config/DefaultConfig.js +187 -0
  12. package/dist/v2/core/LearningOrchestrator.d.ts +65 -0
  13. package/dist/v2/core/LearningOrchestrator.js +499 -0
  14. package/dist/v2/core/MCPServerManager.d.ts +22 -0
  15. package/dist/v2/core/MCPServerManager.js +100 -0
  16. package/dist/v2/core/SessionManager.d.ts +72 -0
  17. package/dist/v2/core/SessionManager.js +200 -0
  18. package/dist/v2/core/YamaV2Orchestrator.d.ts +112 -0
  19. package/dist/v2/core/YamaV2Orchestrator.js +549 -0
  20. package/dist/v2/learning/FeedbackExtractor.d.ts +46 -0
  21. package/dist/v2/learning/FeedbackExtractor.js +237 -0
  22. package/dist/v2/learning/KnowledgeBaseManager.d.ts +91 -0
  23. package/dist/v2/learning/KnowledgeBaseManager.js +475 -0
  24. package/dist/v2/learning/types.d.ts +121 -0
  25. package/dist/v2/learning/types.js +15 -0
  26. package/dist/v2/prompts/EnhancementSystemPrompt.d.ts +8 -0
  27. package/dist/v2/prompts/EnhancementSystemPrompt.js +216 -0
  28. package/dist/v2/prompts/LangfusePromptManager.d.ts +48 -0
  29. package/dist/v2/prompts/LangfusePromptManager.js +144 -0
  30. package/dist/v2/prompts/LearningSystemPrompt.d.ts +11 -0
  31. package/dist/v2/prompts/LearningSystemPrompt.js +180 -0
  32. package/dist/v2/prompts/PromptBuilder.d.ts +45 -0
  33. package/dist/v2/prompts/PromptBuilder.js +257 -0
  34. package/dist/v2/prompts/ReviewSystemPrompt.d.ts +8 -0
  35. package/dist/v2/prompts/ReviewSystemPrompt.js +270 -0
  36. package/dist/v2/types/config.types.d.ts +141 -0
  37. package/dist/v2/types/config.types.js +5 -0
  38. package/dist/v2/types/mcp.types.d.ts +191 -0
  39. package/dist/v2/types/mcp.types.js +6 -0
  40. package/dist/v2/types/v2.types.d.ts +182 -0
  41. package/dist/v2/types/v2.types.js +42 -0
  42. package/dist/v2/utils/ObservabilityConfig.d.ts +22 -0
  43. package/dist/v2/utils/ObservabilityConfig.js +48 -0
  44. package/package.json +16 -10
  45. package/yama.config.example.yaml +259 -204
  46. package/dist/cli/index.d.ts +0 -12
  47. package/dist/cli/index.js +0 -538
  48. package/dist/core/ContextGatherer.d.ts +0 -110
  49. package/dist/core/ContextGatherer.js +0 -470
  50. package/dist/core/Guardian.d.ts +0 -81
  51. package/dist/core/Guardian.js +0 -480
  52. package/dist/core/providers/BitbucketProvider.d.ts +0 -105
  53. package/dist/core/providers/BitbucketProvider.js +0 -489
  54. package/dist/features/CodeReviewer.d.ts +0 -173
  55. package/dist/features/CodeReviewer.js +0 -1707
  56. package/dist/features/DescriptionEnhancer.d.ts +0 -70
  57. package/dist/features/DescriptionEnhancer.js +0 -511
  58. package/dist/features/MultiInstanceProcessor.d.ts +0 -74
  59. package/dist/features/MultiInstanceProcessor.js +0 -360
  60. package/dist/types/index.d.ts +0 -624
  61. package/dist/types/index.js +0 -104
  62. package/dist/utils/Cache.d.ts +0 -103
  63. package/dist/utils/Cache.js +0 -444
  64. package/dist/utils/ConfigManager.d.ts +0 -88
  65. package/dist/utils/ConfigManager.js +0 -602
  66. package/dist/utils/ContentSimilarityService.d.ts +0 -74
  67. package/dist/utils/ContentSimilarityService.js +0 -215
  68. package/dist/utils/ExactDuplicateRemover.d.ts +0 -77
  69. package/dist/utils/ExactDuplicateRemover.js +0 -361
  70. package/dist/utils/Logger.d.ts +0 -31
  71. package/dist/utils/Logger.js +0 -214
  72. package/dist/utils/MemoryBankManager.d.ts +0 -73
  73. package/dist/utils/MemoryBankManager.js +0 -310
  74. package/dist/utils/ParallelProcessing.d.ts +0 -140
  75. package/dist/utils/ParallelProcessing.js +0 -333
  76. package/dist/utils/ProviderLimits.d.ts +0 -58
  77. package/dist/utils/ProviderLimits.js +0 -143
  78. package/dist/utils/RetryManager.d.ts +0 -78
  79. package/dist/utils/RetryManager.js +0 -205
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Session Manager for Yama V2
3
+ * Tracks review sessions, tool calls, and maintains state
4
+ */
5
+ import { randomBytes } from "crypto";
6
+ export class SessionManager {
7
+ sessions = new Map();
8
+ maxSessions = 100;
9
+ /**
10
+ * Create a new review session
11
+ */
12
+ createSession(request) {
13
+ const sessionId = this.generateSessionId();
14
+ const session = {
15
+ sessionId,
16
+ request,
17
+ startTime: new Date(),
18
+ status: "running",
19
+ toolCalls: [],
20
+ metadata: {
21
+ yamaVersion: "2.0.0",
22
+ aiProvider: "auto",
23
+ aiModel: "unknown",
24
+ totalTokens: 0,
25
+ totalCost: 0,
26
+ cacheHitRatio: 0,
27
+ },
28
+ };
29
+ this.sessions.set(sessionId, session);
30
+ // Clean up old sessions if we exceed max
31
+ if (this.sessions.size > this.maxSessions) {
32
+ this.cleanupOldSessions();
33
+ }
34
+ return sessionId;
35
+ }
36
+ /**
37
+ * Get session by ID
38
+ */
39
+ getSession(sessionId) {
40
+ const session = this.sessions.get(sessionId);
41
+ if (!session) {
42
+ throw new Error(`Session not found: ${sessionId}`);
43
+ }
44
+ return session;
45
+ }
46
+ /**
47
+ * Record a tool call in the session
48
+ */
49
+ recordToolCall(sessionId, toolName, args, result, duration, error) {
50
+ const session = this.getSession(sessionId);
51
+ const toolCall = {
52
+ timestamp: new Date(),
53
+ toolName,
54
+ args,
55
+ result,
56
+ error,
57
+ duration,
58
+ };
59
+ session.toolCalls.push(toolCall);
60
+ }
61
+ /**
62
+ * Update session metadata
63
+ */
64
+ updateMetadata(sessionId, updates) {
65
+ const session = this.getSession(sessionId);
66
+ session.metadata = {
67
+ ...session.metadata,
68
+ ...updates,
69
+ };
70
+ }
71
+ /**
72
+ * Mark session as completed
73
+ */
74
+ completeSession(sessionId, result) {
75
+ const session = this.getSession(sessionId);
76
+ session.status = "completed";
77
+ session.endTime = new Date();
78
+ session.result = result;
79
+ }
80
+ /**
81
+ * Mark session as failed
82
+ */
83
+ failSession(sessionId, error) {
84
+ const session = this.getSession(sessionId);
85
+ session.status = "failed";
86
+ session.endTime = new Date();
87
+ session.error = error;
88
+ }
89
+ /**
90
+ * Get all active sessions
91
+ */
92
+ getActiveSessions() {
93
+ return Array.from(this.sessions.values()).filter((s) => s.status === "running");
94
+ }
95
+ /**
96
+ * Get session statistics
97
+ */
98
+ getSessionStats(sessionId) {
99
+ const session = this.getSession(sessionId);
100
+ const duration = session.endTime
101
+ ? session.endTime.getTime() - session.startTime.getTime()
102
+ : Date.now() - session.startTime.getTime();
103
+ const toolCallsByName = {};
104
+ let totalToolDuration = 0;
105
+ session.toolCalls.forEach((tc) => {
106
+ toolCallsByName[tc.toolName] = (toolCallsByName[tc.toolName] || 0) + 1;
107
+ totalToolDuration += tc.duration;
108
+ });
109
+ return {
110
+ duration: Math.round(duration / 1000), // seconds
111
+ toolCallCount: session.toolCalls.length,
112
+ uniqueTools: Object.keys(toolCallsByName).length,
113
+ averageToolCallDuration: session.toolCalls.length > 0
114
+ ? Math.round(totalToolDuration / session.toolCalls.length)
115
+ : 0,
116
+ toolCallsByName,
117
+ };
118
+ }
119
+ /**
120
+ * Generate unique session ID
121
+ */
122
+ generateSessionId() {
123
+ const timestamp = Date.now().toString(36);
124
+ const random = randomBytes(4).toString("hex");
125
+ return `yama-v2-${timestamp}-${random}`;
126
+ }
127
+ /**
128
+ * Clean up old sessions (keep most recent 100)
129
+ */
130
+ cleanupOldSessions() {
131
+ const sessions = Array.from(this.sessions.entries());
132
+ // Sort by start time (oldest first)
133
+ sessions.sort((a, b) => {
134
+ return a[1].startTime.getTime() - b[1].startTime.getTime();
135
+ });
136
+ // Remove oldest sessions
137
+ const toRemove = sessions.length - this.maxSessions;
138
+ for (let i = 0; i < toRemove; i++) {
139
+ this.sessions.delete(sessions[i][0]);
140
+ }
141
+ }
142
+ /**
143
+ * Export session data for debugging
144
+ */
145
+ exportSession(sessionId) {
146
+ const session = this.getSession(sessionId);
147
+ const stats = this.getSessionStats(sessionId);
148
+ return {
149
+ session: {
150
+ sessionId: session.sessionId,
151
+ request: session.request,
152
+ startTime: session.startTime.toISOString(),
153
+ endTime: session.endTime?.toISOString(),
154
+ status: session.status,
155
+ metadata: session.metadata,
156
+ result: session.result,
157
+ error: session.error?.message,
158
+ },
159
+ statistics: stats,
160
+ toolCalls: session.toolCalls.map((tc) => ({
161
+ timestamp: tc.timestamp.toISOString(),
162
+ toolName: tc.toolName,
163
+ args: tc.args,
164
+ duration: tc.duration,
165
+ error: tc.error,
166
+ // Don't include full result in export (can be very large)
167
+ resultSummary: this.summarizeToolResult(tc.result),
168
+ })),
169
+ };
170
+ }
171
+ /**
172
+ * Summarize tool result for logging
173
+ */
174
+ summarizeToolResult(result) {
175
+ if (!result) {
176
+ return "null";
177
+ }
178
+ if (typeof result === "string") {
179
+ return result.length > 100 ? `${result.substring(0, 100)}...` : result;
180
+ }
181
+ if (typeof result === "object") {
182
+ const keys = Object.keys(result);
183
+ return `{${keys.slice(0, 5).join(", ")}${keys.length > 5 ? ", ..." : ""}}`;
184
+ }
185
+ return String(result);
186
+ }
187
+ /**
188
+ * Clear all sessions
189
+ */
190
+ clearAll() {
191
+ this.sessions.clear();
192
+ }
193
+ /**
194
+ * Get session count
195
+ */
196
+ getSessionCount() {
197
+ return this.sessions.size;
198
+ }
199
+ }
200
+ //# sourceMappingURL=SessionManager.js.map
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Yama V2 Orchestrator
3
+ * Main entry point for AI-native autonomous code review
4
+ */
5
+ import { ReviewRequest, ReviewResult, ReviewUpdate } from "../types/v2.types.js";
6
+ export declare class YamaV2Orchestrator {
7
+ private neurolink;
8
+ private mcpManager;
9
+ private configLoader;
10
+ private promptBuilder;
11
+ private sessionManager;
12
+ private config;
13
+ private initialized;
14
+ constructor();
15
+ /**
16
+ * Initialize Yama V2 with configuration and MCP servers
17
+ */
18
+ initialize(configPath?: string): Promise<void>;
19
+ /**
20
+ * Start autonomous AI review
21
+ */
22
+ startReview(request: ReviewRequest): Promise<ReviewResult>;
23
+ /**
24
+ * Stream review with real-time updates (for verbose mode)
25
+ */
26
+ streamReview(request: ReviewRequest): AsyncIterableIterator<ReviewUpdate>;
27
+ /**
28
+ * Start review and then enhance description in the same session
29
+ * This allows the AI to use knowledge gained during review to write better descriptions
30
+ */
31
+ startReviewAndEnhance(request: ReviewRequest): Promise<ReviewResult>;
32
+ /**
33
+ * Enhance PR description only (without full review)
34
+ */
35
+ enhanceDescription(request: ReviewRequest): Promise<any>;
36
+ /**
37
+ * Get session information
38
+ */
39
+ getSession(sessionId: string): import("../types/v2.types.js").ReviewSession;
40
+ /**
41
+ * Get session statistics
42
+ */
43
+ getSessionStats(sessionId: string): {
44
+ duration: number;
45
+ toolCallCount: number;
46
+ uniqueTools: number;
47
+ averageToolCallDuration: number;
48
+ toolCallsByName: Record<string, number>;
49
+ };
50
+ /**
51
+ * Export session data
52
+ */
53
+ exportSession(sessionId: string): any;
54
+ /**
55
+ * Create tool context for AI
56
+ */
57
+ private createToolContext;
58
+ /**
59
+ * Parse AI response into structured review result
60
+ */
61
+ private parseReviewResult;
62
+ /**
63
+ * Extract decision from AI response
64
+ */
65
+ private extractDecision;
66
+ /**
67
+ * Calculate statistics from session
68
+ */
69
+ private calculateStatistics;
70
+ /**
71
+ * Extract issue counts from comment tool calls
72
+ */
73
+ private extractIssueCountsFromComments;
74
+ /**
75
+ * Extract summary from AI response
76
+ */
77
+ private extractSummary;
78
+ /**
79
+ * Calculate cost estimate from token usage
80
+ */
81
+ private calculateCost;
82
+ /**
83
+ * Generate userId for NeuroLink context from repository and branch/PR
84
+ */
85
+ private generateUserId;
86
+ /**
87
+ * Initialize NeuroLink with observability configuration
88
+ */
89
+ private initializeNeurolink;
90
+ /**
91
+ * Ensure orchestrator is initialized
92
+ */
93
+ private ensureInitialized;
94
+ /**
95
+ * Show Yama V2 banner
96
+ */
97
+ private showBanner;
98
+ /**
99
+ * Log review start
100
+ */
101
+ private logReviewStart;
102
+ /**
103
+ * Log review completion
104
+ */
105
+ private logReviewComplete;
106
+ /**
107
+ * Format decision for display
108
+ */
109
+ private formatDecision;
110
+ }
111
+ export declare function createYamaV2(): YamaV2Orchestrator;
112
+ //# sourceMappingURL=YamaV2Orchestrator.d.ts.map