дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
feat(agents): group the task list by project in a workspace (#8108)
With several projects in the window, a Group by Project toggle in the Agents tool window header (off by default, remembered) lists the active tasks under their project, in the workspace's order and each in attention order; pinned and custom groups, Archived and Automated stay as they are. Manual reordering is off while grouped, and the per-row project tag is hidden.
Цей коміт міститься в:
1 джерело
cf5493959b
коміт
9e605ee761
6 files changed
+149
-9
No files matched your search
@@ -40,11 +40,14 @@ import {
|
||||
customSection,
|
||||
groupMembers,
|
||||
pinnedMembers,
|
||||
projectGroups,
|
||||
projectSection,
|
||||
sectionOfTask,
|
||||
statusGroups,
|
||||
statusSection,
|
||||
type OrganizeGroup,
|
||||
} from "./organize";
|
||||
import { setTaskListOptions, useTaskListOptions } from "./taskListOptions";
|
||||
import {
|
||||
agentIcon,
|
||||
externalKey,
|
||||
@@ -78,9 +81,26 @@ import { basename, useProject } from "@/platform/project";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
|
||||
/** The window's projects when it holds several (a workspace), else none. */
|
||||
function useWorkspaceProjects(): readonly string[] {
|
||||
const projects = useProject((s) => s.project?.workspace?.projects);
|
||||
return projects && projects.length > 1 ? projects : NO_PROJECTS;
|
||||
}
|
||||
const NO_PROJECTS: readonly string[] = [];
|
||||
|
||||
export function AgentsHeaderActions() {
|
||||
const several = useWorkspaceProjects().length > 1;
|
||||
const byProject = useTaskListOptions((s) => s.groupByProject);
|
||||
return (
|
||||
<>
|
||||
{several && (
|
||||
<IconButton
|
||||
icon="folder"
|
||||
title="Group by Project"
|
||||
pressed={byProject}
|
||||
onClick={() => setTaskListOptions({ groupByProject: !byProject })}
|
||||
/>
|
||||
)}
|
||||
<IconButton icon="plus" action="agents.newTask" />
|
||||
<IconButton icon="settings" title="Agent Settings" action="file.settings" actionArg={REGISTRY_PAGE} />
|
||||
</>
|
||||
@@ -91,6 +111,7 @@ type Node =
|
||||
| { kind: "pinned"; tasks: AgentTask[] }
|
||||
| { kind: "custom"; group: OrganizeGroup; tasks: AgentTask[] }
|
||||
| { kind: "group"; group: TaskGroup }
|
||||
| { kind: "project"; root: string; tasks: AgentTask[] }
|
||||
| { kind: "task"; task: AgentTask };
|
||||
|
||||
function nodeKey(n: Node): string {
|
||||
@@ -101,14 +122,18 @@ function nodeKey(n: Node): string {
|
||||
return customSection(n.group.id);
|
||||
case "group":
|
||||
return statusSection(n.group.status);
|
||||
case "project":
|
||||
return projectSection(n.root);
|
||||
case "task":
|
||||
return n.task.id;
|
||||
}
|
||||
}
|
||||
|
||||
/** Where a task shows: the pinned section first, else its group, else its status group. */
|
||||
function keysOf(task: AgentTask): string[] {
|
||||
return [sectionOfTask(task, useAgents.getState().organize)];
|
||||
/** Where a task shows: the pinned section first, else its group, else its status group (or its project's). */
|
||||
function keysOf(task: AgentTask, rootOf: ((task: AgentTask) => string) | null): string[] {
|
||||
const section = sectionOfTask(task, useAgents.getState().organize);
|
||||
const kept = section === statusSection("archived") || section === statusSection("automated");
|
||||
return [rootOf && section.startsWith("g:") && !kept ? projectSection(rootOf(task)) : section];
|
||||
}
|
||||
|
||||
type DropIndicator = { kind: "section"; key: string } | { kind: "row"; key: string; position: "before" | "after" };
|
||||
@@ -218,6 +243,20 @@ export function AgentsView() {
|
||||
}, [selected]);
|
||||
const organize = useAgents((s) => s.organize);
|
||||
const pinned = useMemo(() => new Set(organize.pinned), [organize.pinned]);
|
||||
const workspaceProjects = useWorkspaceProjects();
|
||||
const groupByProject = useTaskListOptions((s) => s.groupByProject);
|
||||
// Tasks list under their project only while the window holds several.
|
||||
const rootOf = useMemo(
|
||||
() =>
|
||||
groupByProject && workspaceProjects.length > 1 && project
|
||||
? (task: AgentTask) => task.projectRoot ?? project.root
|
||||
: null,
|
||||
[groupByProject, workspaceProjects, project],
|
||||
);
|
||||
const rootOfRef = useRef(rootOf);
|
||||
useEffect(() => {
|
||||
rootOfRef.current = rootOf;
|
||||
}, [rootOf]);
|
||||
const [query, setQuery] = useState("");
|
||||
const treeRef = useRef<TreeHandle>(null);
|
||||
// Follow the active session tab.
|
||||
@@ -228,7 +267,7 @@ export function AgentsView() {
|
||||
if (!task) return;
|
||||
setSelected((current) => (current.has(task) ? current : new Set([task])));
|
||||
const known = useAgents.getState().tasks.get(task);
|
||||
const keys = known ? keysOf(known) : [];
|
||||
const keys = known ? keysOf(known, rootOfRef.current) : [];
|
||||
if (keys.length)
|
||||
setCollapsed((c) => (keys.some((k) => c.has(k)) ? new Set([...c].filter((k) => !keys.includes(k))) : c));
|
||||
}),
|
||||
@@ -256,9 +295,17 @@ export function AgentsView() {
|
||||
const members = groupMembers(all, organize, group.id);
|
||||
return matches && !members.length ? [] : [{ kind: "custom", group, tasks: members }];
|
||||
}),
|
||||
...statusGroups(all, organize).map((group): Node => ({ kind: "group", group })),
|
||||
...(() => {
|
||||
const groups = statusGroups(all, organize);
|
||||
if (!rootOf) return groups.map((group): Node => ({ kind: "group", group }));
|
||||
const split = projectGroups(groups, workspaceProjects, rootOf);
|
||||
return [
|
||||
...split.projects.map((p): Node => ({ kind: "project", ...p })),
|
||||
...split.rest.map((group): Node => ({ kind: "group", group })),
|
||||
];
|
||||
})(),
|
||||
];
|
||||
}, [tasks, organize, matches, unread, automatedRunFilter, latestAutomated]);
|
||||
}, [tasks, organize, matches, unread, automatedRunFilter, latestAutomated, rootOf, workspaceProjects]);
|
||||
const expanded = useMemo(
|
||||
() => new Set(roots.map(nodeKey).filter((k) => matches || !collapsed.has(k))),
|
||||
[roots, collapsed, matches],
|
||||
@@ -343,7 +390,8 @@ export function AgentsView() {
|
||||
apply: () => moveTasksToStatusGroup(movable.map((t) => t.id)),
|
||||
};
|
||||
}
|
||||
if (searchingRef.current) return null;
|
||||
// Manual order is per status group; rows under a project keep its attention order.
|
||||
if (searchingRef.current || rootOfRef.current) return null;
|
||||
const target = tasks.get(targetKey);
|
||||
if (!target || sourceIds.includes(target.id)) return null;
|
||||
const movable = sources.filter((t) => canReorderTask(t, target, organize));
|
||||
@@ -601,7 +649,9 @@ export function AgentsView() {
|
||||
? "Pinned"
|
||||
: n.kind === "custom"
|
||||
? n.group.name
|
||||
: n.group.label
|
||||
: n.kind === "project"
|
||||
? basename(n.root)
|
||||
: n.group.label
|
||||
}
|
||||
getChildren={(n) =>
|
||||
n.kind === "task"
|
||||
@@ -661,6 +711,8 @@ export function AgentsView() {
|
||||
return <GroupRow label={<T>Pinned</T>} count={n.tasks.length} />;
|
||||
case "custom":
|
||||
return <GroupRow label={n.group.name} count={n.tasks.length} />;
|
||||
case "project":
|
||||
return <GroupRow icon="folder" label={basename(n.root)} count={n.tasks.length} />;
|
||||
case "group":
|
||||
return (
|
||||
<GroupRow
|
||||
@@ -726,7 +778,7 @@ export function AgentsView() {
|
||||
{unread.has(n.task.id) && (
|
||||
<span className={styles.unreadDot} role="img" aria-label={tx("Unread")} title={tx("Unread")} />
|
||||
)}
|
||||
{project?.workspace && (
|
||||
{project?.workspace && !rootOf && (
|
||||
<span className={styles.taskProject} title={n.task.projectRoot ?? project.root}>
|
||||
{basename(n.task.projectRoot ?? project.root)}
|
||||
</span>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
loadOrganize,
|
||||
parseOrganize,
|
||||
pinnedMembers,
|
||||
projectGroups,
|
||||
pruneOrganize,
|
||||
reorderGroupsInOrganize,
|
||||
reorderTaskInOrganize,
|
||||
@@ -269,3 +270,27 @@ describe("task organize", () => {
|
||||
expect(reorderTaskInOrganize(EMPTY_ORGANIZE, all, "m-ready", "a-newer", "before")).toBe(EMPTY_ORGANIZE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("grouping by project", () => {
|
||||
it("lists each project's active tasks in attention order and keeps archived and automated groups", () => {
|
||||
const root: Record<string, string> = { a: "/w/api", b: "/w/web", c: "/w/api", d: "/w/api", e: "/other" };
|
||||
const tasks = [
|
||||
task("a", "ready", 3),
|
||||
task("b", "running", 2),
|
||||
task("c", "needsInput", 1),
|
||||
task("d", "archived", 5),
|
||||
task("e", "ready", 4),
|
||||
];
|
||||
const split = projectGroups(
|
||||
statusGroups(tasks, EMPTY_ORGANIZE),
|
||||
["/w/web", "/w/api", "/w/empty"],
|
||||
(t) => root[t.id]!,
|
||||
);
|
||||
expect(split.projects.map((p) => [p.root, p.tasks.map((t) => t.id)])).toEqual([
|
||||
["/w/web", ["b"]],
|
||||
["/w/api", ["c", "a"]],
|
||||
["/other", ["e"]],
|
||||
]);
|
||||
expect(split.rest.map((g) => [g.status, g.tasks.map((t) => t.id)])).toEqual([["archived", ["d"]]]);
|
||||
});
|
||||
});
|
||||
@@ -375,3 +375,33 @@ export function reorderGroupsInOrganize(
|
||||
});
|
||||
return { ...organize, groups };
|
||||
}
|
||||
|
||||
/** Section of a project's tasks when the list is grouped by project. */
|
||||
export const projectSection = (root: string) => `p:${root}`;
|
||||
|
||||
/**
|
||||
* Status groups regrouped by project: each project of `projects` (then any other root a task names)
|
||||
* gets the tasks of the active status groups in attention order; the archived and automated groups
|
||||
* stay as they are.
|
||||
*/
|
||||
export function projectGroups(
|
||||
groups: readonly TaskGroup[],
|
||||
projects: readonly string[],
|
||||
rootOf: (task: AgentTask) => string,
|
||||
): { projects: { root: string; tasks: AgentTask[] }[]; rest: TaskGroup[] } {
|
||||
const kept = (g: TaskGroup) => g.status === "archived" || g.status === "automated";
|
||||
const byRoot = new Map<string, AgentTask[]>(projects.map((root) => [root, []]));
|
||||
for (const group of groups) {
|
||||
if (kept(group)) continue;
|
||||
for (const task of group.tasks) {
|
||||
const root = rootOf(task);
|
||||
const list = byRoot.get(root);
|
||||
if (list) list.push(task);
|
||||
else byRoot.set(root, [task]);
|
||||
}
|
||||
}
|
||||
return {
|
||||
projects: [...byRoot].filter(([, tasks]) => tasks.length).map(([root, tasks]) => ({ root, tasks })),
|
||||
rest: groups.filter(kept),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/** Agents task list view options, persisted across sessions. */
|
||||
import { create } from "zustand";
|
||||
|
||||
export interface TaskListOptions {
|
||||
/** With several projects in the window, tasks are listed under their project instead of their status. */
|
||||
groupByProject: boolean;
|
||||
}
|
||||
|
||||
const KEY = "openidea.agents.taskList.v1";
|
||||
|
||||
function load(): TaskListOptions {
|
||||
try {
|
||||
const raw = localStorage.getItem(KEY);
|
||||
const o = raw ? (JSON.parse(raw) as Record<string, unknown>) : {};
|
||||
return { groupByProject: o.groupByProject === true };
|
||||
} catch {
|
||||
return { groupByProject: false };
|
||||
}
|
||||
}
|
||||
|
||||
export const useTaskListOptions = create<TaskListOptions>(() => load());
|
||||
|
||||
/** Updates the options and persists them. */
|
||||
export function setTaskListOptions(patch: Partial<TaskListOptions>) {
|
||||
useTaskListOptions.setState(patch);
|
||||
try {
|
||||
localStorage.setItem(KEY, JSON.stringify(useTaskListOptions.getState()));
|
||||
} catch {
|
||||
// Storage unavailable: the options last for this session.
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"Group by Project": "Group by Project",
|
||||
"Copy string concatenation text to the clipboard": "Copy string concatenation text to the clipboard",
|
||||
"Copy string literal text to the clipboard": "Copy string literal text to the clipboard",
|
||||
"GitHub Issues": "GitHub Issues",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"Group by Project": "按项目分组",
|
||||
"Copy string concatenation text to the clipboard": "将字符串拼接文本复制到剪贴板",
|
||||
"Copy string literal text to the clipboard": "将字符串字面量文本复制到剪贴板",
|
||||
"GitHub Issues": "GitHub 议题",
|
||||
|
||||
Reference in new issue
Заблокувати користувача