Compare commits

...
Author SHA1 Message Date
l0ng-ai 03086ce1dc feat(agents): search the task list
A search field above the Agents task list (and the session history popup) filters tasks as you type: fuzzy on the title, with the matched characters highlighted, and by word start on the project folder and branch. The search looks into every section, collapsed ones like Archived included, and hides sections without a match; Up/Down move the selection, Enter opens the task and Escape clears the field.
2026-11-13 21:14:20 +08:00
6 changed files with 120 additions and 17 deletions

No files matched your search

+4
View File
@@ -180,6 +180,10 @@
display: flex;
flex-direction: column;
}
.taskSearch {
flex: none;
margin: 6px 8px 4px;
}
.history {
display: flex;
flex-direction: column;
+26
View File
@@ -391,6 +391,32 @@ describe("Agents pinned and grouped tasks", () => {
expect(treeRows().some((text) => text.includes("Pinned"))).toBe(false);
});
it("filters every section by the search, archived ones included, and highlights the match", () => {
const tasks = useAgents.getState().tasks;
const rename = (id: string, title: string, status: AgentTask["status"] = "ready") =>
tasks.set(id, { ...tasks.get(id)!, title, status });
rename("one", "Fix the lexer");
rename("two", "Refactor parser");
rename("three", "Lexer cleanup", "archived");
useAgents.setState({ tasks: new Map(tasks), organize: { groups: [frontend], groupOf: { two: "g1" }, pinned: [] } });
setup();
const field = screen.getByLabelText("Search tasks");
fireEvent.change(field, { target: { value: "lxr" } });
const rows = treeRows();
expect(rows.some((text) => text.includes("Fix the lexer"))).toBe(true);
// Archived is collapsed by default; a search looks inside it.
expect(rows.some((text) => text.includes("Lexer cleanup"))).toBe(true);
// The user group has no match: it goes.
expect(rows.some((text) => text.includes("Frontend") || text.includes("Refactor parser"))).toBe(false);
const lexer = screen.getAllByRole("treeitem").find((item) => item.textContent?.includes("Fix the lexer"))!;
expect([...lexer.querySelectorAll("mark")].map((m) => m.textContent).join("")).toBe("lxr");
fireEvent.change(field, { target: { value: "nothing like it" } });
expect(screen.getByText("No matching tasks")).toBeInTheDocument();
fireEvent.keyDown(field, { key: "Escape" });
expect(treeRows().some((text) => text.includes("Frontend"))).toBe(true);
});
it("shows a user group above the status groups, without its tasks in them too", () => {
useAgents.setState({ organize: { groups: [frontend], groupOf: { two: "g1" }, pinned: [] } });
setup();
+70 -15
View File
@@ -5,9 +5,11 @@ import type { AgentStatus as Status, AgentTask } from "@/bindings";
import { EDITOR_TAB_MIME, maybeEditorService, type EditorInput } from "@/workbench/contributions";
import {
EmptyState,
HighlightedText,
Icon,
IconButton,
Popup,
SearchField,
Spinner,
T,
Tree,
@@ -15,6 +17,7 @@ import {
showContextMenu,
startPointerDrag,
type IconName,
type TreeHandle,
} from "@/ui";
import {
SESSION_KIND,
@@ -37,6 +40,7 @@ import {
useAgents,
} from "./store";
import { groupMenu, taskMenu } from "./taskActions";
import { matchTask } from "./taskSearch";
import { SessionEditor } from "./SessionEditor";
import { HomeEditor } from "./HomeEditor";
import styles from "./Agents.module.css";
@@ -187,6 +191,8 @@ export function AgentsView() {
return new Set(task ? [task] : []);
});
const organize = useAgents((s) => s.organize);
const [query, setQuery] = useState("");
const treeRef = useRef<TreeHandle>(null);
// Follow the active session tab.
useEffect(
() =>
@@ -201,20 +207,32 @@ export function AgentsView() {
}),
[],
);
// While searching: the matching tasks of every section, collapsed ones included; empty sections go.
const matches = useMemo(() => {
if (!query.trim()) return null;
const found = new Map<string, number[]>();
for (const task of tasks.values()) {
const hit = matchTask(task, query);
if (hit) found.set(task.id, hit);
}
return found;
}, [tasks, query]);
const roots = useMemo<Node[]>(() => {
const all = [...tasks.values()];
const all = [...tasks.values()].filter((t) => !matches || matches.has(t.id));
const pinned = pinnedMembers(all, organize);
return [
...(pinned.length ? [{ kind: "pinned", tasks: pinned } as Node] : []),
...organize.groups.map((group): Node => ({
kind: "custom",
group,
tasks: groupMembers(tasks.values(), organize, group.id),
})),
...organize.groups.flatMap((group): Node[] => {
const members = groupMembers(all, organize, group.id);
return matches && !members.length ? [] : [{ kind: "custom", group, tasks: members }];
}),
...groupTasks(ungroupedMembers(all, organize)).map((group): Node => ({ kind: "group", group })),
];
}, [tasks, organize]);
const expanded = useMemo(() => new Set(roots.map(nodeKey).filter((k) => !collapsed.has(k))), [roots, collapsed]);
}, [tasks, organize, matches]);
const expanded = useMemo(
() => new Set(roots.map(nodeKey).filter((k) => matches || !collapsed.has(k))),
[roots, collapsed, matches],
);
// Dropping a session editor tab anywhere on the tool window docks it.
const viewRef = useRef<HTMLDivElement>(null);
const [tabOver, setTabOver] = useState(false);
@@ -251,8 +269,35 @@ export function AgentsView() {
const taskList = (
<div className={styles.tasks}>
{tasks.size > 0 && (
<SearchField
className={styles.taskSearch}
value={query}
onChange={setQuery}
clearable
placeholder={tx("Search tasks")}
aria-label={tx("Search tasks")}
onKeyDown={(e) => {
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
e.preventDefault();
treeRef.current?.moveSelection(e.key === "ArrowDown" ? 1 : -1);
} else if (e.key === "Enter") {
const lead = treeRef.current?.leadKey();
if (lead && tasks.has(lead)) {
e.preventDefault();
showTask(lead);
}
} else if (e.key === "Escape" && query) {
e.preventDefault();
e.stopPropagation();
setQuery("");
}
}}
/>
)}
<Tree<Node>
aria-label="Agent tasks"
handleRef={treeRef}
roots={roots}
getKey={nodeKey}
getLabel={(n) =>
@@ -331,7 +376,11 @@ export function AgentsView() {
>
<Icon name={providerIcon(n.task.provider)} size={16} label={providerName(n.task.provider)} />
<span className={styles.title} data-unread={unread.has(n.task.id) || undefined}>
{n.task.title}
{matches?.get(n.task.id)?.length ? (
<HighlightedText text={n.task.title} indices={matches.get(n.task.id)!} />
) : (
n.task.title
)}
</span>
{/* Ready tasks say so by their group; the others show what they're doing. */}
{n.task.status !== "ready" && <TaskStatusIcon status={n.task.status} />}
@@ -352,12 +401,18 @@ export function AgentsView() {
}
}}
empty={
<div className={styles.empty}>
<T>No agent tasks yet</T>
<button type="button" className={styles.link} onClick={() => openHome()}>
<T>New Task…</T>
</button>
</div>
matches ? (
<div className={styles.empty}>
<T>No matching tasks</T>
</div>
) : (
<div className={styles.empty}>
<T>No agent tasks yet</T>
<button type="button" className={styles.link} onClick={() => openHome()}>
<T>New Task…</T>
</button>
</div>
)
}
/>
</div>
+14
View File
@@ -0,0 +1,14 @@
/** Filtering the Agents task list: fuzzy on the title (highlighted), word starts on the project folder and branch. */
import type { AgentTask } from "@/bindings";
import { fuzzyMatch, wordMatch } from "@/ui";
import { basename } from "@/platform/project";
/** Indices of `query` in the task's title to highlight ([] when another field matched), or null when it doesn't match. */
export function matchTask(task: AgentTask, query: string): number[] | null {
const q = query.trim();
if (!q) return [];
const title = fuzzyMatch(task.title, q);
if (title) return title;
const others = [task.projectRoot ? basename(task.projectRoot) : null, task.branch];
return others.some((text) => text && wordMatch(text, q)) ? [] : null;
}
+3 -1
View File
@@ -1519,5 +1519,7 @@
"Whether the debugger for a build tool's JVMs is installed, offering the install when not (arg: { module, retry, done(ready) })": "Whether the debugger for a build tool's JVMs is installed, offering the install when not (arg: { module, retry, done(ready) })",
"This module has Kotlin sources, so debugging it needs the Kotlin debugger (kotlin-debug-adapter).": "This module has Kotlin sources, so debugging it needs the Kotlin debugger (kotlin-debug-adapter).",
"Implements {names}": "Implements {names}",
"Choose Implemented Interface of {name} ({count} found)": "Choose Implemented Interface of {name} ({count} found)"
"Choose Implemented Interface of {name} ({count} found)": "Choose Implemented Interface of {name} ({count} found)",
"Search tasks": "Search tasks",
"No matching tasks": "No matching tasks"
}
+3 -1
View File
@@ -7920,5 +7920,7 @@
"Whether the debugger for a build tool's JVMs is installed, offering the install when not (arg: { module, retry, done(ready) })": "检查构建工具启动的 JVM 所需的调试器是否已安装,未安装时提供安装(参数:{ module, retry, done(ready) })",
"This module has Kotlin sources, so debugging it needs the Kotlin debugger (kotlin-debug-adapter).": "此模块包含 Kotlin 源代码,调试它需要 Kotlin 调试器(kotlin-debug-adapter)。",
"Implements {names}": "实现 {names}",
"Choose Implemented Interface of {name} ({count} found)": "选择 {name} 实现的接口(找到 {count} 个)"
"Choose Implemented Interface of {name} ({count} found)": "选择 {name} 实现的接口(找到 {count} 个)",
"Search tasks": "搜索任务",
"No matching tasks": "没有匹配的任务"
}