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
8 changes: 7 additions & 1 deletion packages/kilo-vscode/tests/unit/path-mentions.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { describe, it, expect } from "bun:test"
import { convertToMentionPath, extractDropPaths } from "../../webview-ui/src/utils/path-mentions"
import { convertToMentionPath, extractDropPaths, insertPathMentions } from "../../webview-ui/src/utils/path-mentions"

it("inserts dropped mentions without replacing following text", () => {
expect(insertPathMentions("ab", 1, ["x", "y z"])).toEqual({ text: "a@x @y z b", pos: 9 })
expect(insertPathMentions("a ", 1, ["x"])).toEqual({ text: "a@x ", pos: 4 })
expect(insertPathMentions("", 0, [])).toEqual({ text: " ", pos: 1 })
})

describe("convertToMentionPath", () => {
it("converts an absolute path under cwd to a relative path", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { useImageAttachments, type ImageAttachment } from "../src/hooks/useImage
import { useSpeechToText } from "../src/components/speech-to-text/useSpeechToText"
import { useSpeechToTextModels } from "../src/context/speech-to-text-models"
import { createSpeechShortcut } from "../src/components/speech-to-text/shortcut"
import { convertToMentionPath } from "../src/utils/path-mentions"
import { convertToMentionPath, insertPathMentions } from "../src/utils/path-mentions"
import { insertSpacedText } from "../src/components/chat/prompt-input-utils"
import { useSlashCommand } from "../src/hooks/useSlashCommand"
import { WandSparkles } from "@kilocode/kilo-ui/lucide"
Expand Down Expand Up @@ -299,18 +299,12 @@ export const NewWorktreeDialog: Component<{
const resolved = paths.map((p) => convertToMentionPath(p, cwd))
const ref = textareaRef
if (!ref) return
const val = ref.value
const cursor = ref.selectionStart ?? val.length
const before = val.substring(0, cursor)
const after = val.substring(cursor)
const inserted = resolved.map((p) => `@${p}`).join(" ")
const result = before + inserted + " " + after
ref.value = result
const result = insertPathMentions(ref.value, ref.selectionStart ?? ref.value.length, resolved)
ref.value = result.text
cancel()
setPrompt(result)
persistPrompt(result)
const pos = cursor + inserted.length + 1
ref.setSelectionRange(pos, pos)
setPrompt(result.text)
persistPrompt(result.text)
ref.setSelectionRange(result.pos, result.pos)
ref.focus()
adjustHeight()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { useSpeechToText } from "../speech-to-text/useSpeechToText"
import { useSpeechToTextModels } from "../../context/speech-to-text-models"
import { createSpeechShortcut } from "../speech-to-text/shortcut"
import { useImageAttachments, type ImageAttachment } from "../../hooks/useImageAttachments"
import { convertToMentionPath } from "../../utils/path-mentions"
import { convertToMentionPath, insertPathMentions } from "../../utils/path-mentions"
import { SessionMentionPicker } from "./SessionMentionPicker"
import { WorktreeMentionPicker } from "./WorktreeMentionPicker"
import { usePromptHistory } from "../../hooks/usePromptHistory"
Expand Down Expand Up @@ -224,17 +224,11 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
const resolved = paths.map((p) => convertToMentionPath(p, cwd))
const ref = textareaRef
if (!ref) return
const val = ref.value
const cursor = ref.selectionStart ?? val.length
const before = val.substring(0, cursor)
const after = val.substring(cursor)
const inserted = resolved.map((p) => `@${p}`).join(" ")
const result = before + inserted + " " + after
ref.value = result
setText(result)
const result = insertPathMentions(ref.value, ref.selectionStart ?? ref.value.length, resolved)
ref.value = result.text
setText(result.text)
mention.addPaths(resolved, cwd)
const pos = cursor + inserted.length + 1
ref.setSelectionRange(pos, pos)
ref.setSelectionRange(result.pos, result.pos)
ref.focus()
adjustHeight()
})
Expand Down
5 changes: 5 additions & 0 deletions packages/kilo-vscode/webview-ui/src/utils/path-mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export function convertToMentionPath(path: string, cwd: string): string {
return cleaned
}

export function insertPathMentions(text: string, cursor: number, paths: string[]) {
const inserted = paths.map((path) => `@${path}`).join(" ") + " "
return { text: text.substring(0, cursor) + inserted + text.substring(cursor), pos: cursor + inserted.length }
}

/** Returns true when the line looks like a file URI or absolute path. */
function isFilePath(line: string): boolean {
if (line.startsWith("file://") || line.startsWith("vscode-remote://")) return true
Expand Down
12 changes: 0 additions & 12 deletions script/kilocode-duplication-allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,6 @@
"owner": "kilo-vscode",
"reason": "Existing duplication before the ratchet; remove through a focused, behavior-preserving extraction."
},
{
"files": [
"packages/kilo-vscode/webview-ui/agent-manager/NewWorktreeDialog.tsx",
"packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx"
],
"fingerprint": "0772e382c935aa93",
"maxMatches": 1,
"maxTokens": 122,
"kind": "legacy",
"owner": "kilo-vscode",
"reason": "Existing duplication before the ratchet; remove through a focused, behavior-preserving extraction."
},
{
"files": [
"packages/kilo-vscode/webview-ui/src/context/session-variant-store.ts",
Expand Down
Loading