From 31e07fab34c0ca47d8790140be4564f14917cf0f Mon Sep 17 00:00:00 2001 From: Alassane <79718216+yattdev@users.noreply.github.com> Date: Sat, 15 Aug 2026 12:00:02 -0400 Subject: [PATCH] feat(plugins): add sidebar workspace actions to New Task (#2607) Co-authored-by: ayattara Co-authored-by: Carlos Florencio --- .../fixture-package/ui/bundle.js | 24 ++++ .../plugins/user_state_handlers_test.go | 100 ++++++++++++++ apps/web/AGENTS.md | 2 +- .../app-sidebar-new-task-item.test.tsx | 128 +++++++++++++++++- .../app-sidebar/app-sidebar-new-task-item.tsx | 14 +- .../app-sidebar-workspace-actions.tsx | 81 +++++++++++ .../components/kanban/mobile-menu-sheet.tsx | 8 +- .../navigation/app-nav-sections.tsx | 4 + .../navigation/app-nav-sheet.test.tsx | 35 ++++- .../components/navigation/app-nav-sheet.tsx | 2 + ...e-plugin-sidebar-workspace-actions.spec.ts | 45 ++++++ .../plugin-sidebar-workspace-actions.spec.ts | 94 +++++++++++++ .../tests/plugins/plugin-task-panel.spec.ts | 109 ++++++++------- apps/web/lib/plugins/types.ts | 20 ++- docs/plans/plugins/PLUGIN-API.md | 9 +- docs/public/plugins-authoring.md | 35 +++-- docs/specs/plugins/spec.md | 27 ++++ 17 files changed, 659 insertions(+), 78 deletions(-) create mode 100644 apps/web/components/app-sidebar/app-sidebar-workspace-actions.tsx create mode 100644 apps/web/e2e/tests/plugins/mobile-plugin-sidebar-workspace-actions.spec.ts create mode 100644 apps/web/e2e/tests/plugins/plugin-sidebar-workspace-actions.spec.ts diff --git a/apps/backend/cmd/plugin-fixture/fixture-package/ui/bundle.js b/apps/backend/cmd/plugin-fixture/fixture-package/ui/bundle.js index f59c7c3c45..367bba9c90 100644 --- a/apps/backend/cmd/plugin-fixture/fixture-package/ui/bundle.js +++ b/apps/backend/cmd/plugin-fixture/fixture-package/ui/bundle.js @@ -356,6 +356,29 @@ ); } + function WorkspaceActionsSlot(props) { + var slotProps = props.slotProps || {}; + return jsx( + "button", + { + type: "button", + "data-testid": "e2e-sidebar-workspace-actions", + "data-workspace-id": slotProps.workspaceId, + "data-workspace-label": slotProps.workspaceLabel || "", + "data-presentation": slotProps.presentation || "unknown", + "aria-label": "Fixture workspace action", + className: + slotProps.presentation === "mobile" + ? "flex h-11 w-11 cursor-pointer items-center justify-center rounded-md border" + : "flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border", + onClick: function (event) { + event.currentTarget.setAttribute("data-clicked", "true"); + }, + }, + "W", + ); + } + function StatusSlot(props) { var slotProps = props.slotProps || {}; var id = slotProps.placement === "left" ? "hello-status-left" : "hello-status-right"; @@ -602,6 +625,7 @@ registry.registerComponent("new-session-input-actions", ComposerAction); registry.registerComponent("task-card-indicators", CardIndicator); registry.registerComponent("task-card-tags", CardTags); + registry.registerComponent("sidebar-workspace-actions", WorkspaceActionsSlot); registry.registerTaskMenuAction({ id: "enhance-notes", label: "Enhance notes", diff --git a/apps/backend/internal/plugins/user_state_handlers_test.go b/apps/backend/internal/plugins/user_state_handlers_test.go index 4ab798e29d..6e29644c47 100644 --- a/apps/backend/internal/plugins/user_state_handlers_test.go +++ b/apps/backend/internal/plugins/user_state_handlers_test.go @@ -153,6 +153,106 @@ func TestUserStateGETFromDifferentUserReturns404(t *testing.T) { } } +// TestUserStateWorkspaceScopeIsolatesUsersAndScopes covers the workspace +// scope the way TestUserStateGETFromDifferentUserReturns404 covers the task +// scope. Workspace-scoped entries only became a shipping surface with the +// sidebar-workspace-actions slot (kandev-plugin-notes' per-workspace note), +// and that note's UI promises "only you can see this note" — so the negative +// is asserted for every verb, not just GET: a second user must not read, +// overwrite, delete, or enumerate the first user's workspace note. +// +// The same subtest also pins scope separation on an identical raw id: +// task/X and workspace/X are different entries, which is what lets the +// plugin key one cache by ":" without conflating the two. +func TestUserStateWorkspaceScopeIsolatesUsersAndScopes(t *testing.T) { + router, svc, _ := newUserStateTestRouter(t) + installUserStatePlugin(t, svc, "kandev-plugin-notes", true) + + const ( + wsPath = "/api/plugins/kandev-plugin-notes/user-state/workspace/ws_1/note" + wsList = "/api/plugins/kandev-plugin-notes/user-state/workspace/ws_1" + taskPath = "/api/plugins/kandev-plugin-notes/user-state/task/ws_1/note" + ) + + rec := userStateReq(router, http.MethodPut, wsPath, "user_1", `{"value":"alice's workspace note"}`) + if rec.Code != http.StatusOK { + t.Fatalf("PUT status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + if rec = userStateReq(router, http.MethodPut, taskPath, "user_1", `{"value":"task-scoped"}`); rec.Code != http.StatusOK { + t.Fatalf("PUT task scope status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + + // user_2 must not read it. + if rec = userStateReq(router, http.MethodGet, wsPath, "user_2", ""); rec.Code != http.StatusNotFound { + t.Fatalf("GET (different user) status = %d, want 404, body=%s", rec.Code, rec.Body.String()) + } + + // user_2 must not enumerate it. + rec = userStateReq(router, http.MethodGet, wsList, "user_2", "") + if rec.Code != http.StatusOK { + t.Fatalf("LIST (different user) status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + var user2List struct { + Entries []state.UserStateEntry `json:"entries"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &user2List); err != nil { + t.Fatalf("unmarshal LIST (different user): %v", err) + } + if len(user2List.Entries) != 0 { + t.Fatalf("LIST (different user) returned entries: %+v", user2List.Entries) + } + + assertUserStateValue(t, router, taskPath, "user_1", `"task-scoped"`) + rec = userStateReq(router, http.MethodGet, wsList, "user_1", "") + if rec.Code != http.StatusOK { + t.Fatalf("LIST (workspace scope) status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + var workspaceList struct { + Entries []state.UserStateEntry `json:"entries"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &workspaceList); err != nil { + t.Fatalf("unmarshal LIST (workspace scope): %v", err) + } + if len(workspaceList.Entries) != 1 || workspaceList.Entries[0].Key != "note" { + t.Fatalf("LIST (workspace scope) entries = %+v, want only note", workspaceList.Entries) + } + + // user_2 writing the same path must not disturb user_1's value, and + // user_2 deleting it must not delete user_1's. + if rec = userStateReq(router, http.MethodPut, wsPath, "user_2", `{"value":"bob's own"}`); rec.Code != http.StatusOK { + t.Fatalf("PUT (different user) status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + if rec = userStateReq(router, http.MethodDelete, wsPath, "user_2", ""); rec.Code != http.StatusOK { + t.Fatalf("DELETE (different user) status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + assertUserStateValue(t, router, wsPath, "user_1", `"alice's workspace note"`) + assertUserStateValue(t, router, taskPath, "user_1", `"task-scoped"`) + + // task/ws_1 and workspace/ws_1 are distinct entries for the same user. + if rec = userStateReq(router, http.MethodDelete, wsPath, "user_1", ""); rec.Code != http.StatusOK { + t.Fatalf("DELETE workspace scope status = %d, want 200, body=%s", rec.Code, rec.Body.String()) + } + assertUserStateValue(t, router, taskPath, "user_1", `"task-scoped"`) +} + +// assertUserStateValue fails unless userID's entry at path holds want. +func assertUserStateValue(t *testing.T, router *gin.Engine, path, userID, want string) { + t.Helper() + rec := userStateReq(router, http.MethodGet, path, userID, "") + if rec.Code != http.StatusOK { + t.Fatalf("GET %s status = %d, want 200, body=%s", path, rec.Code, rec.Body.String()) + } + var resp struct { + Value json.RawMessage `json:"value"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil { + t.Fatalf("unmarshal %s: %v", path, err) + } + if string(resp.Value) != want { + t.Fatalf("GET %s value = %s, want %s", path, resp.Value, want) + } +} + // TestUserStateWithoutCapabilityReturns403 pins AC17. func TestUserStateWithoutCapabilityReturns403(t *testing.T) { router, svc, _ := newUserStateTestRouter(t) diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md index 4707b9fa12..e7f6ee34e1 100644 --- a/apps/web/AGENTS.md +++ b/apps/web/AGENTS.md @@ -91,7 +91,6 @@ For rebasing or finishing PRs written against the old Next.js runtime, follow [` Use subscription hooks only; the WS client auto-deduplicates. **Task overview vs. session detail:** Shared task rows read `Task.statusSummary` and `task.status_summary.updated`; rich streams stay session-detail-only. Extend the bounded projection per the [spec](../../docs/specs/platform/bounded-task-status-delivery.md) and [ADR](../../docs/decisions/2026-08-01-separate-task-summary-session-stream-traffic.md). - **Branch-scoped task state:** For live worktree/session state plus `task_prs`, key by `(repository, checked-out branch)`, not task/repository alone. `branch_switched` invalidates prior status/commits; reject late results with a generation/identity guard and preserve siblings. Historical PRs affect Changes only when `repository_id` and normalized `head_branch` match; Review/PR history may still show them. Test single/multi-repo cases and desktop/mobile Changes behavior. **HTTP/WS cache races:** When HTTP hydrates a cache also updated by WebSockets, guard responses with per-scope revision and request/workspace generation; discard or refresh stale responses and cover deferred responses. `useEnsureTaskSession` re-fires `session.ensure` when an open task page sees zero sessions after a prior ensure, so deleting the last session from that page spawns a replacement; test zero-session states through the backend/API instead. @@ -287,6 +286,7 @@ plugin leaks a stale registration. - **Kanban card contributions:** `registerTaskMenuAction({ group: "edit", ... })` turns the flat `Edit` item into an `Edit` submenu (`kanban-card-edit-submenu.tsx`); `registerComponent("task-card-indicators", ...)` renders beside `PRTaskIcon` via ``; `task-card-tags` renders in its own row below the badges (for contributions too wide for the title-row indicators spot, e.g. tag chips). +- **Sidebar workspace actions:** `registerComponent("sidebar-workspace-actions", ...)` renders after Quick Terminal/Quick Chat in the desktop sidebar's New Task row and in the shared phone navigation sheet, forwarding `SidebarWorkspaceActionsSlotProps` with `presentation: "desktop" | "mobile"`; mobile plugin controls own a 44px touch target and accessible name. - **`host.storage`:** authenticated per-user key/value storage (`lib/plugins/host-api.ts`), backed by `/api/plugins/{id}/user-state/...` (`docs/decisions/2026-08-01-per-user-plugin-storage.md`). `subscribe` (`lib/plugins/user-state-sync.ts`) wraps `registerWsHandler` with own-plugin filtering diff --git a/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx b/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx index 8b4eafed0b..6fbdb6168c 100644 --- a/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx +++ b/apps/web/components/app-sidebar/app-sidebar-new-task-item.test.tsx @@ -1,6 +1,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; import { act, cleanup, fireEvent, render, screen } from "@testing-library/react"; import { TooltipProvider } from "@kandev/ui/tooltip"; +import type { JSX } from "react"; const mocks = vi.hoisted(() => ({ routerPush: vi.fn(), @@ -21,10 +22,13 @@ function renderItem(collapsed: boolean) { ); } +const WORKSPACE_ID = "ws-1"; +const WORKSPACE_NAME = "Default Workspace"; + const state = { workspaces: { - activeId: "ws-1" as string | null, - items: [{ id: "ws-1", name: "Default Workspace" }], + activeId: WORKSPACE_ID as string | null, + items: [{ id: WORKSPACE_ID, name: WORKSPACE_NAME }], }, appSidebar: { improveDialogOpen: false }, kanban: { @@ -40,6 +44,22 @@ const QUICK_CHAT_TEST_ID = "sidebar-quick-chat-shortcut"; let officeEnabled = false; let pathname = "/"; +// sidebar-workspace-actions plugin slot registrations (A1-A5). Empty by +// default so the existing dialog-routing/row-action tests above are +// unaffected; individual tests below set this before rendering. +let workspaceActionsRegistrations: Array<{ + registrationId: string; + pluginId: string; + Component: (props: { slotProps?: unknown }) => JSX.Element; +}> = []; + +vi.mock("@/lib/plugins/registry", () => ({ + usePluginRegistry: () => ({ + getSlotRegistrations: (name: string) => + name === "sidebar-workspace-actions" ? workspaceActionsRegistrations : [], + }), +})); + vi.mock("@/components/state-provider", () => ({ useAppStore: (selector: (s: typeof state) => unknown) => selector(state), })); @@ -95,14 +115,14 @@ const REGULAR_DIALOG_TESTID = "regular-task-create-dialog"; function setImproveWorkspaceActive() { state.workspaces.activeId = "ws-improve"; state.workspaces.items = [ - { id: "ws-1", name: "Default Workspace" }, + { id: WORKSPACE_ID, name: WORKSPACE_NAME }, { id: "ws-improve", name: "Improve Kandev" }, ]; } function resetTestState() { - state.workspaces.activeId = "ws-1"; - state.workspaces.items = [{ id: "ws-1", name: "Default Workspace" }]; + state.workspaces.activeId = WORKSPACE_ID; + state.workspaces.items = [{ id: WORKSPACE_ID, name: WORKSPACE_NAME }]; state.appSidebar.improveDialogOpen = false; state.kanban.workflowId = "wf-1"; state.kanban.steps = [{ id: "s1", title: "Todo" }]; @@ -116,6 +136,7 @@ function resetTestState() { mocks.dialogWillNavigate = false; officeEnabled = false; pathname = "/"; + workspaceActionsRegistrations = []; } beforeEach(resetTestState); @@ -255,6 +276,103 @@ describe("AppSidebarNewTaskItem row actions", () => { }); }); +describe("AppSidebarNewTaskItem sidebar-workspace-actions plugin slot", () => { + const PLUGIN_TEST_ID = "plugin-workspace-action"; + const INSET_TEST_ID = "create-task-button"; + + function registerPlugin(Component: (props: { slotProps?: unknown }) => JSX.Element) { + workspaceActionsRegistrations = [{ registrationId: "reg-1", pluginId: "plugin-1", Component }]; + } + + function registerPlugins(components: Array<(props: { slotProps?: unknown }) => JSX.Element>) { + workspaceActionsRegistrations = components.map((Component, index) => ({ + registrationId: `reg-${index + 1}`, + pluginId: `plugin-${index + 1}`, + Component, + })); + } + + it("A1: renders a registered component after Quick Terminal and Quick Chat", () => { + registerPlugin(() =>