Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Language Servers for AWS

[![codecov](https://codecov.io/github/aws/language-servers/graph/badge.svg?token=ZSHpIVkG8S)](https://codecov.io/github/aws/language-servers)
[![Integration Tests](https://github.com/aws/language-servers/actions/workflows/integration-tests.yml/badge.svg)](https://github.com/aws/language-servers/actions/workflows/integration-tests.yml)

Language servers for integration with IDEs and Editors, which implement the protocol (LSP extensions) defined in the [language-server-runtimes](https://github.com/aws/language-server-runtimes/tree/main/runtimes) repo.

Expand Down
2 changes: 1 addition & 1 deletion chat-client/src/client/tabs/tabFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class TabFactory {
body: `<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 200px 0 20px 0;">

<div style="font-size: 24px; margin-bottom: 12px;"><strong>Amazon Q</strong></div>
<div style="background: rgba(255, 255, 255, 0.1); border-radius: 8px; padding: 8px; margin: 4px 0; text-align: center;">
<div style="background: rgba(128, 128, 128, 0.15); border: 1px solid rgba(128, 128, 128, 0.25); border-radius: 8px; padding: 8px; margin: 4px 0; text-align: center;">
<div style="font-size: 14px; margin-bottom: 4px;"><strong>Did you know?</strong></div>
<div>${this.getRandomTip()}</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/q-agentic-chat-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Integration tests for Q Agentic Chat Server",
"main": "out/index.js",
"scripts": {
"clean": "rm -rf out/ node_modules/ tsconfig.tsbuildinfo .tsbuildinfo",
"clean": "rimraf out/ node_modules/ tsconfig.tsbuildinfo .tsbuildinfo",
"compile": "tsc --build && cp -r src/tests/testFixture out/tests/",
"test-integ": "npm run compile && mocha --timeout 30000 \"./out/**/*.test.js\" --retries 2"
},
Expand All @@ -22,6 +22,7 @@
"jose": "^5.10.0",
"json-rpc-2.0": "^1.7.1",
"mocha": "^11.0.1",
"rimraf": "^3.0.2",
"typescript": "^5.0.0",
"yauzl-promise": "^4.0.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { JSONRPCEndpoint, LspClient } from './lspClient'
import { pathToFileURL } from 'url'
import * as crypto from 'crypto'
import { EncryptionInitialization } from '@aws/lsp-core'
import { authenticateServer, decryptObjectWithKey, encryptObjectWithKey } from './testUtils'
import { authenticateServer, decryptObjectWithKey, encryptObjectWithKey, normalizePath } from './testUtils'
import { ChatParams, ChatResult } from '@aws/language-server-runtimes/protocol'
import * as fs from 'fs'

Expand Down Expand Up @@ -172,7 +172,9 @@ describe('Q Agentic Chat Server Integration Tests', async () => {
msg => msg.type === 'tool' && msg.fileList?.rootFolderTitle === '1 file read'
)
expect(fsReadMessage).to.exist
expect(fsReadMessage?.fileList?.filePaths).to.include.members([path.join(rootPath, 'test.py')])
const expectedPath = path.join(rootPath, 'test.py')
const actualPaths = fsReadMessage?.fileList?.filePaths?.map(normalizePath) || []
expect(actualPaths).to.include.members([normalizePath(expectedPath)])
expect(fsReadMessage?.messageId?.startsWith('tooluse_')).to.be.true
})

Expand All @@ -192,7 +194,8 @@ describe('Q Agentic Chat Server Integration Tests', async () => {
msg => msg.type === 'tool' && msg.fileList?.rootFolderTitle === '1 directory listed'
)
expect(listDirectoryMessage).to.exist
expect(listDirectoryMessage?.fileList?.filePaths).to.include.members([rootPath])
const actualPaths = listDirectoryMessage?.fileList?.filePaths?.map(normalizePath) || []
expect(actualPaths).to.include.members([normalizePath(rootPath)])
expect(listDirectoryMessage?.messageId?.startsWith('tooluse_')).to.be.true
})

Expand All @@ -216,12 +219,17 @@ describe('Q Agentic Chat Server Integration Tests', async () => {
expect(executeBashMessage?.body).to.include('test.ts')
})

it('waits for user acceptance when executing mutable bash commands', async () => {
it('waits for user acceptance when executing mutable bash commands', async function () {
const command =
process.platform === 'win32'
? 'echo %date% > timestamp.txt && echo "Timestamp saved"'
: 'date > timestamp.txt && echo "Timestamp saved"'

const encryptedMessage = await encryptObjectWithKey<ChatParams>(
{
tabId,
prompt: {
prompt: `Run this command using the executeBash tool: \`date > timestamp.txt && echo "Timestamp saved"\``,
prompt: `Run this command using the executeBash tool: \`${command}\``,
},
},
encryptionKey
Expand Down Expand Up @@ -367,6 +375,7 @@ describe('Q Agentic Chat Server Integration Tests', async () => {
)
expect(fileSearchMessage).to.exist
expect(fileSearchMessage?.messageId?.startsWith('tooluse_')).to.be.true
expect(fileSearchMessage?.fileList?.filePaths).to.include.members([rootPath])
const actualPaths = fileSearchMessage?.fileList?.filePaths?.map(normalizePath) || []
expect(actualPaths).to.include.members([normalizePath(rootPath)])
})
})
10 changes: 10 additions & 0 deletions integration-tests/q-agentic-chat-server/src/tests/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UpdateCredentialsParams } from '@aws/language-server-runtimes/protocol'
import * as jose from 'jose'
import * as path from 'path'
import { JSONRPCEndpoint } from './lspClient'

/**
Expand Down Expand Up @@ -72,3 +73,12 @@ async function setProfile(endpoint: JSONRPCEndpoint, profileArn: string): Promis
settings: { profileArn },
})
}

/**
* Normalize paths for cross-platform comparison
* @param filePath - The file path to normalize
* @returns Normalized path with consistent casing
*/
export function normalizePath(filePath: string): string {
return path.resolve(filePath).toLowerCase()
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Will be deleted or merged.
*/

import * as crypto from 'crypto'

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "crypto"

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "crypto"
import * as path from 'path'

Check warning on line 7 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "path"

Check warning on line 7 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "path"
import * as os from 'os'

Check warning on line 8 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "os"

Check warning on line 8 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "os"
import {
ChatTriggerType,
Origin,
Expand Down Expand Up @@ -201,7 +201,10 @@
import { CommandCategory } from './tools/executeBash'
import { UserWrittenCodeTracker } from '../../shared/userWrittenCodeTracker'
import { CodeReview } from './tools/qCodeAnalysis/codeReview'
import { FINDINGS_MESSAGE_SUFFIX } from './tools/qCodeAnalysis/codeReviewConstants'
import {
CODE_REVIEW_FINDINGS_MESSAGE_SUFFIX,
DISPLAY_FINDINGS_MESSAGE_SUFFIX,
} from './tools/qCodeAnalysis/codeReviewConstants'
import { McpEventHandler } from './tools/mcp/mcpEventHandler'
import { enabledMCP, createNamespacedToolName } from './tools/mcp/mcpUtils'
import { McpManager } from './tools/mcp/mcpManager'
Expand All @@ -225,6 +228,7 @@
import { ActiveUserTracker } from '../../shared/activeUserTracker'
import { UserContext } from '../../client/token/codewhispererbearertokenclient'
import { CodeWhispererServiceToken } from '../../shared/codeWhispererService'
import { DisplayFindings } from './tools/qCodeAnalysis/displayFindings'

type ChatHandlers = Omit<
LspHandlers<Chat>,
Expand Down Expand Up @@ -1764,7 +1768,8 @@
break
}
case CodeReview.toolName:
// no need to write tool message for code review
case DisplayFindings.toolName:
// no need to write tool message for CodeReview or DisplayFindings
break
// — DEFAULT ⇒ Only MCP tools, but can also handle generic tool execution messages
default:
Expand Down Expand Up @@ -1940,11 +1945,27 @@
) {
await chatResultStream.writeResultBlock({
type: 'tool',
messageId: toolUse.toolUseId + FINDINGS_MESSAGE_SUFFIX,
messageId: toolUse.toolUseId + CODE_REVIEW_FINDINGS_MESSAGE_SUFFIX,
body: (codeReviewResult.output.content as any).findingsByFile,
})
}
break
case DisplayFindings.toolName:
// no need to write tool result for code review, this is handled by model via chat
// Push result in message so that it is picked by IDE plugin to show in issues panel
const displayFindingsResult = result as InvokeOutput
if (
displayFindingsResult?.output?.kind === 'json' &&
displayFindingsResult.output.success &&
displayFindingsResult.output.content !== undefined
) {
await chatResultStream.writeResultBlock({
type: 'tool',
messageId: toolUse.toolUseId + DISPLAY_FINDINGS_MESSAGE_SUFFIX,
body: JSON.stringify(displayFindingsResult.output.content),
})
}
break
// — DEFAULT ⇒ MCP tools
default:
await this.#handleMcpToolResult(toolUse, result, session, chatResultStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,17 @@ export class McpEventHandler {

try {
// Skip server config check for Built-in server
const serverConfig = McpManager.instance.getAllServerConfigs().get(serverName)
if (serverName !== 'Built-in') {
const serverConfig = McpManager.instance.getAllServerConfigs().get(serverName)
if (!serverConfig) {
throw new Error(`Server '${serverName}' not found`)
}
}

const mcpServerPermission = await this.#processPermissionUpdates(updatedPermissionConfig)
const mcpServerPermission = await this.#processPermissionUpdates(
updatedPermissionConfig,
serverConfig?.__configPath__
)

// Store the permission config instead of applying it immediately
this.#pendingPermissionConfig = {
Expand Down Expand Up @@ -1347,10 +1350,7 @@ export class McpEventHandler {
/**
* Processes permission updates from the UI
*/
async #processPermissionUpdates(updatedPermissionConfig: any) {
// Get the appropriate agent path
const agentPath = await this.#getAgentPath()

async #processPermissionUpdates(updatedPermissionConfig: any, agentPath: string | undefined) {
const perm: MCPServerPermission = {
enabled: true,
toolPerms: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const SKIP_DIRECTORIES = [
'temp',
]

export const FINDINGS_MESSAGE_SUFFIX = '_codeReviewFindings'
export const CODE_REVIEW_FINDINGS_MESSAGE_SUFFIX = '_codeReviewFindings'
export const DISPLAY_FINDINGS_MESSAGE_SUFFIX = '_displayFindings'

export const CODE_REVIEW_METRICS_PARENT_NAME = 'amazonq_codeReviewTool'
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ export class CodeReviewUtils {
return qCapabilities?.codeReviewInChat || false
}

/**
* Check if storing display findings in the Code Issues panel is enabled.
* @param params Initialize parameters from client
* @returns True if display findings is enabled, false otherwise
*/
public static isDisplayFindingsEnabled(params: InitializeParams | undefined): boolean {
const qCapabilities = params?.initializationOptions?.aws?.awsClientCapabilities?.q as
| QClientCapabilities
| undefined
return qCapabilities?.displayFindings || false
}

/**
* Converts a Windows absolute file path to Unix format and removes the drive letter
* @param windowsPath The Windows path to convert
Expand Down
Loading
Loading