Skip to content

Commit be2f397

Browse files
committed
Adding /scans functionality to Q chat which runs Project scans
1 parent 1d76c37 commit be2f397

File tree

8 files changed

+102
-2
lines changed

8 files changed

+102
-2
lines changed

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ export class Connector {
210210
})
211211
}
212212

213+
onRunSecurityScans = (tabID: string): void => {
214+
this.sendMessageToExtension({
215+
tabID: tabID,
216+
command: 'runProjectScan',
217+
chatMessage: 'Security scan started and you can see results in terminal',
218+
tabType: 'cwc',
219+
})
220+
}
221+
213222
private sendTriggerMessageProcessed = async (requestID: any): Promise<void> => {
214223
this.sendMessageToExtension({
215224
command: 'trigger-message-processed',

packages/core/src/amazonq/webview/ui/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ type MessageCommand =
3131
| 'file-click'
3232
| 'form-action-click'
3333
| 'open-settings'
34+
| 'runProjectScan'
3435

3536
export type ExtensionMessage = Record<string, any> & { command: MessageCommand }

packages/core/src/amazonq/webview/ui/connector.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ export class Connector {
151151
this.gumbyChatConnector.transform(tabID)
152152
}
153153

154+
scan = (tabID: string): void => {
155+
switch (this.tabsStorage.getTab(tabID)?.type) {
156+
case 'cwc':
157+
this.cwChatConnector.onRunSecurityScans(tabID)
158+
break
159+
}
160+
// this.cwChatConnector.onRunSecurityScans(tabID)
161+
}
162+
154163
handleMessageReceive = async (message: MessageEvent): Promise<void> => {
155164
if (message.data === undefined) {
156165
return

packages/core/src/amazonq/webview/ui/quickActions/generator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class QuickActionGenerator {
4242
},
4343
]
4444
: []),
45+
{
46+
command: '/scan',
47+
description: 'Run a project scan',
48+
},
4549
],
4650
},
4751
{
@@ -71,11 +75,11 @@ export class QuickActionGenerator {
7175
},
7276
featuredev: {
7377
description: "This command isn't available in /dev",
74-
unavailableItems: ['/dev', '/transform', '/help', '/clear'],
78+
unavailableItems: ['/dev', '/transform', '/help', '/clear', '/scan'],
7579
},
7680
gumby: {
7781
description: "This command isn't available in /transform",
78-
unavailableItems: ['/dev', '/transform'],
82+
unavailableItems: ['/dev', '/transform', '/scan'],
7983
},
8084
unknown: {
8185
description: '',

packages/core/src/amazonq/webview/ui/quickActions/handler.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export class QuickActionHandler {
5252
case '/clear':
5353
this.handleClearCommand(tabID)
5454
break
55+
case '/scan':
56+
this.handleSecurityScansCommand(tabID)
57+
break
5558
}
5659
}
5760

@@ -169,4 +172,61 @@ export class QuickActionHandler {
169172
}
170173
}
171174
}
175+
176+
private handleSecurityScansCommand(tabID: string) {
177+
if (this.tabsStorage.getTab(tabID)?.type === 'unknown') {
178+
this.tabsStorage.updateTabTypeFromUnknown(tabID, 'cwc')
179+
}
180+
// this.connector.scan(tabID)
181+
this.connector.scan(tabID)
182+
183+
/*
184+
let scanTabId: string | undefined = undefined
185+
186+
this.tabsStorage.getTabs().forEach((tab) => {
187+
if (tab.type === 'scan') {
188+
scanTabId = tab.id
189+
}
190+
})
191+
192+
if (scanTabId !== undefined) {
193+
this.mynahUI.selectTab(scanTabId, eventId || '')
194+
this.connector.onTabChange(scanTabId)
195+
return
196+
}
197+
198+
let affectedTabId: string | undefined = tabID
199+
// if there is no scan tab, open a new one
200+
if (this.tabsStorage.getTab(affectedTabId)?.type !== 'unknown') {
201+
affectedTabId = this.mynahUI.updateStore('', {
202+
loadingChat: true,
203+
})
204+
}
205+
206+
if (affectedTabId === undefined) {
207+
this.mynahUI.notify({
208+
content: uiComponentsTexts.noMoreTabsTooltip,
209+
type: NotificationType.WARNING,
210+
})
211+
return
212+
} else {
213+
this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'scan')
214+
this.connector.onKnownTabOpen(affectedTabId)
215+
this.connector.onUpdateTabType(affectedTabId)
216+
217+
// reset chat history
218+
this.mynahUI.updateStore(affectedTabId, {
219+
chatItems: [],
220+
})
221+
222+
this.mynahUI.updateStore(affectedTabId, this.tabDataGenerator.getTabData('scan', true, undefined))
223+
224+
// disable chat prompt
225+
this.mynahUI.updateStore(affectedTabId, {
226+
loadingChat: true,
227+
})
228+
229+
this.connector.scan(affectedTabId)
230+
}*/
231+
}
172232
}

packages/core/src/amazonq/webview/ui/storages/tabsStorage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
export type TabStatus = 'free' | 'busy' | 'dead'
7+
// export type TabType = 'cwc' | 'featuredev' | 'gumby' | 'unknown' | 'scan'
78
export type TabType = 'cwc' | 'featuredev' | 'gumby' | 'unknown'
89
export type TabOpenType = 'click' | 'contextMenu' | 'hotkeys'
910

packages/core/src/amazonq/webview/ui/tabs/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const commonTabData: TabTypeData = {
2121
export const TabTypeDataMap: Record<TabType, TabTypeData> = {
2222
unknown: commonTabData,
2323
cwc: commonTabData,
24+
// scan:commonTabData,
2425
featuredev: {
2526
title: 'Q - Dev',
2627
placeholder: 'Describe your task or issue in as much detail as possible',
@@ -37,4 +38,9 @@ To get started, describe the task you are trying to accomplish.`,
3738
3839
I can help you upgrade your Java 8 and 11 codebases to Java 17.`,
3940
},
41+
// scan: {
42+
// title: 'Q Security Scans',
43+
// placeholder: 'Open a new Tab to run security scans',
44+
// welcome: `Welcome to Security scans!`,
45+
// }
4046
}

packages/core/src/codewhispererChat/view/messages/messageListener.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { ChatControllerMessagePublishers } from '../../controllers/chat/controll
99
import { ReferenceLogController } from './referenceLogController'
1010
import { getLogger } from '../../../shared/logger'
1111
import { openSettingsId } from '../../../shared/settings'
12+
import { showSecurityScan } from '../../../codewhisperer/commands/basicCommands'
13+
import { placeholder } from '../../../shared/vscode/commands2'
14+
import { cwQuickPickSource } from '../../../codewhisperer/commands/types'
1215

1316
export interface UIMessageListenerProps {
1417
readonly chatControllerMessagePublishers: ChatControllerMessagePublishers
@@ -95,8 +98,15 @@ export class UIMessageListener {
9598
case 'footer-info-link-click':
9699
this.processFooterInfoLinkClick(msg)
97100
break
101+
case 'runProjectScan':
102+
showSecurityScan.execute(placeholder, cwQuickPickSource)
103+
// void vscode.window.setStatusBarMessage('Got Message from Chat')
104+
// this.processChatMessage(msg)
105+
break
98106
case 'open-settings':
99107
this.processOpenSettings(msg)
108+
// this.processOpenSettings(msg)
109+
// void vscode.window.setStatusBarMessage('Got Message from Chat')
100110
}
101111
}
102112

0 commit comments

Comments
 (0)