Agent Zero AI framework
Fix sidebar folder lag during activity and focus updates
Alessandro52744fe7b142
diff --git a/plugins/_sidebar_folders/AGENTS.md b/plugins/_sidebar_folders/AGENTS.mdindex c53552b5d..3c8f90e56 100644--- a/plugins/_sidebar_folders/AGENTS.md+++ b/plugins/_sidebar_folders/AGENTS.md@@ -19,6 +19,9 @@- Reordering folders, chats, or tasks by drag and drop automatically selects and saves manual sorting.- Neighboring folder/thread/task drops select the insertion edge that swaps their order; longer moves use the hovered row's midpoint for before/after placement.- Drag hover reuses the rendered sections and rows; do not regroup chat families on each pointer event or republish an unchanged drop target.+- A grouping pass shares one root list and parent/child index across pins and folders. Filter passes share a child index across families; direct family lookups build a fresh index, preserving current nesting without a persistent cache.+- The folder list passes its existing sections to `sections()`. Retain them when group metadata, row identities and ordering are unchanged; reactive chat metadata continues updating in place without refreshing every row scope.+- Focus refreshes preserve config and order identities when their values are unchanged; the project store preserves unchanged project lists. Refreshes must not rebuild the sidebar solely because a response contains new object instances.- Both sides of a gap share one insertion target at the following row's top edge, with a bottom edge only after the last row. Drop indicators and released drops use that same target; dragged rows do not target themselves.- Folder containers receive drops across their padding and expanded contents. Thread-list gaps resolve to the nearest thread, including the last thread's bottom edge; folder headers remain project-move targets for chats. Folder insertion markers surround the whole folder, including its workers, and clear when the drag leaves the list.- Pin state and row indicators belong to `_pin_to_top`. Each list groups pins above all project folders, including pinned **No project**, with a separator and no subtitle. Pins retain their project/color, appear only once, and return to their own folder when unpinned; project filters also apply to pins.@@ -51,6 +54,7 @@- `python -m pytest plugins/_sidebar_folders/tests/test_folders.py tests/test_chat_create.py tests/test_sidebar_row_actions.py tests/test_chat_working_animation.py tests/test_webui_chat_deletion.py -q`- `node plugins/_sidebar_folders/tests/test_frontend.mjs`+- Check unchanged window-focus refreshes avoid sidebar DOM updates; activity metadata must still update clocks, status and names, with regrouping when ordering, filters or family membership change.- Verify live creation in an explicit project, folder/flat switching, nesting, pins, drag ordering, cross-project chat moves, no-project moves, task actions, reload persistence, and desktop/mobile/light-mode layouts.## Child DOX Indexdiff --git a/plugins/_sidebar_folders/tests/test_frontend.mjs b/plugins/_sidebar_folders/tests/test_frontend.mjsindex 0e374c8b6..dcad1d745 100644--- a/plugins/_sidebar_folders/tests/test_frontend.mjs+++ b/plugins/_sidebar_folders/tests/test_frontend.mjs@@ -40,7 +40,7 @@ globalThis.__folderApi = async (url, data) => {globalThis.document = { activeElement: null };globalThis.localStorage = { setItem() {} };const { chats, tasks } = globalThis.__foldersTest;-chats.topLevelContexts = () => store.sortRows("chat", contexts.filter((row) => !row.parent_context_id));+chats.topLevelContexts = () => store.sortRows("chat", chats.contexts.filter((row) => !row.parent_context_id));tasks.visibleTasks = () => store.sortRows("task", tasks.tasks);assert.deepEqual(store.groups("chat").map((g) => g.id), ["alpha", "beta", ""]);@@ -410,4 +410,81 @@ await store.loadConfig();assert.equal(store.config.project_filter, "*");assert.equal(store.config.status_filter, "all");assert.equal(store.config.activity_filter, "all");++const unchangedConfig = store.config;+await store.loadConfig();+assert.equal(store.config, unchangedConfig, "an unchanged focus refresh retains config identity");+const savedOrder = JSON.parse(JSON.stringify(store.order));+globalThis.__folderApi = async () => ({ order: JSON.parse(JSON.stringify(savedOrder)) });+const unchangedOrder = store.order;+await store.loadOrder();+assert.equal(store.order, unchangedOrder, "an unchanged focus refresh retains ordering identity");+savedOrder.chat.push("new-chat");+await store.loadOrder();+assert.notEqual(store.order, unchangedOrder, "changed ordering is still applied");++const originalContexts = chats.contexts;+let parentReads = 0;+chats.contexts = Array.from({ length: 600 }, (_, index) => ({+ id: `row-${index}`, created_at: "2026-01-01",+ get parent_context_id() {+ parentReads++;+ return index % 2 ? `row-${index - 1}` : null;+ },+}));+store.config = { ...store.config, sort_by: "created", status_filter: "all", activity_filter: "all", project_filter: "*" };+const largeSections = store.sections("chat");+assert.equal(largeSections.flatMap((group) => group.rows).length, 300);+assert.ok(parentReads <= chats.contexts.length * 6, "a grouping pass must index parents once, not scan every chat for each family");+chats.contexts[0].last_message = "2026-10-06";+assert.equal(store.sections("chat", largeSections), largeSections, "metadata updates retain unchanged rendered sections");+chats.contexts[2].last_message = "2026-10-07";+store.config.sort_by = "recent";+const reorderedSections = store.sections("chat", largeSections);+assert.notEqual(reorderedSections, largeSections, "changed row order must reach the rendered sections");+assert.equal(reorderedSections.find((group) => group.id === "").rows[0].id, "row-2");+store.config.sort_by = "created";+const originalTitle = projects.projectList[0].title;+projects.projectList[0].title = "Updated project";+const renamedSections = store.sections("chat", largeSections);+assert.notEqual(renamedSections, largeSections, "changed folder metadata must reach the rendered sections");+assert.equal(renamedSections.find((group) => group.id === "alpha").title, "Updated project");+projects.projectList[0].title = originalTitle;+const originalRow = chats.contexts[0];+chats.contexts[0] = { ...originalRow };+assert.notEqual(store.sections("chat", largeSections), largeSections, "equal row values cannot retain stale object references");+chats.contexts[0] = originalRow;+chats.contexts[0].project = { name: "new-project" };+assert.notEqual(store.sections("chat", largeSections), largeSections, "project moves rebuild the affected sections");+chats.contexts[0].project = null;+store.config.status_filter = "idle";+parentReads = 0;+assert.equal(store.roots("chat").length, 300);+assert.ok(parentReads <= chats.contexts.length * 6, "filters must share the parent index across families");+chats.contexts = originalContexts;+store.config.status_filter = "all";+const grandchild = { id: "grandchild", parent_context_id: "child" };+contexts.push(grandchild);+assert.deepEqual(store.family(contexts[0], "chat").map((row) => row.id), ["a", "child", "grandchild"]);+grandchild.parent_context_id = "c";+assert.deepEqual(store.family(contexts[0], "chat").map((row) => row.id), ["a", "child"], "reparenting cannot reuse a stale index");+contexts[3].parent_context_id = "grandchild";+grandchild.parent_context_id = "child";+assert.deepEqual(store.family(contexts[3], "chat").map((row) => row.id), ["child", "grandchild"], "malformed cycles remain bounded");+contexts[3].parent_context_id = "a";+contexts.pop();++const projectSource = await readFile(new URL("../../../webui/components/projects/projects-store.js", import.meta.url), "utf8");+let projectResponse = [{ name: "example", title: "Example" }];+const projectStore = new Function("api", projectSource.slice(projectSource.indexOf("const model ="), projectSource.indexOf("// convert it to alpine store")) + "\nreturn model;")({+ callJsonApi: async () => ({ data: JSON.parse(JSON.stringify(projectResponse)) }),+});+await projectStore.loadProjectsList();+const unchangedProjects = projectStore.projectList;+await projectStore.loadProjectsList();+assert.equal(projectStore.projectList, unchangedProjects, "an unchanged focus refresh retains the project list");+projectResponse[0].title = "Renamed";+await projectStore.loadProjectsList();+assert.notEqual(projectStore.projectList, unchangedProjects);+assert.equal(projectStore.projectList[0].title, "Renamed", "project edits remain visible after refresh");console.log("Folder view grouping, sorting, pins, movement, selection, drop, menu-scope, and preference checks passed.");diff --git a/plugins/_sidebar_folders/webui/folder-list.html b/plugins/_sidebar_folders/webui/folder-list.htmlindex db35c561c..6c191520f 100644--- a/plugins/_sidebar_folders/webui/folder-list.html+++ b/plugins/_sidebar_folders/webui/folder-list.html@@ -5,7 +5,7 @@<template x-if="$store.sidebarFolders && $store.sidebarFolders.config.folder_view"><div class="sidebar-folder-host" x-effect="$store.sidebarFolders.revealSelection(kind, $store.chats.selected)"><ul class="config-list sidebar-folder-list no-scrollbar" :class="kind === 'chat' ? 'chats-config-list' : 'tasks-config-list'"- x-effect="sections = $store.sidebarFolders.sections(kind)"+ x-effect="sections = $store.sidebarFolders.sections(kind, sections)":aria-label="kind === 'chat' ? 'Chat folders' : 'Task folders'" @dragend="$store.sidebarFolders.endDrag()"@dragleave="if (!$el.contains($event.relatedTarget)) $store.sidebarFolders.dropTarget = null"><template x-for="group in sections" :key="group.pinned ? 'pinned' : 'project:' + group.id">diff --git a/plugins/_sidebar_folders/webui/sidebar-folders-store.js b/plugins/_sidebar_folders/webui/sidebar-folders-store.jsindex db4a5af50..0f6a3a994 100644--- a/plugins/_sidebar_folders/webui/sidebar-folders-store.js+++ b/plugins/_sidebar_folders/webui/sidebar-folders-store.js@@ -56,13 +56,14 @@ export const store = createStore("sidebarFolders", {try {const result = await callJsonApi("plugins", { action: "get_config", plugin_name: PLUGIN });if (!result.ok) throw new Error(result.error || "Could not load folder settings");- this.config = {+ const config = {folder_view: result.data?.folder_view !== false,sort_by: SORTS.includes(result.data?.sort_by) ? result.data.sort_by : "created",project_filter: typeof result.data?.project_filter === "string" ? result.data.project_filter : "*",status_filter: ["all", "running", "idle"].includes(result.data?.status_filter) ? result.data.status_filter : "all",activity_filter: ["all", "1", "3", "7", "30"].includes(result.data?.activity_filter) ? result.data.activity_filter : "all",};+ if (JSON.stringify(config) !== JSON.stringify(this.config)) this.config = config;} catch (error) {this.report(error);}@@ -71,7 +72,7 @@ export const store = createStore("sidebarFolders", {async loadOrder() {try {const result = await callJsonApi(`/plugins/${PLUGIN}/layout`, {});- this.order = result.order;+ if (JSON.stringify(result.order) !== JSON.stringify(this.order)) this.order = result.order;} catch (error) {this.report(error);}@@ -111,13 +112,24 @@ export const store = createStore("sidebarFolders", {return row;},- family(row, kind) {+ childIndex() {+ const children = new Map();+ for (const context of chats.contexts) {+ if (!context.parent_context_id) continue;+ if (!children.has(context.parent_context_id)) children.set(context.parent_context_id, []);+ children.get(context.parent_context_id).push(context);+ }+ return children;+ },++ family(row, kind, children = null) {if (kind !== "chat") return [row];+ children ??= this.childIndex();const family = [row];const seen = new Set([row.id]);for (const parent of family) {- for (const child of chats.contexts) {- if (child.parent_context_id === parent.id && !seen.has(child.id)) {+ for (const child of children.get(parent.id) || []) {+ if (!seen.has(child.id)) {seen.add(child.id);family.push(child);}@@ -126,10 +138,10 @@ export const store = createStore("sidebarFolders", {return family;},- matches(row, kind) {+ matches(row, kind, children) {if (this.config.project_filter !== "*" && (row.project?.name || "") !== this.config.project_filter) return false;if (this.config.status_filter === "all" && this.config.activity_filter === "all") return true;- const family = this.family(row, kind);+ const family = this.family(row, kind, children);const working = family.some((item) => item.running && !item.paused && item.state !== "disabled");if (this.config.status_filter === "running" && !working) return false;if (this.config.status_filter === "idle" && working) return false;@@ -143,8 +155,10 @@ export const store = createStore("sidebarFolders", {},sortRows(kind, rows) {+ const children = kind === "chat" && (this.config.status_filter !== "all" || this.config.activity_filter !== "all")+ ? this.childIndex() : null;const rank = new Map(this.order[kind].map((id, index) => [id, index]));- return rows.filter((row) => row.parent_context_id || this.matches(row, kind)).sort((a, b) => {+ return rows.filter((row) => row.parent_context_id || this.matches(row, kind, children)).sort((a, b) => {const pinned = Number(pins.isPinned(kind, b.id)) - Number(pins.isPinned(kind, a.id));if (pinned) return pinned;if (this.config.sort_by === "manual") {@@ -158,32 +172,41 @@ export const store = createStore("sidebarFolders", {});},- isPinnedRow(kind, row) {- return this.family(row, kind).some((member) => pins.isPinned(kind, member.id));+ isPinnedRow(kind, row, children) {+ return this.family(row, kind, children).some((member) => pins.isPinned(kind, member.id));},- pinnedRows(kind) {- const rows = this.roots(kind).filter((row) => this.isPinnedRow(kind, row));+ pinnedRows(kind, roots = this.roots(kind), children = kind === "chat" ? this.childIndex() : null) {+ const rows = roots.filter((row) => this.isPinnedRow(kind, row, children));if (this.config.sort_by !== "manual") return pins.sortItems(kind, rows);const rank = new Map(this.order[kind].map((id, index) => [id, index]));return rows.sort((a, b) => (rank.get(a.id) ?? Infinity) - (rank.get(b.id) ?? Infinity) || 0);},- sections(kind) {- const pinned = this.pinnedRows(kind);- const folders = this.groups(kind);- return pinned.length ? [{ id: null, pinned: true, rows: pinned }, ...folders] : folders;+ sections(kind, previous) {+ const rows = this.roots(kind);+ const children = kind === "chat" ? this.childIndex() : null;+ const pinned = this.pinnedRows(kind, rows, children);+ const folders = this.groups(kind, rows, children);+ const sections = pinned.length ? [{ id: null, pinned: true, rows: pinned }, ...folders] : folders;+ if (previous?.length === sections.length && sections.every((group, index) => {+ const current = previous[index];+ return ["id", "pinned", "title", "color", "hasPinned"].every((key) => group[key] === current[key])+ && group.rows.length === current.rows.length+ && group.rows.every((row, rowIndex) => row === current.rows[rowIndex]);+ })) return previous;+ return sections;},- groups(kind) {+ groups(kind, rows = this.roots(kind), children = kind === "chat" ? this.childIndex() : null) {const groups = new Map(projects.projectList.map((project) => [project.name, {id: project.name, title: project.title || project.name, color: project.color, rows: [],}]));groups.set("", { id: "", title: "No project", color: "", rows: [] });- for (const row of this.roots(kind)) {+ for (const row of rows) {const id = row.project?.name || "";if (!groups.has(id)) groups.set(id, { id, title: row.project.title || id, color: row.project.color, rows: [] });- if (this.isPinnedRow(kind, row)) groups.get(id).hasPinned = true;+ if (this.isPinnedRow(kind, row, children)) groups.get(id).hasPinned = true;else groups.get(id).rows.push(row);}const rank = new Map(this.order.project.map((id, index) => [id, index]));diff --git a/webui/components/projects/AGENTS.md b/webui/components/projects/AGENTS.mdindex cf4bd161e..7efd3d23c 100644--- a/webui/components/projects/AGENTS.md+++ b/webui/components/projects/AGENTS.md@@ -14,6 +14,7 @@## Local Contracts- Keep project API payloads synchronized with backend project handlers.+- `loadProjectsList()` retains the current list when response values are unchanged, avoiding sidebar regrouping on window focus. Changed project values and ordering still replace the list.- Do not expose project secrets in logs, URLs, or long-lived frontend state unnecessarily.- Preserve scoped settings interactions with plugins, models, skills, and MCP servers.- Project model settings select a global `_model_config` preset; they do not own copied model dictionaries or project-local preset definitions.diff --git a/webui/components/projects/projects-store.js b/webui/components/projects/projects-store.jsindex d885dabba..3386a7c01 100644--- a/webui/components/projects/projects-store.js+++ b/webui/components/projects/projects-store.js@@ -340,7 +340,8 @@ const model = {const response = await api.callJsonApi("projects", {action: "list",});- this.projectList = response.data || [];+ const projectList = response.data || [];+ if (JSON.stringify(projectList) !== JSON.stringify(this.projectList)) this.projectList = projectList;} catch (error) {console.error("Error loading projects list:", error);} finally {