Skip to content

Commit 9e5bc76

Browse files
Merge main into feature/eclipse-auth
2 parents 242a940 + ae7d3fc commit 9e5bc76

25 files changed

Lines changed: 49 additions & 957 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:09b75b788854e2c2f08b9fa73c671e476f7e20b8284521f544ea7f2e2c82d3fa
3-
size 96549602
2+
oid sha256:f59a63572dbadb648fe60741b41d929cbd2735a72312fedd07dc37bf9b9a78e8
3+
size 3080924
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f13048f6989d01f8a5b8d9743ca2efa023cc4ae0c05efcd4fc0cb22f4b2dd5c3
3-
size 98233434
2+
oid sha256:f59a63572dbadb648fe60741b41d929cbd2735a72312fedd07dc37bf9b9a78e8
3+
size 3080924
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6e119ae06538b7bfe7ce0050d88909c64989b10c481477e24bdd6ab9f6152846
3-
size 102483123
2+
oid sha256:f59a63572dbadb648fe60741b41d929cbd2735a72312fedd07dc37bf9b9a78e8
3+
size 3080924
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:8aea05af87c620a7be4cb58b4b9b1a579e5726b1eb3682e55c42302ff19d853d
3-
size 114470426
2+
oid sha256:f59a63572dbadb648fe60741b41d929cbd2735a72312fedd07dc37bf9b9a78e8
3+
size 3080924
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:aafb3ef97fca6ba0369f7bfc48b5846e2b4f4fdec0014aae58be70f49cc42116
3-
size 113755807
2+
oid sha256:f59a63572dbadb648fe60741b41d929cbd2735a72312fedd07dc37bf9b9a78e8
3+
size 3080924

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,7 @@ describe('AgenticChatController', () => {
257257
} as any // Using 'as any' to prevent type errors when the Agent interface is updated with new methods
258258

259259
additionalContextProviderStub = sinon.stub(AdditionalContextProvider.prototype, 'getAdditionalContext')
260-
additionalContextProviderStub.callsFake(async (triggerContext, _, context: ContextCommand[]) => {
261-
// When @workspace is in the context, set hasWorkspace flag
262-
if (context && context.some(item => item.command === '@workspace')) {
263-
triggerContext.hasWorkspace = true
264-
}
260+
additionalContextProviderStub.callsFake(async () => {
265261
return []
266262
})
267263
// @ts-ignore
@@ -1415,60 +1411,6 @@ describe('AgenticChatController', () => {
14151411
extractDocumentContextStub.restore()
14161412
})
14171413

1418-
it('parses relevant document and includes as requestInput if @workspace context is included', async () => {
1419-
const localProjectContextController = new LocalProjectContextController('client-name', [], logging)
1420-
const mockRelevantDocs = [
1421-
{ filePath: '/test/1.ts', content: 'text', id: 'id-1', index: 0, vec: [1] },
1422-
{ filePath: '/test/2.ts', content: 'text2', id: 'id-2', index: 0, vec: [1] },
1423-
]
1424-
1425-
sinon.stub(LocalProjectContextController, 'getInstance').resolves(localProjectContextController)
1426-
sinon.stub(localProjectContextController, 'isIndexingEnabled').returns(true)
1427-
sinon.stub(localProjectContextController, 'queryVectorIndex').resolves(mockRelevantDocs)
1428-
1429-
await chatController.onChatPrompt(
1430-
{
1431-
tabId: 'tab',
1432-
prompt: {
1433-
prompt: '@workspace help me understand this code',
1434-
escapedPrompt: '@workspace help me understand this code',
1435-
},
1436-
context: [{ command: '@workspace' }],
1437-
},
1438-
mockCancellationToken
1439-
)
1440-
1441-
const calledRequestInput: GenerateAssistantResponseCommandInput =
1442-
generateAssistantResponseStub.firstCall.firstArg
1443-
1444-
assert.deepStrictEqual(
1445-
calledRequestInput.conversationState?.currentMessage?.userInputMessage?.userInputMessageContext
1446-
?.editorState,
1447-
{
1448-
workspaceFolders: [],
1449-
relevantDocuments: [
1450-
{
1451-
endLine: -1,
1452-
path: '/test/1.ts',
1453-
relativeFilePath: '1.ts',
1454-
startLine: -1,
1455-
text: 'text',
1456-
type: ContentType.WORKSPACE,
1457-
},
1458-
{
1459-
endLine: -1,
1460-
path: '/test/2.ts',
1461-
relativeFilePath: '2.ts',
1462-
startLine: -1,
1463-
text: 'text2',
1464-
type: ContentType.WORKSPACE,
1465-
},
1466-
],
1467-
useRelevantDocuments: true,
1468-
}
1469-
)
1470-
})
1471-
14721414
it('leaves cursorState as undefined if cursorState is not passed', async () => {
14731415
const documentContextObject = {
14741416
programmingLanguage: 'typescript',

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3537,7 +3537,6 @@ export class AgenticChatController implements ChatHandlers {
35373537
if (triggerContext.contextInfo) {
35383538
metric.mergeWith({
35393539
cwsprChatHasContextList: triggerContext.documentReference?.filePaths?.length ? true : false,
3540-
cwsprChatHasWorkspaceContext: triggerContext.hasWorkspace ?? false,
35413540
cwsprChatFolderContextCount: triggerContext.contextInfo.contextCount.folderContextCount,
35423541
cwsprChatFileContextCount: triggerContext.contextInfo.contextCount.fileContextCount,
35433542
cwsprChatRuleContextCount: triggerContext.contextInfo.contextCount.activeRuleContextCount,

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/additionalContextProvider.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,27 +326,6 @@ describe('AdditionalContextProvider', () => {
326326
assert.strictEqual(triggerContext.cursorState, undefined)
327327
})
328328

329-
it('should set hasWorkspace flag when @workspace is present', async () => {
330-
const mockWorkspaceFolder = {
331-
uri: URI.file('/workspace').toString(),
332-
name: 'test',
333-
}
334-
sinon.stub(workspaceUtils, 'getWorkspaceFolderPaths').returns(['/workspace'])
335-
const triggerContext: TriggerContext = {
336-
workspaceFolder: mockWorkspaceFolder,
337-
}
338-
339-
const workspaceContext = [{ id: '@workspace', command: 'Workspace', label: 'folder' }]
340-
;(chatHistoryDb.getPinnedContext as sinon.SinonStub).returns(workspaceContext)
341-
342-
fsExistsStub.resolves(false)
343-
getContextCommandPromptStub.resolves([])
344-
345-
await provider.getAdditionalContext(triggerContext, 'tab1')
346-
347-
assert.strictEqual(triggerContext.hasWorkspace, true)
348-
})
349-
350329
it('should count context types correctly', async () => {
351330
const mockWorkspaceFolder = {
352331
uri: URI.file('/workspace').toString(),

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/additionalContextProvider.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,6 @@ export class AdditionalContextProvider {
436436
contextInfo = contextInfo.filter(item => item.id !== ACTIVE_EDITOR_CONTEXT_ID)
437437
}
438438

439-
if (contextInfo.some(item => item.id === '@workspace')) {
440-
triggerContext.hasWorkspace = true
441-
}
442439
// Handle code symbol ID mismatches between indexing sessions
443440
// When a workspace is re-indexed, code symbols receive new IDs
444441
// If a pinned symbol's ID is no longer found in the current index:
@@ -609,8 +606,19 @@ export class AdditionalContextProvider {
609606
const image = imageMap.get(item.description)
610607
if (image) ordered.push(image)
611608
} else {
612-
const doc = item.route ? docMap.get(path.join(...item.route)) : undefined
613-
if (doc) ordered.push(doc)
609+
const itemPath = item.route ? path.join(...item.route) : undefined
610+
if (itemPath) {
611+
const doc = docMap.get(itemPath)
612+
if (doc) {
613+
ordered.push(doc)
614+
} else if (item.label === 'folder') {
615+
// Folder expands into multiple file entries — match all children
616+
const children = docEntries.filter(
617+
entry => !entry.pinned && entry.path.startsWith(itemPath + path.sep)
618+
)
619+
ordered.push(...children)
620+
}
621+
}
614622
}
615623
}
616624
// Append pinned context entries (docs and images)

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/agenticChatTriggerContext.ts

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
EnvState,
1515
Origin,
1616
ImageBlock,
17+
RelevantTextDocument,
1718
} from '@amzn/codewhisperer-streaming'
1819
import {
1920
BedrockTools,
@@ -22,18 +23,15 @@ import {
2223
InlineChatParams,
2324
FileList,
2425
TextDocument,
25-
OPEN_WORKSPACE_INDEX_SETTINGS_BUTTON_ID,
2626
} from '@aws/language-server-runtimes/server-interface'
2727
import { Features } from '../../types'
2828
import { DocumentContext, DocumentContextExtractor } from '../../chat/contexts/documentContext'
2929
import { workspaceUtils } from '@aws/lsp-core'
3030
import { URI } from 'vscode-uri'
31-
import { LocalProjectContextController } from '../../../shared/localProjectContextController'
3231
import * as path from 'path'
33-
import { RelevantTextDocument } from '@amzn/codewhisperer-streaming'
3432
import { languageByExtension } from '../../../shared/languageDetection'
3533
import { AgenticChatResultStream } from '../agenticChatResultStream'
36-
import { ContextInfo, mergeFileLists, mergeRelevantTextDocuments } from './contextUtils'
34+
import { ContextInfo } from './contextUtils'
3735
import { WorkspaceFolderManager } from '../../workspaceContext/workspaceFolderManager'
3836
import { getRelativePathWithWorkspaceFolder } from '../../workspaceContext/util'
3937
import { ChatCommandInput } from '../../../shared/streamingClientService'
@@ -47,7 +45,6 @@ export interface TriggerContext extends Partial<DocumentContext> {
4745
* Represents the context transparency list displayed at the top of the assistant response.
4846
*/
4947
documentReference?: FileList
50-
hasWorkspace?: boolean
5148
}
5249
export type LineInfo = { startLine: number; endLine: number }
5350

@@ -178,7 +175,6 @@ export class AgenticChatTriggerContext {
178175
const { prompt } = params
179176
const workspaceFolders = workspaceUtils.getWorkspaceFolderPaths(this.#workspace).slice(0, maxWorkspaceFolders)
180177
const defaultEditorState = { workspaceFolders }
181-
const hasWorkspace = triggerContext.hasWorkspace
182178

183179
// prompt.prompt is what user typed in the input, should be sent to backend
184180
// prompt.escapedPrompt is HTML serialized string, which should only be used for UI.
@@ -190,10 +186,6 @@ export class AgenticChatTriggerContext {
190186
promptContent = promptContent.replace(/\*\*@sage\*\*/g, '@sage')
191187
}
192188

193-
if (hasWorkspace) {
194-
promptContent = promptContent?.replace(/\*\*@workspace\*\*/, '')
195-
}
196-
197189
// Append remote workspaceId if it exists
198190
// Only append workspaceId to GenerateCompletions when WebSocket client is connected
199191
const remoteWsFolderManager = WorkspaceFolderManager.getInstance()
@@ -204,15 +196,7 @@ export class AgenticChatTriggerContext {
204196
undefined
205197
this.#logging.info(`remote workspaceId: ${workspaceId}`)
206198

207-
// Get workspace documents if @workspace is used
208-
let relevantDocuments = hasWorkspace
209-
? await this.#getRelevantDocuments(promptContent ?? '', chatResultStream)
210-
: []
211-
212-
const workspaceFileList = mergeRelevantTextDocuments(relevantDocuments)
213-
triggerContext.documentReference = triggerContext.documentReference
214-
? mergeFileLists(triggerContext.documentReference, workspaceFileList)
215-
: workspaceFileList
199+
const relevantDocuments: RelevantTextDocumentAddition[] = []
216200
// Add @context in prompt to relevantDocuments
217201
if (additionalContent) {
218202
for (const item of additionalContent.filter(item => !item.pinned)) {
@@ -444,81 +428,4 @@ export class AgenticChatTriggerContext {
444428

445429
return [...uris]
446430
}
447-
448-
async #getRelevantDocuments(
449-
prompt: string,
450-
chatResultStream?: AgenticChatResultStream
451-
): Promise<RelevantTextDocumentAddition[]> {
452-
const localProjectContextController = await LocalProjectContextController.getInstance()
453-
if (!localProjectContextController.isIndexingEnabled() && chatResultStream) {
454-
await chatResultStream.writeResultBlock({
455-
body: `To add your workspace as context, enable local indexing in your IDE settings. After enabling, add @workspace to your question, and I'll generate a response using your workspace as context.`,
456-
buttons: [
457-
{
458-
id: OPEN_WORKSPACE_INDEX_SETTINGS_BUTTON_ID,
459-
text: 'Open settings',
460-
icon: 'external',
461-
keepCardAfterClick: false,
462-
status: 'info',
463-
},
464-
],
465-
})
466-
return []
467-
}
468-
469-
let relevantTextDocuments = await this.#queryRelevantDocuments(prompt, localProjectContextController)
470-
relevantTextDocuments = relevantTextDocuments.filter(doc => doc.text && doc.text.length > 0)
471-
for (const relevantDocument of relevantTextDocuments) {
472-
if (relevantDocument.text && relevantDocument.text.length > workspaceChunkMaxSize) {
473-
relevantDocument.text = relevantDocument.text.substring(0, workspaceChunkMaxSize)
474-
this.#logging.debug(`Truncating @workspace chunk: ${relevantDocument.relativeFilePath} `)
475-
}
476-
}
477-
478-
return relevantTextDocuments
479-
}
480-
481-
async #queryRelevantDocuments(
482-
prompt: string,
483-
localProjectContextController: LocalProjectContextController
484-
): Promise<RelevantTextDocumentAddition[]> {
485-
try {
486-
const chunks = await localProjectContextController.queryVectorIndex({ query: prompt })
487-
const relevantTextDocuments: RelevantTextDocumentAddition[] = []
488-
if (!chunks) {
489-
return relevantTextDocuments
490-
}
491-
492-
for (const chunk of chunks) {
493-
const text = chunk.context ?? chunk.content
494-
const baseDocument = {
495-
text,
496-
path: chunk.filePath,
497-
relativeFilePath: chunk.relativePath ?? path.basename(chunk.filePath),
498-
startLine: chunk.startLine ?? -1,
499-
endLine: chunk.endLine ?? -1,
500-
}
501-
502-
if (chunk.programmingLanguage && chunk.programmingLanguage !== 'unknown') {
503-
relevantTextDocuments.push({
504-
...baseDocument,
505-
programmingLanguage: {
506-
languageName: chunk.programmingLanguage,
507-
},
508-
type: ContentType.WORKSPACE,
509-
})
510-
} else {
511-
relevantTextDocuments.push({
512-
...baseDocument,
513-
type: ContentType.WORKSPACE,
514-
})
515-
}
516-
}
517-
518-
return relevantTextDocuments
519-
} catch (e) {
520-
this.#logging.error(`Error querying query vector index to get relevant documents: ${e}`)
521-
return []
522-
}
523-
}
524431
}

0 commit comments

Comments
 (0)