Agent Zero AI framework
Fix disappearing chats when Sidebar Folders is disabled
Alessandrocb93ed055b56
diff --git a/plugins/_sidebar_folders/AGENTS.md b/plugins/_sidebar_folders/AGENTS.mdindex 3c8f90e56..e20913f99 100644--- a/plugins/_sidebar_folders/AGENTS.md+++ b/plugins/_sidebar_folders/AGENTS.md@@ -40,6 +40,7 @@- Sidebar menus share their pointer scope with the opening row or header. Dismiss after leaving both, allowing a short gap-crossing delay; also dismiss when focus leaves, the surrounding list scrolls, the window resizes, or the header extension unmounts. Mouse cleanup must not interrupt touch interaction or scrolling inside a menu.- Resolve the core row menu through its `rowActionsMenu` reference, not shared menu styling classes that community plugins may also use. Header integrations must preserve the core header and its `chats-header-controls` extension point.- The two list-view extension points are display-only alternatives. Disabling the plugin restores the core lists and existing chat/task controls.+- Register view and sorting callbacks when each list-view extension mounts, and unregister them when it unmounts. Importing the store from another plugin must not hide or filter the core lists while this plugin is disabled.## Work Guidancediff --git a/plugins/_sidebar_folders/extensions/webui/sidebar-chats-list-view/folders.html b/plugins/_sidebar_folders/extensions/webui/sidebar-chats-list-view/folders.htmlindex 85c705186..4f0d8c5f7 100644--- a/plugins/_sidebar_folders/extensions/webui/sidebar-chats-list-view/folders.html+++ b/plugins/_sidebar_folders/extensions/webui/sidebar-chats-list-view/folders.html@@ -1,7 +1,8 @@<html><head><script type="module" src="/plugins/_sidebar_folders/webui/sidebar-folders-store.js"></script></head><body>- <div x-data="{ kind: 'chat' }" class="sidebar-folder-host">+ <div x-data="{ kind: 'chat' }" class="sidebar-folder-host"+ x-create="$store.sidebarFolders.mountList('chat')" x-destroy="$store.sidebarFolders.unmountList('chat')"><x-component path="/plugins/_sidebar_folders/webui/folder-list.html"></x-component></div></body>diff --git a/plugins/_sidebar_folders/extensions/webui/sidebar-tasks-list-view/folders.html b/plugins/_sidebar_folders/extensions/webui/sidebar-tasks-list-view/folders.htmlindex 180e1e921..1ec2fd5e8 100644--- a/plugins/_sidebar_folders/extensions/webui/sidebar-tasks-list-view/folders.html+++ b/plugins/_sidebar_folders/extensions/webui/sidebar-tasks-list-view/folders.html@@ -1,7 +1,8 @@<html><head><script type="module" src="/plugins/_sidebar_folders/webui/sidebar-folders-store.js"></script></head><body>- <div x-data="{ kind: 'task' }" class="sidebar-folder-host">+ <div x-data="{ kind: 'task' }" class="sidebar-folder-host"+ x-create="$store.sidebarFolders.mountList('task')" x-destroy="$store.sidebarFolders.unmountList('task')"><x-component path="/plugins/_sidebar_folders/webui/folder-list.html"></x-component></div></body>diff --git a/plugins/_sidebar_folders/tests/test_frontend.mjs b/plugins/_sidebar_folders/tests/test_frontend.mjsindex dcad1d745..3152bced5 100644--- a/plugins/_sidebar_folders/tests/test_frontend.mjs+++ b/plugins/_sidebar_folders/tests/test_frontend.mjs@@ -10,8 +10,10 @@ const contexts = [];const pins = { chat: new Set(), task: new Set(), project: new Set() };const apiCalls = [];+const sidebarSource = await readFile(new URL("../../../webui/components/sidebar/sidebar-store.js", import.meta.url), "utf8");+const sidebarModel = new Function(sidebarSource.slice(sidebarSource.indexOf("const model ="), sidebarSource.indexOf("export const store")) + "\nreturn model;")();globalThis.__foldersTest = {- sidebar: { rowMenuOpenId: "", rowMenuClose() { this.rowMenuOpenId = ""; } },+ sidebar: sidebarModel,chats: { contexts, displayName: (row) => row.name || row.id },tasks: { tasks: [{ id: "task", project: { name: "alpha" } }] },projects: { projectList: [{ name: "alpha", title: "Alpha" }, { name: "beta", title: "Beta" }] },@@ -487,4 +489,34 @@ 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");++const refresh = store.refresh;+store.refresh = async () => {};+localStorage.getItem = () => null;+globalThis.window = { addEventListener() {} };+await store.init();+assert.equal(sidebar.hasListView("chat"), false, "another plugin importing the folders store cannot hide the core chats list");+assert.equal(sidebar.hasListView("task"), false, "another plugin importing the folders store cannot hide the core tasks list");+const roots = contexts.filter((row) => !row.parent_context_id);+store.config.project_filter = "missing-project";+for (const kind of ["chat", "task"]) {+ const rows = kind === "chat" ? roots : tasks.tasks;+ sidebar.registerRowListExtension(kind, "other-plugin", { sort: (items) => [...items].reverse() });+ const fallback = sidebar.sortRows(kind, rows);+ store.mountList(kind);+ assert.equal(sidebar.hasListView(kind), true, "a mounted folders component owns its list view");+ assert.deepEqual(sidebar.sortRows(kind, rows), [], "mounted folder filters still apply");+ store.unmountList(kind);+ assert.equal(sidebar.hasListView(kind), false, "unmounting folders restores the core list");+ assert.deepEqual(sidebar.sortRows(kind, rows), fallback, "unmounting removes folder filters while retaining other plugins' sorting");+ store.mountList(kind);+ assert.equal(sidebar.hasListView(kind), true, "remounting restores the saved folder view");+ assert.equal(store.config.project_filter, "missing-project", "unmounting preserves saved preferences");+ store.unmountList(kind);+ sidebar.unregisterRowListExtension(kind, "other-plugin");+ const extension = await readFile(new URL(`../extensions/webui/sidebar-${kind === "chat" ? "chats" : "tasks"}-list-view/folders.html`, import.meta.url), "utf8");+ assert.ok(extension.includes(`x-create="$store.sidebarFolders.mountList('${kind}')"`));+ assert.ok(extension.includes(`x-destroy="$store.sidebarFolders.unmountList('${kind}')"`));+}+store.refresh = refresh;console.log("Folder view grouping, sorting, pins, movement, selection, drop, menu-scope, and preference checks passed.");diff --git a/plugins/_sidebar_folders/webui/sidebar-folders-store.js b/plugins/_sidebar_folders/webui/sidebar-folders-store.jsindex 0f6a3a994..f509e75bd 100644--- a/plugins/_sidebar_folders/webui/sidebar-folders-store.js+++ b/plugins/_sidebar_folders/webui/sidebar-folders-store.js@@ -38,16 +38,21 @@ export const store = createStore("sidebarFolders", {} catch (error) {console.error("Could not restore sidebar folders", error);}- for (const kind of ["chat", "task"]) {- sidebar.registerRowListExtension(kind, PLUGIN, {- hasView: () => this.config.folder_view,- sort: (rows) => this.sortRows(kind, rows),- });- }window.addEventListener("focus", () => this.refresh());await this.refresh();},+ mountList(kind) {+ sidebar.registerRowListExtension(kind, PLUGIN, {+ hasView: () => this.config.folder_view,+ sort: (rows) => this.sortRows(kind, rows),+ });+ },++ unmountList(kind) {+ sidebar.unregisterRowListExtension(kind, PLUGIN);+ },+async refresh() {await Promise.all([this.loadConfig(), this.loadOrder(), projects.loadProjectsList()]);},diff --git a/webui/components/sidebar/AGENTS.md b/webui/components/sidebar/AGENTS.mdindex c56b7ccbb..18e48e915 100644--- a/webui/components/sidebar/AGENTS.md+++ b/webui/components/sidebar/AGENTS.md@@ -32,6 +32,7 @@- Cancelling the Load Chat file chooser resolves without calling `chat_load` or showing a success/error notification.- `sidebar-row-actions-menu` owns plugin-contributed row-menu actions; list-order plugins register stable sort and divider callbacks through the sidebar store instead of patching chat/task stores or injecting row DOM.- `sidebar-chats-list-view` and `sidebar-tasks-list-view` host plugin list presentations. A row-list extension may expose `hasView()` to hide the default list; both presentations reuse the core row components and their inherited `context`/`task` scopes.+- List-view callbacks belong to their mounted extensions, not store initialization. Use `unregisterRowListExtension(kind, name)` on unmount to restore the default list and remove only the departing extension's sorting and dividers.- `chats.newChat(projectName)` passes an explicit project choice to `chat_create`; omitted project names retain inheritance behavior, and an empty name explicitly creates a chat without a project.- Bottom version information shows its commit timestamp in UTC without a timezone suffix and remains on one line.- Avoid text or controls overflowing fixed sidebar widths.diff --git a/webui/components/sidebar/sidebar-store.js b/webui/components/sidebar/sidebar-store.jsindex e2fc1b914..b19ef7eb7 100644--- a/webui/components/sidebar/sidebar-store.js+++ b/webui/components/sidebar/sidebar-store.js@@ -146,6 +146,13 @@ const model = {};},+ unregisterRowListExtension(kind, name) {+ if (!this.rowListExtensions[kind]?.[name]) return;+ const extensions = { ...this.rowListExtensions[kind] };+ delete extensions[name];+ this.rowListExtensions = { ...this.rowListExtensions, [kind]: extensions };+ },+hasListView(kind) {return Object.values(this.rowListExtensions[kind] || {}).some((extension) => extension.hasView?.(),