Skip to content

Commit 2c33b38

Browse files
feat(amazonq): add user requirement to zipfile for code review tool (#2430)
Co-authored-by: Laxman Reddy <[email protected]>
1 parent bee5cad commit 2c33b38

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/qCodeAnalysis/codeReview.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ describe('CodeReview', () => {
104104
folderLevelArtifacts: [],
105105
ruleArtifacts: [],
106106
scopeOfReview: FULL_REVIEW,
107+
userRequirement: 'Test requirement',
107108
modelId: 'claude-4-sonnet',
108109
}
109110
})
@@ -136,7 +137,9 @@ describe('CodeReview', () => {
136137
md5Hash: 'hash123',
137138
isCodeDiffPresent: false,
138139
programmingLanguages: new Set(['javascript']),
140+
numberOfFilesInCustomerCodeZip: 1,
139141
codeDiffFiles: new Set(),
142+
filePathsInZip: new Set(['/test/file.js']),
140143
})
141144
sandbox.stub(codeReview as any, 'parseFindings').returns([])
142145

@@ -265,7 +268,9 @@ describe('CodeReview', () => {
265268
md5Hash: 'hash123',
266269
isCodeDiffPresent: false,
267270
programmingLanguages: new Set(['javascript']),
271+
numberOfFilesInCustomerCodeZip: 1,
268272
codeDiffFiles: new Set(),
273+
filePathsInZip: new Set(['/test/file.js']),
269274
})
270275
sandbox.stub(codeReview as any, 'parseFindings').returns([])
271276

@@ -305,6 +310,7 @@ describe('CodeReview', () => {
305310
folderLevelArtifacts: [],
306311
ruleArtifacts: [],
307312
scopeOfReview: FULL_REVIEW,
313+
userRequirement: 'Test requirement',
308314
modelId: 'claude-4-sonnet',
309315
}
310316

@@ -428,6 +434,7 @@ describe('CodeReview', () => {
428434
folderLevelArtifacts: [],
429435
ruleArtifacts: [],
430436
scopeOfReview: FULL_REVIEW,
437+
userRequirement: 'Test requirement',
431438
modelId: 'claude-4-sonnet',
432439
}
433440

@@ -453,6 +460,7 @@ describe('CodeReview', () => {
453460
folderLevelArtifacts: [{ path: '/test/folder' }],
454461
ruleArtifacts: [],
455462
scopeOfReview: CODE_DIFF_REVIEW,
463+
userRequirement: 'Test requirement',
456464
modelId: 'claude-4-sonnet',
457465
}
458466

@@ -488,6 +496,7 @@ describe('CodeReview', () => {
488496
const ruleArtifacts: any[] = []
489497

490498
const result = await (codeReview as any).prepareFilesAndFoldersForUpload(
499+
'Test requirement',
491500
fileArtifacts,
492501
folderArtifacts,
493502
ruleArtifacts,
@@ -507,6 +516,7 @@ describe('CodeReview', () => {
507516
sandbox.stub(CodeReviewUtils, 'processArtifactWithDiff').resolves('diff content\n')
508517

509518
const result = await (codeReview as any).prepareFilesAndFoldersForUpload(
519+
'Test requirement',
510520
fileArtifacts,
511521
folderArtifacts,
512522
ruleArtifacts,
@@ -526,6 +536,7 @@ describe('CodeReview', () => {
526536

527537
try {
528538
await (codeReview as any).prepareFilesAndFoldersForUpload(
539+
'Test requirement',
529540
fileArtifacts,
530541
folderArtifacts,
531542
ruleArtifacts,
@@ -554,6 +565,7 @@ describe('CodeReview', () => {
554565
sandbox.stub(require('crypto'), 'randomUUID').returns('test-uuid-123')
555566

556567
await (codeReview as any).prepareFilesAndFoldersForUpload(
568+
'Test requirement',
557569
fileArtifacts,
558570
folderArtifacts,
559571
ruleArtifacts,
@@ -767,6 +779,7 @@ describe('CodeReview', () => {
767779
folderLevelArtifacts: [],
768780
ruleArtifacts: [],
769781
scopeOfReview: FULL_REVIEW,
782+
userRequirement: 'Test requirement',
770783
modelId: 'claude-4-sonnet',
771784
}
772785

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/qCodeAnalysis/codeReview.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class CodeReview {
3939
private static readonly CODE_ARTIFACT_PATH = 'code_artifact'
4040
private static readonly CUSTOMER_CODE_ZIP_NAME = 'customerCode.zip'
4141
private static readonly CODE_DIFF_PATH = 'code_artifact/codeDiff/customerCodeDiff.diff'
42+
private static readonly USER_REQUIREMENT_PATH = 'code_artifact/userRequirement/userRequirement.txt'
4243
private static readonly RULE_ARTIFACT_PATH = '.amazonq/rules'
4344
private static readonly MAX_POLLING_ATTEMPTS = 90 // 90 * POLLING_INTERVAL_MS (10000) = 15 mins
4445
private static readonly MID_POLLING_ATTEMPTS = 20
@@ -176,6 +177,7 @@ export class CodeReview {
176177

177178
// parse input
178179
const validatedInput = Z_CODE_REVIEW_INPUT_SCHEMA.parse(input)
180+
const userRequirement = validatedInput.userRequirement
179181
const fileArtifacts = validatedInput.fileLevelArtifacts || []
180182
const folderArtifacts = validatedInput.folderLevelArtifacts || []
181183
const ruleArtifacts = validatedInput.ruleArtifacts || []
@@ -204,9 +206,12 @@ export class CodeReview {
204206
const programmingLanguage = 'java'
205207
const scanName = 'Standard-' + randomUUID()
206208

207-
this.logging.info(`Agentic scan name: ${scanName} selectedModel: ${modelId}`)
209+
this.logging.info(
210+
`Agentic scan name: ${scanName} selectedModel: ${modelId} userRequirement: ${userRequirement}`
211+
)
208212

209213
return {
214+
userRequirement,
210215
fileArtifacts,
211216
folderArtifacts,
212217
isFullReviewRequest,
@@ -235,6 +240,7 @@ export class CodeReview {
235240
codeDiffFiles,
236241
filePathsInZip,
237242
} = await this.prepareFilesAndFoldersForUpload(
243+
setup.userRequirement,
238244
setup.fileArtifacts,
239245
setup.folderArtifacts,
240246
setup.ruleArtifacts,
@@ -603,6 +609,7 @@ export class CodeReview {
603609
* @returns An object containing the zip file buffer and its MD5 hash
604610
*/
605611
private async prepareFilesAndFoldersForUpload(
612+
userRequirement: string,
606613
fileArtifacts: FileArtifacts,
607614
folderArtifacts: FolderArtifacts,
608615
ruleArtifacts: RuleArtifacts,
@@ -660,6 +667,9 @@ export class CodeReview {
660667
codeArtifactZip.file(CodeReview.CODE_DIFF_PATH, codeDiff)
661668
}
662669

670+
// Add user requirement
671+
codeArtifactZip.file(CodeReview.USER_REQUIREMENT_PATH, userRequirement)
672+
663673
// Generate the final code artifact zip
664674
const zipBuffer = await CodeReviewUtils.generateZipBuffer(codeArtifactZip)
665675
CodeReviewUtils.logZipStructure(codeArtifactZip, 'Code artifact', this.logging)

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/qCodeAnalysis/codeReviewSchemas.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { FINDING_SEVERITY, SCOPE_OF_CODE_REVIEW } from './codeReviewConstants'
1212
export const CODE_REVIEW_INPUT_SCHEMA = {
1313
type: <const>'object',
1414
description: [
15-
'**3 main fields in the tool:**',
15+
'**4 main fields in the tool:**',
1616
'- scopeOfReview: CRITICAL - Must be set to either FULL_REVIEW (analyze entire file/folder/project/workspace) or CODE_DIFF_REVIEW (focus only on changes/modifications in the file/folder/project/workspace). This is a required field.',
17+
'- userRequirement: CRITICAL - Must be set as a string to describe the user requirement by analyzing the current conversation and extracting all the related information for code review. This is a required field.',
1718
'- fileLevelArtifacts: Array of specific files to review, each with absolute path. Use this when reviewing individual files, not folders. Format: [{"path": "/absolute/path/to/file.py"}]',
1819
'- folderLevelArtifacts: Array of folders to review, each with absolute path. Use this when reviewing entire directories, not individual files. Format: [{"path": "/absolute/path/to/folder/"}]',
1920
"Note: Either fileLevelArtifacts OR folderLevelArtifacts should be provided based on what's being reviewed, but not both for the same items.",
@@ -84,14 +85,15 @@ export const CODE_REVIEW_INPUT_SCHEMA = {
8485
},
8586
},
8687
},
87-
required: ['scopeOfReview'] as const,
88+
required: ['scopeOfReview', 'userRequirement'] as const,
8889
}
8990

9091
/**
9192
* Zod schema for input validation during execution of Code Review tool
9293
*/
9394
export const Z_CODE_REVIEW_INPUT_SCHEMA = z.object({
9495
scopeOfReview: z.enum(SCOPE_OF_CODE_REVIEW as [string, ...string[]]),
96+
userRequirement: z.string(),
9597
fileLevelArtifacts: z
9698
.array(
9799
z.object({

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/qCodeAnalysis/codeReviewTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum SuccessMetricName {
1414
}
1515

1616
export type ValidateInputAndSetupResult = {
17+
userRequirement: string
1718
fileArtifacts: FileArtifacts
1819
folderArtifacts: FolderArtifacts
1920
isFullReviewRequest: boolean

0 commit comments

Comments
 (0)