Agent Zero AI framework
feat(pin-to-top): add plugin-owned sidebar pin indicators
Alessandroceb252ff87db
diff --git a/plugins/_pin_to_top/AGENTS.md b/plugins/_pin_to_top/AGENTS.mdindex 553c4102e..e282c3705 100644--- a/plugins/_pin_to_top/AGENTS.md+++ b/plugins/_pin_to_top/AGENTS.md@@ -10,16 +10,18 @@- `helpers/pins.py` and `api/` own persistent pin state and authenticated toggle/read endpoints.- `webui/pin-to-top-store.js` owns row ordering, divider callbacks, and the project pin interface used by Folder view.- `extensions/webui/sidebar-row-actions-menu/` owns the dropdown action.+- `extensions/webui/initFw_end/pin-indicators.js` decorates existing chat, parallel-child, and task titles with passive Alpine-bound icons; indicator styling belongs to this plugin's menu extension.## Local Contracts- Pin state is separated into `chat`, `task`, and `project` groups and stored under the `plugin_pin_to_top` persistent KVP key; older state without `project` remains valid.- Project keys are validated project directory names, with `""` reserved for the virtual **No project** folder. Adding a named project pin requires its project header to exist; removing a stale pin remains possible. Empty chat/task IDs and missing project IDs remain invalid.-- **No project** is pinned by default with timestamp `1.0`, ahead of dated pins. Persist `no_project_pin_initialized` with pin changes so an explicit unpin survives reloads and changes to other pins; older pin state receives the default without losing existing pins.+- **No project** is pinned by default with timestamp `1.0`, ahead of dated project pins. Persist `no_project_pin_initialized` with pin changes so an explicit unpin survives reloads and changes to other pins; older pin state receives the default without losing existing pins.- Folder view reads `pins.project`, calls `isProjectPinned(name)` / `toggleProjectPin(name)`, and can sort groups with `sortItems("project", items)` where each item has `id: name`.- The plugin must register sidebar row-list callbacks; it must not patch chat/task stores or inject controls directly into rows.- Pinned items sort before unpinned items, older pins remain first, and existing order is preserved within the unpinned group.- The menu label and icon must reflect whether the active row is pinned.+- Keep pin markup, styling, and visibility inside this plugin. The idempotent startup decorator handles added rows in both list views; Alpine owns icon reactivity and cleanup when rows are removed. Do not add pin-specific hooks to the core sidebar or copy its row templates.## Work Guidance@@ -29,6 +31,7 @@## Verification- Run `pytest plugins/_pin_to_top/tests tests/test_sidebar_row_actions.py`.+- Verify one reactive indicator per parent, worker, and task title after pin/unpin, folder collapse/remount, and flat/folder switching; core sidebar files must stay free of pin-specific code.## Child DOX Indexdiff --git a/plugins/_pin_to_top/README.md b/plugins/_pin_to_top/README.mdindex a193664cd..37f4fad2c 100644--- a/plugins/_pin_to_top/README.md+++ b/plugins/_pin_to_top/README.md@@ -3,6 +3,7 @@Built-in Agent Zero plugin for pinning chats, scheduled tasks, and project folders to the top of their sidebar lists.- Adds a context-aware **Pin to Top** / **Unpin from Top** action to the sidebar row menu.+- Marks pinned chats, parallel workers, and tasks with a small pin icon beside their title.- Keeps pinned items in pin order and preserves the existing order within the unpinned group.- Separates pinned and unpinned items with the standard sidebar divider.- Persists state in Agent Zero's user key-value storage.diff --git a/plugins/_pin_to_top/extensions/webui/initFw_end/pin-indicators.js b/plugins/_pin_to_top/extensions/webui/initFw_end/pin-indicators.jsnew file mode 100644index 000000000..b35f8963d--- /dev/null+++ b/plugins/_pin_to_top/extensions/webui/initFw_end/pin-indicators.js@@ -0,0 +1,36 @@+import { store } from "/plugins/_pin_to_top/webui/pin-to-top-store.js";++const TITLES = "#chats-section .chat-name, #tasks-section .task-name";+let observer = null;++function addIndicator(title) {+ if (title.nextElementSibling?.classList.contains("pin-to-top-indicator")) return;+ const task = title.classList.contains("task-name");+ const item = task ? "task" : title.closest(".chat-child-list") ? "child" : "context";+ const icon = document.createElement("x-icon");+ icon.className = "pin-to-top-indicator";+ icon.setAttribute("name", "push_pin");+ icon.setAttribute("aria-label", "Pinned");+ icon.setAttribute("x-cloak", "");+ icon.setAttribute("x-show", `$store.pinToTop.isPinned('${task ? "task" : "chat"}', ${item}.id)`);+ title.after(icon);+}++function scan(root) {+ if (root.matches?.(TITLES)) addIndicator(root);+ root.querySelectorAll(TITLES).forEach(addIndicator);+}++export default function initPinIndicators() {+ if (observer) return;+ store.init();+ scan(document);+ observer = new MutationObserver((mutations) => {+ for (const mutation of mutations) {+ for (const node of mutation.addedNodes) {+ if (node instanceof Element) scan(node);+ }+ }+ });+ observer.observe(document.body, { childList: true, subtree: true });+}diff --git a/plugins/_pin_to_top/extensions/webui/sidebar-row-actions-menu/pin-to-top.html b/plugins/_pin_to_top/extensions/webui/sidebar-row-actions-menu/pin-to-top.htmlindex ec529c0cd..8e68996d7 100644--- a/plugins/_pin_to_top/extensions/webui/sidebar-row-actions-menu/pin-to-top.html+++ b/plugins/_pin_to_top/extensions/webui/sidebar-row-actions-menu/pin-to-top.html@@ -14,5 +14,12 @@x-text="$store.pinToTop.isMenuItemPinned($store.sidebar.rowMenuOpenId, $store.sidebar.rowMenuKind) ? 'Unpin from Top' : 'Pin to Top'"></span></button></div>+ <style>+ .pin-to-top-indicator {+ flex-shrink: 0;+ font-size: 12px;+ color: var(--color-text-muted);+ }+ </style></body></html>diff --git a/plugins/_pin_to_top/tests/test_pins.py b/plugins/_pin_to_top/tests/test_pins.pyindex b4123d753..6b0b31a16 100644--- a/plugins/_pin_to_top/tests/test_pins.py+++ b/plugins/_pin_to_top/tests/test_pins.py@@ -172,6 +172,15 @@ assert.equal(calls.length, callCount, 'only an explicit empty project ID represesubprocess.run(["node", "--input-type=module", "-e", script, str(store)], check=True)+def test_pin_presentation_does_not_depend_on_core_sidebar_pin_code():+ sidebar = Path(__file__).resolve().parents[3] / "webui/components/sidebar"+ for name in ("sidebar-store.js", "left-sidebar.html", "chats/chat-tree.html", "tasks/task-row.html"):+ source = (sidebar / name).read_text(encoding="utf-8")+ assert "isRowPinned" not in source+ assert "pinToTop" not in source+ assert 'name="push_pin"' not in source++def test_pin_endpoints_keep_default_auth_and_csrf_protection():for handler in (GetPins, TogglePin):assert handler.requires_auth() is True