Skip to content

Commit 5ef5cc7

Browse files
committed
fix(amazonq): use isInDirectory utility
1 parent e0106b3 commit 5ef5cc7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,12 +980,12 @@ export class ChatController {
980980
if (Array.isArray(prompts) && prompts.length > 0) {
981981
triggerPayload.additionalContextLengths = this.telemetryHelper.getContextLengths(prompts)
982982
for (const prompt of prompts.slice(0, 20)) {
983-
let description = prompt.description
984983
// Add system prompt for user prompts and workspace rules
985984
const contextType = this.telemetryHelper.getContextType(prompt)
986-
if (contextType === 'rule' || contextType === 'prompt') {
987-
description = `You must follow the instructions in ${prompt.relativePath}. Below are lines ${prompt.startLine}-${prompt.endLine} of this file:\n`
988-
}
985+
const description =
986+
contextType === 'rule' || contextType === 'prompt'
987+
? `You must follow the instructions in ${prompt.relativePath}. Below are lines ${prompt.startLine}-${prompt.endLine} of this file:\n`
988+
: prompt.description
989989
const entry = {
990990
name: prompt.name.substring(0, aditionalContentNameLimit),
991991
description: description.substring(0, aditionalContentNameLimit),

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { getSelectedCustomization } from '../../../codewhisperer/util/customizat
4343
import { undefinedIfEmpty } from '../../../shared/utilities/textUtilities'
4444
import { AdditionalContextPrompt } from '../../../amazonq/lsp/types'
4545
import { getUserPromptsDirectory, promptFileExtension } from '../../constants'
46+
import { isInDirectory } from '../../../shared/filesystemUtilities'
4647

4748
export function logSendTelemetryEventFailure(error: any) {
4849
let requestId: string | undefined
@@ -149,9 +150,9 @@ export class CWCTelemetryHelper {
149150

150151
public getContextType(prompt: AdditionalContextPrompt): string {
151152
if (prompt.filePath.endsWith(promptFileExtension)) {
152-
if (prompt.relativePath.startsWith(path.join('.amazonq', 'rules'))) {
153+
if (isInDirectory(path.join('.amazonq', 'rules'), prompt.relativePath)) {
153154
return 'rule'
154-
} else if (prompt.filePath.startsWith(getUserPromptsDirectory())) {
155+
} else if (isInDirectory(getUserPromptsDirectory(), prompt.filePath)) {
155156
return 'prompt'
156157
}
157158
}

0 commit comments

Comments
 (0)