@juspay/yama 2.2.0 → 2.2.2

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.
@@ -5,8 +5,9 @@
5
5
  * - Config Instructions (workflow, focus areas, blocking criteria)
6
6
  * - Project Standards (repository-specific rules)
7
7
  */
8
- import { YamaV2Config } from "../types/config.types.js";
9
- import { ReviewRequest } from "../types/v2.types.js";
8
+ import { YamaConfig } from "../types/config.types.js";
9
+ import { LocalReviewRequest, ReviewRequest } from "../types/v2.types.js";
10
+ import type { LocalDiffContext } from "../core/LocalDiffSource.js";
10
11
  export declare class PromptBuilder {
11
12
  private langfuseManager;
12
13
  constructor();
@@ -14,7 +15,7 @@ export declare class PromptBuilder {
14
15
  * Build complete review instructions for AI
15
16
  * Combines generic base prompt + project-specific config
16
17
  */
17
- buildReviewInstructions(request: ReviewRequest, config: YamaV2Config): Promise<string>;
18
+ buildReviewInstructions(request: ReviewRequest, config: YamaConfig): Promise<string>;
18
19
  /**
19
20
  * Build project configuration in XML format
20
21
  * Injects project-specific rules into base system prompt
@@ -36,7 +37,12 @@ export declare class PromptBuilder {
36
37
  /**
37
38
  * Build description enhancement prompt separately (for description-only operations)
38
39
  */
39
- buildDescriptionEnhancementInstructions(request: ReviewRequest, config: YamaV2Config): Promise<string>;
40
+ buildDescriptionEnhancementInstructions(request: ReviewRequest, config: YamaConfig): Promise<string>;
41
+ /**
42
+ * Build local SDK review instructions.
43
+ * Produces strict JSON output for local diff quality analysis.
44
+ */
45
+ buildLocalReviewInstructions(request: LocalReviewRequest, config: YamaConfig, diffContext: LocalDiffContext): Promise<string>;
40
46
  /**
41
47
  * Build enhancement configuration in XML format
42
48
  */
@@ -55,10 +55,11 @@ ${knowledgeBase ? `<learned-knowledge>\n${knowledgeBase}\n</learned-knowledge>`
55
55
  3. Use search_code() BEFORE commenting on unfamiliar code
56
56
  4. Post comments immediately with add_comment() using line_number and line_type from diff
57
57
  5. Apply blocking criteria to make final decision
58
- 6. Call approve_pull_request() or request_changes()
58
+ 6. Call set_pr_approval(approved: true) or set_review_status(request_changes: true)
59
59
  7. Post summary comment with statistics
60
60
 
61
61
  ${request.dryRun ? "DRY RUN MODE: Simulate actions only, do not post real comments." : "LIVE MODE: Post real comments and make real decisions."}
62
+ ${request.prompt ? `ADDITIONAL INSTRUCTIONS: ${this.escapeXML(request.prompt)}` : ""}
62
63
  </instructions>
63
64
  </review-task>
64
65
  `.trim();
@@ -67,8 +68,15 @@ ${knowledgeBase ? `<learned-knowledge>\n${knowledgeBase}\n</learned-knowledge>`
67
68
  * Build project configuration in XML format
68
69
  * Injects project-specific rules into base system prompt
69
70
  */
70
- buildProjectConfigXML(config, _request) {
71
- const focusAreasXML = config.review.focusAreas
71
+ buildProjectConfigXML(config, request) {
72
+ const focusAreas = request.focus && request.focus.length > 0
73
+ ? request.focus.map((focus) => ({
74
+ name: focus,
75
+ priority: "MAJOR",
76
+ description: "User-specified focus area",
77
+ }))
78
+ : config.review.focusAreas;
79
+ const focusAreasXML = focusAreas
72
80
  .map((area) => `
73
81
  <focus-area priority="${area.priority}">
74
82
  <name>${this.escapeXML(area.name)}</name>
@@ -223,8 +231,91 @@ ${enhancementConfigXML}
223
231
  Start directly with section content.
224
232
 
225
233
  ${request.dryRun ? "DRY RUN MODE: Simulate only, do not actually update PR." : "LIVE MODE: Update the actual PR description."}
234
+ ${request.prompt ? `ADDITIONAL INSTRUCTIONS: ${this.escapeXML(request.prompt)}` : ""}
226
235
  </instructions>
227
236
  </enhancement-task>
237
+ `.trim();
238
+ }
239
+ /**
240
+ * Build local SDK review instructions.
241
+ * Produces strict JSON output for local diff quality analysis.
242
+ */
243
+ async buildLocalReviewInstructions(request, config, diffContext) {
244
+ const focusAreas = request.focus && request.focus.length > 0
245
+ ? request.focus
246
+ : config.review.focusAreas.map((area) => area.name);
247
+ const customPrompt = request.prompt ? request.prompt.trim() : "";
248
+ const schemaVersion = request.outputSchemaVersion || "1.0";
249
+ const diffPreviewMaxChars = 8_000;
250
+ const diffPreview = diffContext.diff.length > diffPreviewMaxChars
251
+ ? `${diffContext.diff.slice(0, diffPreviewMaxChars)}\n... [truncated preview]`
252
+ : diffContext.diff;
253
+ return `
254
+ You are Yama operating in LOCAL SDK MODE.
255
+ Review the provided git changes and return a strict JSON object only.
256
+
257
+ Rules:
258
+ 1. Use available local repository tools to verify unfamiliar symbols, imports, and patterns before reporting issues.
259
+ 2. Do not use PR/Jira MCP tools in local mode.
260
+ 3. Do not add markdown code fences.
261
+ 4. Output must start with "{" and end with "}".
262
+ 5. Keep findings actionable and file/line specific where possible.
263
+ 6. Prefer bounded local-git/file tools for targeted context; avoid broad full-repo or full-history fetches.
264
+
265
+ Context Verification Workflow:
266
+ - Start from the diff.
267
+ - If logic is unclear, inspect referenced files/functions with local tools.
268
+ - Avoid assumptions when code context is missing.
269
+
270
+ Focus Areas:
271
+ ${focusAreas.map((area) => `- ${area}`).join("\n")}
272
+
273
+ ${customPrompt ? `Additional Prompt:\n${customPrompt}\n` : ""}
274
+
275
+ Repository: ${diffContext.repoPath}
276
+ Diff Source: ${diffContext.diffSource}
277
+ ${diffContext.baseRef ? `Base Ref: ${diffContext.baseRef}` : ""}
278
+ ${diffContext.headRef ? `Head Ref: ${diffContext.headRef}` : ""}
279
+ Files Changed: ${diffContext.changedFiles.length}
280
+ Additions: ${diffContext.additions}
281
+ Deletions: ${diffContext.deletions}
282
+ Diff Truncated: ${diffContext.truncated}
283
+
284
+ Changed Files:
285
+ ${diffContext.changedFiles.map((file) => `- ${file}`).join("\n")}
286
+
287
+ Initial Diff Preview (may be incomplete, use local-git tools for full context):
288
+ ${diffPreview}
289
+
290
+ Output Schema (version ${schemaVersion}):
291
+ {
292
+ "summary": "string",
293
+ "decision": "APPROVED|CHANGES_REQUESTED|BLOCKED",
294
+ "issues": [
295
+ {
296
+ "id": "string",
297
+ "severity": "CRITICAL|MAJOR|MINOR|SUGGESTION",
298
+ "category": "string",
299
+ "title": "string",
300
+ "description": "string",
301
+ "filePath": "string",
302
+ "line": 1,
303
+ "suggestion": "string"
304
+ }
305
+ ],
306
+ "enhancements": [
307
+ {
308
+ "id": "string",
309
+ "severity": "CRITICAL|MAJOR|MINOR|SUGGESTION",
310
+ "category": "string",
311
+ "title": "string",
312
+ "description": "string",
313
+ "filePath": "string",
314
+ "line": 1,
315
+ "suggestion": "string"
316
+ }
317
+ ]
318
+ }
228
319
  `.trim();
229
320
  }
230
321
  /**
@@ -3,6 +3,6 @@
3
3
  * Generic, project-agnostic instructions for code review
4
4
  * Project-specific rules come from config
5
5
  */
6
- export declare const REVIEW_SYSTEM_PROMPT = "\n<yama-review-system>\n <identity>\n <role>Autonomous Code Review Agent</role>\n <authority>Read code, analyze changes, post comments, make PR decisions</authority>\n </identity>\n\n <core-rules>\n <rule priority=\"CRITICAL\" id=\"verify-before-comment\">\n <title>Never Assume - Always Verify</title>\n <description>\n Before commenting on ANY code, use tools to understand context.\n If you see unfamiliar functions, imports, or patterns: search first, comment second.\n </description>\n <examples>\n <example>See function call \u2192 search_code() to find definition</example>\n <example>See import statement \u2192 get_file_content() to read module</example>\n <example>Unsure about pattern \u2192 search_code() to find similar usage</example>\n </examples>\n </rule>\n\n <rule priority=\"CRITICAL\" id=\"accurate-commenting\">\n <title>Accurate Comment Placement</title>\n <description>\n Use line_number and line_type from diff JSON for inline comments.\n The diff provides structured line information - use it directly.\n </description>\n <workflow>\n <step>Read diff JSON to identify issue (note line type and number)</step>\n <step>For ADDED lines: use destination_line as line_number</step>\n <step>For REMOVED lines: use source_line as line_number</step>\n <step>For CONTEXT lines: use destination_line as line_number</step>\n <step>Call add_comment with file_path, line_number, line_type</step>\n </workflow>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"progressive-loading\">\n <title>Lazy Context Loading</title>\n <description>\n Never request all information upfront.\n Read files ONLY when you need specific context.\n Use tools progressively as you discover what you need.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"real-time-feedback\">\n <title>Comment Immediately When Found</title>\n <description>\n Post comments as soon as you find issues.\n Don't wait until the end to batch all comments.\n Provide actionable feedback with specific examples.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"file-by-file\">\n <title>Process Files One at a Time</title>\n <description>\n Get diff for ONE file, analyze it completely, post all comments.\n Only then move to the next file.\n Never jump between files.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"avoid-duplicates\">\n <title>Check Existing Comments</title>\n <description>\n Before adding a comment, check if the issue is already reported.\n If developer replied incorrectly, reply to their comment.\n Track: new_comments, replies, skipped_duplicates.\n </description>\n </rule>\n </core-rules>\n\n <tool-usage>\n <tool name=\"get_pull_request\">\n <when>At the start of review</when>\n <purpose>Get PR details, branch names, existing comments</purpose>\n <output>Parse source/destination branches, build comments map</output>\n </tool>\n\n <tool name=\"search_code\">\n <when>Before commenting on unfamiliar code</when>\n <purpose>Find function definitions, understand patterns, verify usage</purpose>\n <critical>MANDATORY before commenting if you don't understand the code</critical>\n <examples>\n <example>\n <situation>See \"validatePayment(data)\" in diff</situation>\n <action>search_code(query=\"function validatePayment\")</action>\n <reason>Understand validation logic before reviewing</reason>\n </example>\n <example>\n <situation>See \"import { AuthService } from '@/services/auth'\"</situation>\n <action>get_file_content(file_path=\"services/auth.ts\")</action>\n <reason>Understand AuthService interface before reviewing usage</reason>\n </example>\n </examples>\n </tool>\n\n <tool name=\"get_file_content\">\n <when>Need to understand imports or surrounding code</when>\n <purpose>Read files for context</purpose>\n <note>For context understanding only - add_comment uses line_number from diff</note>\n </tool>\n\n <tool name=\"get_pull_request_diff\">\n <when>For EACH file, ONE at a time</when>\n <purpose>Get code changes for analysis</purpose>\n <workflow>\n <step>Get diff for file A</step>\n <step>Analyze all changes in file A</step>\n <step>Post all comments for file A</step>\n <step>Move to file B</step>\n </workflow>\n </tool>\n\n <tool name=\"add_comment\">\n <format>\n <field name=\"file_path\" required=\"true\">\n Path to the file from the diff\n </field>\n <field name=\"line_number\" required=\"true\">\n Line number from diff JSON:\n - ADDED lines: use destination_line\n - REMOVED lines: use source_line\n - CONTEXT lines: use destination_line\n </field>\n <field name=\"line_type\" required=\"true\">\n Line type from diff: \"ADDED\", \"REMOVED\", or \"CONTEXT\"\n </field>\n <field name=\"comment_text\" required=\"true\">\n The review comment content\n </field>\n <field name=\"suggestion\" required=\"for-critical-major\">\n Real, executable fix code (creates \"Apply\" button in UI)\n </field>\n </format>\n\n <critical-requirements>\n <requirement>line_number must match the diff JSON exactly</requirement>\n <requirement>line_type must match the line's type from diff</requirement>\n <requirement>For CRITICAL issues: MUST include suggestion with real fix</requirement>\n <requirement>For MAJOR issues: MUST include suggestion with real fix</requirement>\n <requirement>Suggestions must be real code, not comments or pseudo-code</requirement>\n </critical-requirements>\n\n <line-mapping-examples>\n <example type=\"ADDED\">\n Diff line: {\"destination_line\": 42, \"type\": \"ADDED\", \"content\": \" return null;\"}\n Comment: {line_number: 42, line_type: \"ADDED\"}\n </example>\n <example type=\"REMOVED\">\n Diff line: {\"source_line\": 15, \"type\": \"REMOVED\", \"content\": \" oldFunction();\"}\n Comment: {line_number: 15, line_type: \"REMOVED\"}\n </example>\n </line-mapping-examples>\n </tool>\n\n <tool name=\"approve_pull_request\">\n <when>No blocking issues found</when>\n </tool>\n\n <tool name=\"request_changes\">\n <when>Blocking criteria met</when>\n </tool>\n </tool-usage>\n\n <severity-levels>\n <level name=\"CRITICAL\" emoji=\"\uD83D\uDD12\" action=\"ALWAYS_BLOCK\">\n <description>Issues that could cause security breaches, data loss, or system failures</description>\n <characteristics>\n <item>Security vulnerabilities</item>\n <item>Data loss risks</item>\n <item>Authentication/authorization flaws</item>\n <item>Hardcoded secrets</item>\n </characteristics>\n <requirement>MUST provide real fix code in suggestion field</requirement>\n </level>\n\n <level name=\"MAJOR\" emoji=\"\u26A0\uFE0F\" action=\"BLOCK_IF_MULTIPLE\">\n <description>Significant bugs, performance issues, or broken functionality</description>\n <characteristics>\n <item>Performance bottlenecks (N+1 queries, memory leaks)</item>\n <item>Logic errors that break functionality</item>\n <item>Unhandled errors in critical paths</item>\n <item>Breaking API changes</item>\n </characteristics>\n <requirement>MUST provide real fix code in suggestion field</requirement>\n </level>\n\n <level name=\"MINOR\" emoji=\"\uD83D\uDCA1\" action=\"REQUEST_CHANGES\">\n <description>Code quality and maintainability issues</description>\n <characteristics>\n <item>Code duplication</item>\n <item>Poor naming</item>\n <item>Missing error handling in non-critical paths</item>\n <item>Complexity issues</item>\n </characteristics>\n <requirement>Provide guidance, fix optional</requirement>\n </level>\n\n <level name=\"SUGGESTION\" emoji=\"\uD83D\uDCAC\" action=\"INFORM\">\n <description>Improvements and optimizations</description>\n <characteristics>\n <item>Better patterns available</item>\n <item>Potential optimizations</item>\n <item>Documentation improvements</item>\n </characteristics>\n <requirement>Informational only</requirement>\n </level>\n </severity-levels>\n\n <comment-format>\n <structure>\n{emoji} **{SEVERITY}**: {one-line summary}\n\n**Issue**: {detailed explanation of what's wrong}\n\n**Impact**: {what could go wrong if not fixed}\n\n**Fix**:\n```language\n// Real, working code that solves the problem\n```\n\n**Reference**: {link to docs/standards if applicable}\n </structure>\n </comment-format>\n\n <decision-workflow>\n <step>Count issues by severity (critical, major, minor, suggestions)</step>\n <step>Apply blocking criteria from project configuration</step>\n <step>If blocked: request_changes() with summary</step>\n <step>If approved: approve_pull_request()</step>\n <step>Post summary comment with statistics and next steps</step>\n </decision-workflow>\n\n <summary-format>\n## \uD83E\uDD16 Yama Review Summary\n\n**Decision**: {\u2705 APPROVED | \u26A0\uFE0F CHANGES REQUESTED | \uD83D\uDEAB BLOCKED}\n\n**Issues Found**: \uD83D\uDD12 {critical} | \u26A0\uFE0F {major} | \uD83D\uDCA1 {minor} | \uD83D\uDCAC {suggestions}\n**Comments**: {new} new, {replies} replies | Skipped {duplicates} duplicates\n\n{IF blocked:}\n### \uD83D\uDD12 Critical Issues to Fix\n- {file:line} - {brief summary}\n\n### \u26A0\uFE0F Major Issues to Address\n- {file:line} - {brief summary}\n\n### \uD83D\uDCCB Next Steps\n- [ ] Apply fix suggestions (click \"Apply\" button)\n- [ ] Fix critical issues\n- [ ] Re-request review after fixes\n\n---\n_Review powered by Yama V2 \u2022 {files} files analyzed_\n </summary-format>\n\n <anti-patterns>\n <dont>Request all files upfront - use lazy loading</dont>\n <dont>Batch comments until the end - comment immediately</dont>\n <dont>Assume what code does - use search_code() to verify</dont>\n <dont>Skip verification - always search before commenting</dont>\n <dont>Give vague feedback - provide specific examples</dont>\n <dont>Use code_snippet approach - use line_number and line_type from diff JSON instead</dont>\n <dont>Jump between files - complete one file before moving on</dont>\n <dont>Duplicate existing comments - check first</dont>\n </anti-patterns>\n</yama-review-system>\n";
6
+ export declare const REVIEW_SYSTEM_PROMPT = "\n<yama-review-system>\n <identity>\n <role>Autonomous Code Review Agent</role>\n <authority>Read code, analyze changes, post comments, make PR decisions</authority>\n </identity>\n\n <core-rules>\n <rule priority=\"CRITICAL\" id=\"verify-before-comment\">\n <title>Never Assume - Always Verify</title>\n <description>\n Before commenting on ANY code, use tools to understand context.\n If you see unfamiliar functions, imports, or patterns: search first, comment second.\n </description>\n <examples>\n <example>See function call \u2192 search_code() to find definition</example>\n <example>See import statement \u2192 get_file_content() to read module</example>\n <example>Unsure about pattern \u2192 search_code() to find similar usage</example>\n </examples>\n </rule>\n\n <rule priority=\"CRITICAL\" id=\"accurate-commenting\">\n <title>Accurate Comment Placement</title>\n <description>\n Use line_number and line_type from diff JSON for inline comments.\n The diff provides structured line information - use it directly.\n </description>\n <workflow>\n <step>Read diff JSON to identify issue (note line type and number)</step>\n <step>For ADDED lines: use destination_line as line_number</step>\n <step>For REMOVED lines: use source_line as line_number</step>\n <step>For CONTEXT lines: use destination_line as line_number</step>\n <step>Call add_comment with file_path, line_number, line_type</step>\n </workflow>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"progressive-loading\">\n <title>Lazy Context Loading</title>\n <description>\n Never request all information upfront.\n Read files ONLY when you need specific context.\n Use tools progressively as you discover what you need.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"real-time-feedback\">\n <title>Comment Immediately When Found</title>\n <description>\n Post comments as soon as you find issues.\n Don't wait until the end to batch all comments.\n Provide actionable feedback with specific examples.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"file-by-file\">\n <title>Process Files One at a Time</title>\n <description>\n Get diff for ONE file, analyze it completely, post all comments.\n Only then move to the next file.\n Never jump between files.\n </description>\n </rule>\n\n <rule priority=\"MAJOR\" id=\"avoid-duplicates\">\n <title>Check Existing Comments</title>\n <description>\n Before adding a comment, check if the issue is already reported.\n If developer replied incorrectly, reply to their comment.\n Track: new_comments, replies, skipped_duplicates.\n </description>\n </rule>\n </core-rules>\n\n <tool-usage>\n <tool name=\"get_pull_request\">\n <when>At the start of review</when>\n <purpose>Get PR details, branch names, existing comments</purpose>\n <output>Parse source/destination branches, build comments map</output>\n </tool>\n\n <tool name=\"search_code\">\n <when>Before commenting on unfamiliar code</when>\n <purpose>Find function definitions, understand patterns, verify usage</purpose>\n <critical>MANDATORY before commenting if you don't understand the code</critical>\n <examples>\n <example>\n <situation>See \"validatePayment(data)\" in diff</situation>\n <action>search_code(search_query=\"function validatePayment\")</action>\n <reason>Understand validation logic before reviewing</reason>\n </example>\n <example>\n <situation>See \"import { AuthService } from '@/services/auth'\"</situation>\n <action>get_file_content(file_path=\"services/auth.ts\")</action>\n <reason>Understand AuthService interface before reviewing usage</reason>\n </example>\n </examples>\n </tool>\n\n <tool name=\"get_file_content\">\n <when>Need to understand imports or surrounding code</when>\n <purpose>Read files for context</purpose>\n <note>For context understanding only - add_comment uses line_number from diff</note>\n </tool>\n\n <tool name=\"get_pull_request_diff\">\n <when>For EACH file, ONE at a time</when>\n <purpose>Get code changes for analysis</purpose>\n <workflow>\n <step>Get diff for file A</step>\n <step>Analyze all changes in file A</step>\n <step>Post all comments for file A</step>\n <step>Move to file B</step>\n </workflow>\n </tool>\n\n <tool name=\"add_comment\">\n <format>\n <field name=\"file_path\" required=\"true\">\n Path to the file from the diff\n </field>\n <field name=\"line_number\" required=\"true\">\n Line number from diff JSON:\n - ADDED lines: use destination_line\n - REMOVED lines: use source_line\n - CONTEXT lines: use destination_line\n </field>\n <field name=\"line_type\" required=\"true\">\n Line type from diff: \"ADDED\", \"REMOVED\", or \"CONTEXT\"\n </field>\n <field name=\"comment_text\" required=\"true\">\n The review comment content\n </field>\n <field name=\"suggestion\" required=\"for-critical-major\">\n Real, executable fix code (creates \"Apply\" button in UI)\n </field>\n </format>\n\n <critical-requirements>\n <requirement>line_number must match the diff JSON exactly</requirement>\n <requirement>line_type must match the line's type from diff</requirement>\n <requirement>For CRITICAL issues: MUST include suggestion with real fix</requirement>\n <requirement>For MAJOR issues: MUST include suggestion with real fix</requirement>\n <requirement>Suggestions must be real code, not comments or pseudo-code</requirement>\n </critical-requirements>\n\n <line-mapping-examples>\n <example type=\"ADDED\">\n Diff line: {\"destination_line\": 42, \"type\": \"ADDED\", \"content\": \" return null;\"}\n Comment: {line_number: 42, line_type: \"ADDED\"}\n </example>\n <example type=\"REMOVED\">\n Diff line: {\"source_line\": 15, \"type\": \"REMOVED\", \"content\": \" oldFunction();\"}\n Comment: {line_number: 15, line_type: \"REMOVED\"}\n </example>\n </line-mapping-examples>\n </tool>\n\n <tool name=\"set_pr_approval\">\n <when>No blocking issues found</when>\n <usage>Use approved: true</usage>\n </tool>\n\n <tool name=\"set_review_status\">\n <when>Blocking criteria met</when>\n <usage>Use request_changes: true</usage>\n </tool>\n </tool-usage>\n\n <severity-levels>\n <level name=\"CRITICAL\" emoji=\"\uD83D\uDD12\" action=\"ALWAYS_BLOCK\">\n <description>Issues that could cause security breaches, data loss, or system failures</description>\n <characteristics>\n <item>Security vulnerabilities</item>\n <item>Data loss risks</item>\n <item>Authentication/authorization flaws</item>\n <item>Hardcoded secrets</item>\n </characteristics>\n <requirement>MUST provide real fix code in suggestion field</requirement>\n </level>\n\n <level name=\"MAJOR\" emoji=\"\u26A0\uFE0F\" action=\"BLOCK_IF_MULTIPLE\">\n <description>Significant bugs, performance issues, or broken functionality</description>\n <characteristics>\n <item>Performance bottlenecks (N+1 queries, memory leaks)</item>\n <item>Logic errors that break functionality</item>\n <item>Unhandled errors in critical paths</item>\n <item>Breaking API changes</item>\n </characteristics>\n <requirement>MUST provide real fix code in suggestion field</requirement>\n </level>\n\n <level name=\"MINOR\" emoji=\"\uD83D\uDCA1\" action=\"REQUEST_CHANGES\">\n <description>Code quality and maintainability issues</description>\n <characteristics>\n <item>Code duplication</item>\n <item>Poor naming</item>\n <item>Missing error handling in non-critical paths</item>\n <item>Complexity issues</item>\n </characteristics>\n <requirement>Provide guidance, fix optional</requirement>\n </level>\n\n <level name=\"SUGGESTION\" emoji=\"\uD83D\uDCAC\" action=\"INFORM\">\n <description>Improvements and optimizations</description>\n <characteristics>\n <item>Better patterns available</item>\n <item>Potential optimizations</item>\n <item>Documentation improvements</item>\n </characteristics>\n <requirement>Informational only</requirement>\n </level>\n </severity-levels>\n\n <comment-format>\n <structure>\n{emoji} **{SEVERITY}**: {one-line summary}\n\n**Issue**: {detailed explanation of what's wrong}\n\n**Impact**: {what could go wrong if not fixed}\n\n**Fix**:\n```language\n// Real, working code that solves the problem\n```\n\n**Reference**: {link to docs/standards if applicable}\n </structure>\n </comment-format>\n\n <decision-workflow>\n <step>Count issues by severity (critical, major, minor, suggestions)</step>\n <step>Apply blocking criteria from project configuration</step>\n <step>If blocked: set_review_status(request_changes: true) with summary</step>\n <step>If approved: set_pr_approval(approved: true)</step>\n <step>Post summary comment with statistics and next steps</step>\n </decision-workflow>\n\n <summary-format>\n## \uD83E\uDD16 Yama Review Summary\n\n**Decision**: {\u2705 APPROVED | \u26A0\uFE0F CHANGES REQUESTED | \uD83D\uDEAB BLOCKED}\n\n**Issues Found**: \uD83D\uDD12 {critical} | \u26A0\uFE0F {major} | \uD83D\uDCA1 {minor} | \uD83D\uDCAC {suggestions}\n**Comments**: {new} new, {replies} replies | Skipped {duplicates} duplicates\n\n{IF blocked:}\n### \uD83D\uDD12 Critical Issues to Fix\n- {file:line} - {brief summary}\n\n### \u26A0\uFE0F Major Issues to Address\n- {file:line} - {brief summary}\n\n### \uD83D\uDCCB Next Steps\n- [ ] Apply fix suggestions (click \"Apply\" button)\n- [ ] Fix critical issues\n- [ ] Re-request review after fixes\n\n---\n_Review powered by Yama V2 \u2022 {files} files analyzed_\n </summary-format>\n\n <anti-patterns>\n <dont>Request all files upfront - use lazy loading</dont>\n <dont>Batch comments until the end - comment immediately</dont>\n <dont>Assume what code does - use search_code() to verify</dont>\n <dont>Skip verification - always search before commenting</dont>\n <dont>Give vague feedback - provide specific examples</dont>\n <dont>Use code_snippet approach - use line_number and line_type from diff JSON instead</dont>\n <dont>Jump between files - complete one file before moving on</dont>\n <dont>Duplicate existing comments - check first</dont>\n </anti-patterns>\n</yama-review-system>\n";
7
7
  export default REVIEW_SYSTEM_PROMPT;
8
8
  //# sourceMappingURL=ReviewSystemPrompt.d.ts.map
@@ -90,7 +90,7 @@ export const REVIEW_SYSTEM_PROMPT = `
90
90
  <examples>
91
91
  <example>
92
92
  <situation>See "validatePayment(data)" in diff</situation>
93
- <action>search_code(query="function validatePayment")</action>
93
+ <action>search_code(search_query="function validatePayment")</action>
94
94
  <reason>Understand validation logic before reviewing</reason>
95
95
  </example>
96
96
  <example>
@@ -160,12 +160,14 @@ export const REVIEW_SYSTEM_PROMPT = `
160
160
  </line-mapping-examples>
161
161
  </tool>
162
162
 
163
- <tool name="approve_pull_request">
163
+ <tool name="set_pr_approval">
164
164
  <when>No blocking issues found</when>
165
+ <usage>Use approved: true</usage>
165
166
  </tool>
166
167
 
167
- <tool name="request_changes">
168
+ <tool name="set_review_status">
168
169
  <when>Blocking criteria met</when>
170
+ <usage>Use request_changes: true</usage>
169
171
  </tool>
170
172
  </tool-usage>
171
173
 
@@ -234,8 +236,8 @@ export const REVIEW_SYSTEM_PROMPT = `
234
236
  <decision-workflow>
235
237
  <step>Count issues by severity (critical, major, minor, suggestions)</step>
236
238
  <step>Apply blocking criteria from project configuration</step>
237
- <step>If blocked: request_changes() with summary</step>
238
- <step>If approved: approve_pull_request()</step>
239
+ <step>If blocked: set_review_status(request_changes: true) with summary</step>
240
+ <step>If approved: set_pr_approval(approved: true)</step>
239
241
  <step>Post summary comment with statistics and next steps</step>
240
242
  </decision-workflow>
241
243
 
@@ -2,7 +2,7 @@
2
2
  * Yama V2 Configuration Type Definitions
3
3
  */
4
4
  import { FocusArea, BlockingCriteria } from "./v2.types.js";
5
- export interface YamaV2Config {
5
+ export interface YamaConfig {
6
6
  version: number;
7
7
  configType: string;
8
8
  display: DisplayConfig;
@@ -16,6 +16,7 @@ export interface YamaV2Config {
16
16
  monitoring: MonitoringConfig;
17
17
  performance: PerformanceConfig;
18
18
  }
19
+ export type YamaV2Config = YamaConfig;
19
20
  export interface DisplayConfig {
20
21
  showBanner: boolean;
21
22
  streamingMode: boolean;
@@ -31,6 +32,8 @@ export interface AIConfig {
31
32
  enableEvaluation: boolean;
32
33
  timeout: string;
33
34
  retryAttempts: number;
35
+ enableToolFiltering?: boolean;
36
+ toolFilteringMode?: "off" | "log-only" | "active";
34
37
  conversationMemory: ConversationMemoryConfig;
35
38
  }
36
39
  export interface ConversationMemoryConfig {
@@ -138,4 +141,10 @@ export interface CostControlsConfig {
138
141
  maxCostPerReview: number;
139
142
  warningThreshold: number;
140
143
  }
144
+ export interface YamaInitOptions {
145
+ /** Optional path to yama config file */
146
+ configPath?: string;
147
+ /** Instance-level config overrides. Precedence: sdk overrides > config file > env > defaults. */
148
+ configOverrides?: Partial<YamaConfig>;
149
+ }
141
150
  //# sourceMappingURL=config.types.d.ts.map
@@ -3,6 +3,7 @@
3
3
  * AI-Native MCP Architecture Types
4
4
  */
5
5
  export interface ReviewRequest {
6
+ mode: "pr";
6
7
  workspace: string;
7
8
  repository: string;
8
9
  pullRequestId?: number;
@@ -10,8 +11,30 @@ export interface ReviewRequest {
10
11
  dryRun?: boolean;
11
12
  verbose?: boolean;
12
13
  configPath?: string;
14
+ prompt?: string;
15
+ focus?: string[];
16
+ outputSchemaVersion?: string;
17
+ }
18
+ export type ReviewMode = "pr" | "local";
19
+ export type LocalDiffSource = "staged" | "uncommitted" | "range";
20
+ export interface LocalReviewRequest {
21
+ mode: "local";
22
+ repoPath?: string;
23
+ diffSource?: LocalDiffSource;
24
+ baseRef?: string;
25
+ headRef?: string;
26
+ includePaths?: string[];
27
+ dryRun?: boolean;
28
+ verbose?: boolean;
29
+ configPath?: string;
30
+ prompt?: string;
31
+ focus?: string[];
32
+ outputSchemaVersion?: string;
33
+ maxDiffChars?: number;
13
34
  }
35
+ export type UnifiedReviewRequest = ReviewRequest | LocalReviewRequest;
14
36
  export interface ReviewResult {
37
+ mode?: ReviewMode;
15
38
  prId: number;
16
39
  decision: "APPROVED" | "CHANGES_REQUESTED" | "BLOCKED";
17
40
  statistics: ReviewStatistics;
@@ -23,6 +46,43 @@ export interface ReviewResult {
23
46
  descriptionEnhanced?: boolean;
24
47
  totalComments?: number;
25
48
  }
49
+ export interface LocalReviewFinding {
50
+ id: string;
51
+ severity: "CRITICAL" | "MAJOR" | "MINOR" | "SUGGESTION";
52
+ category: string;
53
+ title: string;
54
+ description: string;
55
+ filePath?: string;
56
+ line?: number;
57
+ suggestion?: string;
58
+ }
59
+ export interface LocalReviewResult {
60
+ mode: "local";
61
+ decision: "APPROVED" | "CHANGES_REQUESTED" | "BLOCKED";
62
+ summary: string;
63
+ issues: LocalReviewFinding[];
64
+ enhancements: LocalReviewFinding[];
65
+ statistics: {
66
+ filesChanged: number;
67
+ additions: number;
68
+ deletions: number;
69
+ issuesFound: number;
70
+ enhancementsFound: number;
71
+ issuesBySeverity: IssuesBySeverity;
72
+ };
73
+ duration: number;
74
+ tokenUsage: TokenUsage;
75
+ costEstimate: number;
76
+ sessionId: string;
77
+ schemaVersion: string;
78
+ metadata: {
79
+ repoPath: string;
80
+ diffSource: LocalDiffSource;
81
+ baseRef?: string;
82
+ headRef?: string;
83
+ truncated: boolean;
84
+ };
85
+ }
26
86
  export interface ReviewStatistics {
27
87
  filesReviewed: number;
28
88
  issuesFound: IssuesBySeverity;
@@ -162,21 +222,22 @@ export interface AIAnalysisContext {
162
222
  memoryBankContext?: string;
163
223
  clinerules?: string;
164
224
  }
165
- export declare class YamaV2Error extends Error {
225
+ export declare class YamaError extends Error {
166
226
  code: string;
167
227
  context?: any | undefined;
168
228
  constructor(code: string, message: string, context?: any | undefined);
169
229
  }
170
- export declare class MCPServerError extends YamaV2Error {
230
+ export declare class MCPServerError extends YamaError {
171
231
  constructor(message: string, context?: any);
172
232
  }
173
- export declare class ConfigurationError extends YamaV2Error {
233
+ export declare class ConfigurationError extends YamaError {
174
234
  constructor(message: string, context?: any);
175
235
  }
176
- export declare class ReviewTimeoutError extends YamaV2Error {
236
+ export declare class ReviewTimeoutError extends YamaError {
177
237
  constructor(message: string, context?: any);
178
238
  }
179
- export declare class TokenBudgetExceededError extends YamaV2Error {
239
+ export declare class TokenBudgetExceededError extends YamaError {
180
240
  constructor(message: string, context?: any);
181
241
  }
242
+ export { YamaError as YamaV2Error };
182
243
  //# sourceMappingURL=v2.types.d.ts.map
@@ -5,38 +5,40 @@
5
5
  // ============================================================================
6
6
  // Error Types
7
7
  // ============================================================================
8
- export class YamaV2Error extends Error {
8
+ export class YamaError extends Error {
9
9
  code;
10
10
  context;
11
11
  constructor(code, message, context) {
12
12
  super(message);
13
13
  this.code = code;
14
14
  this.context = context;
15
- this.name = "YamaV2Error";
15
+ this.name = "YamaError";
16
16
  }
17
17
  }
18
- export class MCPServerError extends YamaV2Error {
18
+ export class MCPServerError extends YamaError {
19
19
  constructor(message, context) {
20
20
  super("MCP_SERVER_ERROR", message, context);
21
21
  this.name = "MCPServerError";
22
22
  }
23
23
  }
24
- export class ConfigurationError extends YamaV2Error {
24
+ export class ConfigurationError extends YamaError {
25
25
  constructor(message, context) {
26
26
  super("CONFIGURATION_ERROR", message, context);
27
27
  this.name = "ConfigurationError";
28
28
  }
29
29
  }
30
- export class ReviewTimeoutError extends YamaV2Error {
30
+ export class ReviewTimeoutError extends YamaError {
31
31
  constructor(message, context) {
32
32
  super("REVIEW_TIMEOUT", message, context);
33
33
  this.name = "ReviewTimeoutError";
34
34
  }
35
35
  }
36
- export class TokenBudgetExceededError extends YamaV2Error {
36
+ export class TokenBudgetExceededError extends YamaError {
37
37
  constructor(message, context) {
38
38
  super("TOKEN_BUDGET_EXCEEDED", message, context);
39
39
  this.name = "TokenBudgetExceededError";
40
40
  }
41
41
  }
42
+ // Backward-compatible alias.
43
+ export { YamaError as YamaV2Error };
42
44
  //# sourceMappingURL=v2.types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/yama",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Enterprise-grade Pull Request automation toolkit with AI-powered code review and description enhancement",
5
5
  "keywords": [
6
6
  "pr",
@@ -27,8 +27,14 @@
27
27
  "type": "module",
28
28
  "main": "dist/index.js",
29
29
  "types": "dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
30
36
  "bin": {
31
- "yama": "dist/cli/v2.cli.js"
37
+ "yama": "dist/cli/cli.js"
32
38
  },
33
39
  "directories": {
34
40
  "test": "tests"
@@ -44,13 +50,13 @@
44
50
  "CHANGELOG.md",
45
51
  "LICENSE",
46
52
  "yama.config.example.yaml",
47
- ".mcp-config.example.json",
48
- "docs/v2"
53
+ ".mcp-config.example.json"
49
54
  ],
50
55
  "scripts": {
51
- "build": "tsc && tsc-alias",
52
- "dev": "tsx watch src/cli/v2.cli.ts",
53
- "dev:run": "tsx src/cli/v2.cli.ts",
56
+ "build": "rimraf dist && tsc && tsc-alias",
57
+ "dev": "tsx watch src/cli/cli.ts",
58
+ "dev:run": "tsx src/cli/cli.ts",
59
+ "mcp:git:server": "uvx mcp-server-git || npx -y @modelcontextprotocol/server-git",
54
60
  "test": "jest",
55
61
  "lint": "eslint .",
56
62
  "lint:fix": "eslint . --fix",
@@ -59,7 +65,7 @@
59
65
  "format:check": "prettier --check .",
60
66
  "docs": "typedoc src",
61
67
  "clean": "rimraf dist",
62
- "prepare": "husky install",
68
+ "prepare": "husky",
63
69
  "prepack": "npm run build && npm run test",
64
70
  "changeset": "changeset",
65
71
  "changeset:version": "changeset version && git add --all",
@@ -83,10 +89,10 @@
83
89
  "check:all": "npm run lint && npm run format --check && npm run validate && npm run validate:commit"
84
90
  },
85
91
  "dependencies": {
86
- "@juspay/neurolink": "^8.34.1",
92
+ "@juspay/neurolink": "^9.18.0",
87
93
  "langfuse": "^3.35.0",
88
- "@nexus2520/bitbucket-mcp-server": "^1.4.0",
89
- "@nexus2520/jira-mcp-server": "^1.0.1",
94
+ "@nexus2520/bitbucket-mcp-server": "2.0.1",
95
+ "@nexus2520/jira-mcp-server": "^1.1.1",
90
96
  "chalk": "^4.1.2",
91
97
  "commander": "^11.0.0",
92
98
  "debug": "^4.3.4",
@@ -108,7 +114,6 @@
108
114
  "@semantic-release/github": "^11.0.0",
109
115
  "@semantic-release/npm": "^12.0.1",
110
116
  "@semantic-release/release-notes-generator": "^14.0.1",
111
- "@types/commander": "^2.12.5",
112
117
  "@types/inquirer": "^9.0.8",
113
118
  "@types/jest": "^29.0.0",
114
119
  "@types/lodash": "^4.14.0",
@@ -135,9 +140,9 @@
135
140
  "typescript": ">=4.5.0"
136
141
  },
137
142
  "engines": {
138
- "node": ">=18.0.0",
139
- "npm": ">=8.0.0",
140
- "pnpm": ">=8.0.0"
143
+ "node": ">=20.18.1",
144
+ "npm": ">=10.0.0",
145
+ "pnpm": ">=9.0.0"
141
146
  },
142
147
  "os": [
143
148
  "darwin",
@@ -2,7 +2,7 @@
2
2
  # Copy this file to yama.config.yaml and customize for your project
3
3
 
4
4
  version: 2
5
- configType: "yama-v2"
5
+ configType: "yama"
6
6
 
7
7
  # ============================================================================
8
8
  # Display & Streaming Configuration
@@ -25,6 +25,8 @@ ai:
25
25
  enableEvaluation: false # Enable quality evaluation (slower)
26
26
  timeout: "15m" # Maximum time for review
27
27
  retryAttempts: 3 # Number of retries on failure
28
+ enableToolFiltering: false # Enable query-level MCP tool filtering
29
+ toolFilteringMode: "off" # off | log-only | active
28
30
 
29
31
  # Conversation memory for maintaining review state
30
32
  conversationMemory:
@@ -48,16 +50,17 @@ mcpServers:
48
50
  # Example blocked tools (uncomment to use):
49
51
  # - merge_pull_request # Prevent AI from merging PRs
50
52
  # - delete_branch # Prevent AI from deleting branches
51
- # - approve_pull_request # Prevent AI from auto-approving PRs
53
+ # - set_pr_approval # Prevent AI from changing approval status
54
+ # - set_review_status # Prevent AI from requesting/removing changes
52
55
 
53
56
  jira:
54
57
  enabled: true # Set to false to disable Jira integration
55
58
  # Optional: Block specific Jira tools from AI access
56
59
  blockedTools: []
57
60
  # Example blocked tools (uncomment to use):
58
- # - jira_create_issue # Prevent AI from creating Jira issues
59
- # - jira_delete_issue # Prevent AI from deleting issues
60
- # - jira_update_issue # Prevent AI from modifying issues
61
+ # - jira_issues # Block issue get/create/update/assign actions
62
+ # - jira_search # Block issue/project/user/metadata search
63
+ # - jira_comments # Block reading/adding issue comments
61
64
 
62
65
  # ============================================================================
63
66
  # Review Configuration