Files
PaperClipAI/ui/src/lib/task-side-panel-state.test.ts
T
Nicky LeachandPaperclip c7c12dbc79 Support plugin panels in task sidebars (#17796)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Task side panels keep live work beside the conversation.
> - Plugins can already provide agent detail tabs.
> - Those tabs have no generic way to appear beside the task that is
using the agent.
> - This pull request adds an optional task-side-panel declaration to
agent detail tabs.
> - The plugin owns the label, component and availability. Core supplies
the task's running agent.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Access to plugin-contributed live views from task chat.

**Subsystem affected**

Plugin manifest validation, slot discovery, and task side-panel
UI/state.

**Current behavior**

Agent detail-tab contributions appear on agent pages. A task cannot
offer the same view through a plugin-owned availability decision.

**Proposed behavior**

An agent detail tab can declare `taskSidePanel: { availabilityPath }`.
Core substitutes the running agent into the plugin-local path. A
declared board GET route scoped to that agent returns `{ available:
boolean }`. Available contributions appear in desktop and mobile task
side panels.

**Reason and benefit**

Keep the task and its live plugin views together. Preserve plugin
ownership of provider protocols and product behavior. Core contains no
concrete plugin identifiers, routes, labels or readiness rules.

**Breaking changes**

None. The field is optional. Existing contributions remain unchanged.
Missing, disabled or unavailable plugins add no panel.

**Additional context**

Related: #17111 established the agent detail-tab and scoped API
extension surfaces. Roadmap and related PR searches found no duplicate
of this extension.

## What Changed

- Extend the manifest with optional task-panel metadata. Validate safe
plugin-local paths and require a declared board GET route with
agent-scoped authorization.
- Discover and load only opted-in agent contributions. Poll their
generic availability responses and mount the existing components with
agent context.
- Add generic panel tabs, launcher entries, dismissal and inactive-view
removal in desktop/mobile task chat.
- Reuse the existing live-run polling guard so idle tasks with a healthy
live connection stop polling.
- Add provider-neutral fixtures, schema/authorization tests, task tests
and SDK/feature documentation.

## Verification

- PASS: 301 focused tests including the full task-detail file, generic
panel discovery, persistence, slot loading and manifest validation.
Regressions cover POST-before-GET route order, mobile drawer dismissal,
recovery without focus and the absence of the hidden desktop task panel
on mobile.
- PASS: UI and shared-package typechecks; production UI build; token
gates, feature-map and module-boundary checks; diff and secrets/PII
review.
- PASS on final head: all 795 UI files / 9,186 tests, and all 95
shared-package files / 1,038 tests. Commands: `node
node_modules/vitest/vitest.mjs run --project @paperclipai/ui
--maxWorkers 3` and the corresponding `--project @paperclipai/shared`
command with local socket access.
- On the final head, server shards 7/12 and 10/12 and workspace shard
a-1/2 were interrupted by runner shutdown/communication loss. GitHub
reported infrastructure failures; no assertion failure was surfaced in
the available diagnostics. The queued summary was cancelled, then `gh
run rerun --failed` successfully requested retries for only those three
jobs. They are currently queued for CI runners; the 50 successful checks
remain passing. Interrupted attempts are not counted as passing.
[Final-head CI and
retry](https://github.com/paperclipai/paperclip/actions/runs/40396870920).
- Earlier verification exposed an empty-panel rerender loop, which was
fixed. The sandboxed combined run also failed five shared port-registry
tests because it could not bind loopback listeners; the full shared
rerun with socket access passed. These earlier failures are retained
here rather than reported as passing runs.
- Full workspace typecheck/build were attempted with pinned pnpm 9 after
resolving the initial local package-manager setup. Both stop at the
unchanged Runner Rust step because `cargo` is not installed. Full local
workspace checks are not reported as passing; final CI must provide
those broader checks.
- No live provider or plugin-specific transport acceptance is claimed by
Core's synthetic fixtures.

## Risks

- Availability is polled every three seconds only while an authorized
running agent exists. Plugins own the side effects and meaning of that
read.
- A view uses the running agent's context. It is not a separate per-task
resource.
- Optional metadata adds no backend endpoint or permission bypass. The
host requires existing board and agent authorization.
- Reverting the optional contract and UI integration removes task panels
without a data migration.

## Model Used

OpenAI Codex (GPT-6), with reasoning, repository tools and code
execution. The exact backend snapshot ID and context window size are not
exposed by this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have described the issue in-PR following the relevant issue
template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
ticket id
- [x] I have run focused tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-26 14:47:15 -07:00

128 lines
5.1 KiB
TypeScript

// @vitest-environment jsdom
import { beforeEach, describe, expect, it } from "vitest";
import {
readTaskSidePanelState,
taskPanelDocumentTab,
taskPanelPluginTab,
taskPanelFilesTab,
taskPanelPropertiesTab,
taskPanelSkillTab,
taskPanelSubtasksTab,
writeTaskSidePanelState,
shouldSuppressTaskPanelUntilPlan,
openSkillPanelState,
} from "./task-side-panel-state";
describe("task side-panel persistence", () => {
beforeEach(() => window.localStorage.clear());
it("round-trips a plugin panel identity", () => {
const entityId = "33333333-3333-4333-8333-333333333333";
const panel = { entityId, slot: { pluginKey: "example.live-view", id: "screen", displayName: "Live view" } };
const id = `plugin:example.live-view:screen:${entityId}`;
writeTaskSidePanelState("user-1", "company-1", "task-1", {
state: { tabs: [taskPanelPluginTab(panel)], activeTabId: id },
launcherOpen: false, userInteracted: true, autoPlanHandled: true, updatedAt: 1,
});
expect(readTaskSidePanelState("user-1", "company-1", "task-1", true)?.state).toMatchObject({
tabs: [{ payload: { kind: "plugin-panel", pluginKey: "example.live-view", slotId: "screen", entityId } }], activeTabId: id,
});
});
it("round-trips an intentionally empty task state", () => {
writeTaskSidePanelState("user-1", "company-1", "task-1", {
state: { tabs: [], activeTabId: null },
launcherOpen: false,
userInteracted: true,
autoPlanHandled: true,
updatedAt: 1,
});
expect(readTaskSidePanelState("user-1", "company-1", "task-1", true)).toMatchObject({
state: { tabs: [], activeTabId: null },
userInteracted: true,
});
});
it("persists and restores a skill tab", () => {
writeTaskSidePanelState("user-1", "company-1", "task-skill", {
state: { tabs: [taskPanelPropertiesTab(), taskPanelSkillTab("skill-1", "Release helper")], activeTabId: "skill:skill-1" },
launcherOpen: false,
userInteracted: true,
autoPlanHandled: false,
updatedAt: 1,
});
expect(readTaskSidePanelState("user-1", "company-1", "task-skill", true)?.state).toMatchObject({
activeTabId: "skill:skill-1",
tabs: [{ id: "properties" }, { id: "skill:skill-1", payload: { kind: "skill", skillId: "skill-1" } }],
});
});
it("keeps an onboarding panel open after skill acknowledgement", () => {
const before = { panelBeforePlanOverrideIssueId: null };
const opened = openSkillPanelState(before, { id: "skill-1", name: "Release helper" }, "task-1", true);
expect(opened.panelBeforePlanOverrideIssueId).toBe("task-1");
const acknowledged = { ...opened, skill: null };
expect(shouldSuppressTaskPanelUntilPlan({ deferredPlanAvailable: false, panelBeforePlanOverride: acknowledged.panelBeforePlanOverrideIssueId === "task-1" })).toBe(false);
});
it("isolates account and company state", () => {
writeTaskSidePanelState("user-1", "company-1", "task-1", {
state: { tabs: [taskPanelPropertiesTab()], activeTabId: "properties" },
launcherOpen: false,
userInteracted: false,
autoPlanHandled: false,
updatedAt: 1,
});
expect(readTaskSidePanelState("user-2", "company-1", "task-1", true)).toBeNull();
expect(readTaskSidePanelState("user-1", "company-2", "task-1", true)).toBeNull();
});
it("drops file tabs when the experiment is disabled while keeping documents", () => {
writeTaskSidePanelState("user-1", "company-1", "task-1", {
state: {
tabs: [taskPanelPropertiesTab(), taskPanelFilesTab(), taskPanelDocumentTab("plan", "Plan")],
activeTabId: "files",
},
launcherOpen: false,
userInteracted: true,
autoPlanHandled: true,
updatedAt: 1,
});
const restored = readTaskSidePanelState("user-1", "company-1", "task-1", false);
expect(restored?.state.tabs.map((tab) => tab.id)).toEqual(["properties", "document:plan"]);
expect(restored?.state.activeTabId).toBe("properties");
});
it("round-trips the Streamlined UI subtasks tab", () => {
writeTaskSidePanelState("user-1", "company-1", "task-1", {
state: {
tabs: [taskPanelPropertiesTab(), taskPanelSubtasksTab()],
activeTabId: "subtasks",
},
launcherOpen: false,
userInteracted: true,
autoPlanHandled: true,
updatedAt: 1,
});
const restored = readTaskSidePanelState("user-1", "company-1", "task-1", false);
expect(restored?.state.tabs.map((tab) => tab.id)).toEqual(["properties", "subtasks"]);
expect(restored?.state.activeTabId).toBe("subtasks");
});
it("retains only the 50 most recently written tasks", () => {
for (let index = 0; index < 52; index += 1) {
writeTaskSidePanelState("user-1", "company-1", `task-${index}`, {
state: { tabs: [taskPanelPropertiesTab()], activeTabId: "properties" },
launcherOpen: false,
userInteracted: false,
autoPlanHandled: false,
updatedAt: index,
});
}
expect(readTaskSidePanelState("user-1", "company-1", "task-0", true)).toBeNull();
expect(readTaskSidePanelState("user-1", "company-1", "task-51", true)).not.toBeNull();
});
});