Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/mention-query-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Keep the `@` mention list open while typing spaces, so names with spaces are searchable — files such as `@my report.txt`, entries like `@past chats` and `@git changes`, and past chats by title directly in the list.
122 changes: 122 additions & 0 deletions packages/kilo-vscode/tests/unit/file-mention-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getPastChatsMentionResult,
isCursorAtMentionEnd,
findMentionRange,
mentionSettled,
sessionMentionFilename,
sessionMentionText,
sessionMentionToken,
Expand All @@ -20,7 +21,11 @@ import {
PAST_CHATS_RESULT,
TERMINAL_RESULT,
GIT_CHANGES_RESULT,
WORKTREES_RESULT,
} from "../../webview-ui/src/hooks/file-mention-utils"
import type { MentionResult } from "../../webview-ui/src/hooks/file-mention-utils"
import { TERMINAL_MENTION } from "../../webview-ui/src/hooks/terminal-context-utils"
import { GIT_CHANGES_MENTION } from "../../webview-ui/src/hooks/git-changes-context-utils"

describe("AT_PATTERN", () => {
it("matches @mention at start of string", () => {
Expand All @@ -40,6 +45,26 @@ describe("AT_PATTERN", () => {
expect(match?.[1]).toBe("path/to/file.ts")
})

it("captures spaces in an in-progress mention query", () => {
const match = "hello @my report".match(AT_PATTERN)
expect(match?.[1]).toBe("my report")
})

it("starts a new query at the latest mention instead of swallowing an earlier one", () => {
const match = "see @src/a.ts and @my rep".match(AT_PATTERN)
expect(match?.[1]).toBe("my rep")
})

it("keeps an @ that is part of a scoped path inside the query", () => {
const match = "@node_modules/@types/node".match(AT_PATTERN)
expect(match?.[1]).toBe("node_modules/@types/node")
})

it("does not span a newline", () => {
const match = "@src/a.ts\nnext line".match(AT_PATTERN)
expect(match).toBeNull()
})

it("matches empty @", () => {
expect(AT_PATTERN.test("@")).toBe(true)
})
Expand Down Expand Up @@ -102,6 +127,28 @@ describe("buildMentionResults", () => {
FILE_PICKER_RESULT,
])
})

it.each([
["past chats", PAST_CHATS_RESULT],
["past ch", PAST_CHATS_RESULT],
["git changes", GIT_CHANGES_RESULT],
["git ch", GIT_CHANGES_RESULT],
])("finds the %s entry from a spaced query", (query, expected) => {
expect(buildMentionResults(query as string, [])).toContainEqual(expected)
})

it("finds worktree references from a spaced query", () => {
const result = buildMentionResults("search work", [], true, true)
expect(result).toContainEqual(WORKTREES_RESULT)
})

it("ranks matching past chats between the special entries and the files", () => {
const session = { id: "ses_a", title: "Fix auth bug", updated: 1 }
const result = buildMentionResults("fix auth", ["src/auth.ts"], true, false, [
{ type: "session", value: "Fix auth bug", session },
])
expect(result.map((item) => item.type)).toEqual(["session", "file", "file-picker"])
})
})

describe("filterMentionResults", () => {
Expand All @@ -118,6 +165,19 @@ describe("filterMentionResults", () => {
const result = filterMentionResults("zz", [FILE_PICKER_RESULT])
expect(result).toEqual([FILE_PICKER_RESULT])
})

it("keeps the special entries for spaced queries that spell their labels", () => {
const items = [TERMINAL_RESULT, GIT_CHANGES_RESULT, PAST_CHATS_RESULT, WORKTREES_RESULT]
expect(filterMentionResults("git changes", items)).toEqual([GIT_CHANGES_RESULT])
expect(filterMentionResults("past chats", items)).toEqual([PAST_CHATS_RESULT])
})

it("matches past chats by title, ignoring separator differences", () => {
const session = { id: "ses_a", title: "Fix auth bug", updated: 1 }
const items: MentionResult[] = [{ type: "session", value: "Fix auth bug", session }]
expect(filterMentionResults("auth bug", items)).toEqual(items)
expect(filterMentionResults("nothing", items)).toEqual([])
})
})

describe("filterSessions", () => {
Expand Down Expand Up @@ -617,6 +677,15 @@ describe("session mentions", () => {
it("hides the picker for unrelated queries", () => {
expect(getPastChatsMentionResult("index")).toEqual([])
})

it("offers the picker for its spaced label", () => {
expect(getPastChatsMentionResult("past chats")).toEqual([PAST_CHATS_RESULT])
expect(getPastChatsMentionResult("Past Ch")).toEqual([PAST_CHATS_RESULT])
})

it("still hides the picker once a spaced query stops matching", () => {
expect(getPastChatsMentionResult("past chats and more")).toEqual([])
})
})

describe("sessionMentionText / filename", () => {
Expand Down Expand Up @@ -652,6 +721,59 @@ describe("session mentions", () => {
})
})

describe("mentionSettled", () => {
const tokens = new Set(["my file.txt", "src/a.ts"])

it("reports the inserted mention followed by prose", () => {
expect(mentionSettled("my file.txt and then", "my file.txt", tokens)).toBe(true)
})

it("reports the inserted mention followed by a single space", () => {
expect(mentionSettled("src/a.ts ", "src/a.ts", tokens)).toBe(true)
})

it("treats a prefix of the inserted mention as an edit in progress", () => {
expect(mentionSettled("my file", "my file.txt", tokens)).toBe(false)
})

it("treats the exact inserted mention as an edit in progress", () => {
expect(mentionSettled("my file.txt", "my file.txt", tokens)).toBe(false)
})

it("does not report a longer path that merely starts like the inserted one", () => {
expect(mentionSettled("src/a.tsx", "src/a.ts", tokens)).toBe(false)
})

it("reports nothing when no mention was inserted at this @", () => {
expect(mentionSettled("my file.txt and then", undefined, tokens)).toBe(false)
})

it("does not settle on a short known path that only prefixes a new query", () => {
// "my" lingers in the sticky known set from an earlier mention; typing a
// longer, unrelated path that starts with it must keep searching.
expect(mentionSettled("my report.txt", undefined, new Set(["my"]))).toBe(false)
})

it("keeps searching while the query still grows toward a longer known path", () => {
const known = new Set(["my", "my report.txt"])
expect(mentionSettled("my report", "my", known)).toBe(false)
})

it("settles once the query passes every known path it could complete", () => {
const known = new Set(["my", "my report.txt"])
expect(mentionSettled("my report.txt and then", "my", known)).toBe(true)
})

it("reports inserted builtin mentions", () => {
expect(mentionSettled("terminal what failed", TERMINAL_MENTION, new Set())).toBe(true)
expect(mentionSettled("git-changes review", GIT_CHANGES_MENTION, new Set())).toBe(true)
})

it("reports nothing for an unrelated query", () => {
expect(mentionSettled("some other thing", "my file.txt", tokens)).toBe(false)
})
})

describe("filterMentionResults", () => {
it("keeps the past-chats picker for alias queries", () => {
const filtered = filterMentionResults("sess", buildMentionResults("", []))
Expand Down
89 changes: 48 additions & 41 deletions packages/kilo-vscode/tests/unit/session-provider-activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,52 @@ const webview = path.join(root, "webview-ui")
const fixture = path.join(root, "tests/fixtures/session-provider-activity.tsx")

describe("SessionProvider activity", () => {
it("covers real session activity lifecycle messages", async () => {
const solid = path.dirname(Bun.resolveSync("solid-js/package.json", webview))
const aliases: Record<string, string> = {
"solid-js": path.join(solid, "dist/solid.js"),
"solid-js/web": path.join(solid, "web/dist/web.js"),
"solid-js/store": path.join(solid, "store/dist/store.js"),
}
const dedupe = {
name: "solid-dedupe",
setup(ctx: Parameters<NonNullable<Parameters<typeof build>[0]["plugins"]>[number]["setup"]>[0]) {
ctx.onResolve({ filter: /^solid-js(\/web|\/store)?$/ }, (args) => ({ path: aliases[args.path] }))
ctx.onResolve({ filter: /\?worker&url$/ }, (args) => ({ path: args.path, namespace: "worker-url" }))
ctx.onLoad({ filter: /.*/, namespace: "worker-url" }, () => ({
contents: "export default undefined",
loader: "js",
}))
},
}
const result = await build({
entryPoints: [fixture],
bundle: true,
conditions: ["browser"],
external: ["happy-dom"],
format: "esm",
logLevel: "silent",
loader: { ".css": "empty", ".svg": "dataurl" },
platform: "node",
plugins: [dedupe, solidPlugin()],
target: "es2022",
write: false,
})
const file = path.join(root, `.session-provider-activity-${crypto.randomUUID()}.mjs`)
await Bun.write(file, result.outputFiles[0]!.contents)
try {
const child = Bun.spawnSync(["bun", file], { cwd: webview, stdout: "pipe", stderr: "pipe" })
const output = child.stdout.toString() + child.stderr.toString()
expect(child.exitCode, output).toBe(0)
} finally {
unlinkSync(file)
}
})
// Bundling the fixture's whole webview graph and running it in a spawned
// process regularly costs more than the 5s default budget, so the timeout is
// explicit rather than left to chance.
it(
"covers real session activity lifecycle messages",
async () => {
const solid = path.dirname(Bun.resolveSync("solid-js/package.json", webview))
const aliases: Record<string, string> = {
"solid-js": path.join(solid, "dist/solid.js"),
"solid-js/web": path.join(solid, "web/dist/web.js"),
"solid-js/store": path.join(solid, "store/dist/store.js"),
}
const dedupe = {
name: "solid-dedupe",
setup(ctx: Parameters<NonNullable<Parameters<typeof build>[0]["plugins"]>[number]["setup"]>[0]) {
ctx.onResolve({ filter: /^solid-js(\/web|\/store)?$/ }, (args) => ({ path: aliases[args.path] }))
ctx.onResolve({ filter: /\?worker&url$/ }, (args) => ({ path: args.path, namespace: "worker-url" }))
ctx.onLoad({ filter: /.*/, namespace: "worker-url" }, () => ({
contents: "export default undefined",
loader: "js",
}))
},
}
const result = await build({
entryPoints: [fixture],
bundle: true,
conditions: ["browser"],
external: ["happy-dom"],
format: "esm",
logLevel: "silent",
loader: { ".css": "empty", ".svg": "dataurl" },
platform: "node",
plugins: [dedupe, solidPlugin()],
target: "es2022",
write: false,
})
const file = path.join(root, `.session-provider-activity-${crypto.randomUUID()}.mjs`)
await Bun.write(file, result.outputFiles[0]!.contents)
try {
const child = Bun.spawnSync(["bun", file], { cwd: webview, stdout: "pipe", stderr: "pipe" })
const output = child.stdout.toString() + child.stderr.toString()
expect(child.exitCode, output).toBe(0)
} finally {
unlinkSync(file)
}
},
{ timeout: 120000 },
)
})
Loading