mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-28 12:04:41 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The board has two different pages for change history: a basic Activity list and a rich Audit feed > - The two pages show the same kind of information, so an operator must guess which page to open > - The basic list also caps at 200 rows and has no filters, so it hides older changes > - This pull request merges both pages into one Activity page that is built on the rich audit feed > - The page adds a scope toggle for all actors or agent actions only, and it hides privileged controls from members who do not have the audit permission > - The benefit is one obvious place to answer "who changed what", for every member, with filters and full history ## Linked Issues or Issue Description Related pull requests in this stack (open both before this one): - Refs #10830 — adds the company prefix to the board audit route. - Refs #10831 — adds the two-tier all-actors scope to the audit endpoint. This pull request calls that scope. This branch is stacked on those two pull requests. The diff therefore shows their commits until they merge. After they merge, this pull request contains only the last two commits: the page merge and the actor-label fix. **Problem or motivation** The board has two overlapping history pages. `/:company/activity` renders a plain list that is capped at 200 rows and has no filters. The audit page renders a filtered, paginated feed of agent actions, but it is a separate sidebar item and it was reachable only by members with the audit permission. A member who wants to know who changed an issue must know which of the two pages answers the question. **Proposed solution** Keep one sidebar item, "Activity", and build it on the rich feed. Add a scope toggle: "All activity" reads every actor kind, and "Agent actions" keeps the earlier audit behavior. Put the scope in the `mode` query parameter so a person can link to it. Show the responsible-user filter and the CSV export only to callers that the server answers at the privileged tier. Redirect the earlier audit paths to the merged page with the agent scope preset, so old links continue to work. Delete the plain list page. **Alternatives considered** Keeping both pages and adding filters to the plain list. That duplicates the feed logic and keeps the "which page?" problem. Deleting the audit page instead was also rejected, because the audit feed has the pagination, filters, and export that the plain list does not. **Roadmap alignment** The roadmap marks the activity log and action attribution as shipped. This change improves that shipped capability. It does not add a new subsystem. ## What Changed - Added a scope toggle to `AuditFeed`. "All activity" requests `actorScope=all`, and "Agent actions" keeps the earlier agent-only request. Cursor pagination works in both scopes. - Stored the scope in the `mode` query parameter, so a person can bookmark or share a scope. - Made the page chrome permission-aware. The toggle, the responsible-user filter, and the CSV export appear only when the server answers at the privileged tier. A basic member sees the shared feed and no upsell wall. - Replaced the sidebar "Audit" item. The sidebar now has one "Activity" item. - Redirected `/:company/audit` and the unprefixed `/audit` to `/:company/activity?mode=agents`. - Deleted the earlier `ui/src/pages/Activity.tsx` list page and the `CompanyAudit` page wrapper. Added `CompanyActivity` as the single route target. - Fixed the actor label for stripped rows. The basic tier removes the agent id but keeps the actor kind, so every agent row rendered as "System". Rows now fall back to the actor kind: "Agent", "User", "Plugin", or "System". - Widened the responsible-user filter control, which truncated its own label. - Resolved agent names on the basic tier. The basic tier removes the privileged `agentId` but keeps the acting principal `actorId`, and the company agent directory this page already reads is authorization-filtered. The feed therefore resolves an agent actor from `agentId` first and from an agent-typed `actorId` second. Hiding the name only in the UI gave no confidentiality benefit, because any reader could join the retained id against the readable directory. Agents that the directory filters out still fall back to the generic kind label. No server payload or permission was widened. - Fixed a stuck state in the access-downgrade recovery. A downgrade between cursor requests leaves full-tier and basic-tier pages in one cache, which starts a single recovery refetch. If that refetch did not clear the mix, the cached pages kept the condition true, the "Refreshing audit access…" banner rendered permanently, and it hid the error state together with its "Try again" button. The banner is now tied to an outstanding attempt. The refetch effect also depended on the whole query object, which changes identity every render, so it repeated the request on each render; the attempt is now tracked in state and runs once per downgrade. - Kept the agent detail "Audit" tab unchanged. That tab passes a locked agent id, which keeps the earlier privileged scope and hides the toggle. The `GET /companies/:id/activity` endpoint stays. The dashboard still reads it. This pull request does not change that endpoint. ## Verification - `pnpm exec vitest run ui/src/pages/audit/AuditFeed.test.tsx ui/src/App.activity-routing.test.tsx ui/src/lib/company-routes.test.ts ui/src/components/Sidebar.test.tsx server/src/__tests__/activity-routes.test.ts server/src/__tests__/agent-action-audit-routes.test.ts` — all tests pass. - New `ui/src/App.activity-routing.test.tsx` drives the real route table. It asserts that the company activity path resolves, and that both the company audit path and the unprefixed audit path reach the activity path with the agent scope preset. - New `AuditFeed` tests cover the scope toggle, the basic tier without privileged chrome, the locked-agent case, the actor-kind fallback label, basic-tier name resolution, and both downgrade-recovery paths (the refetch errors, and the refetch returns a still-mixed pair). - Mutation-checked the three new guards: disabling each one fails the test that covers it, so none of them pass vacuously. - `pnpm -r typecheck` is clean. Both design token gates are clean. - Rendered every state in a browser at 1440x900 and at 390x844: both scopes, the basic member view, the loading state, the error state, the filtered-empty state, and the true-empty state. A designer reviewed the renders and approved them. ## Risks - The default company page now reads the all-actors scope, which returns more rows than the earlier agent-only query. Cursor pagination and the existing page limit bound each request. - The page is now visible to every company member. The server decides what each member sees. The UI only hides controls that the caller cannot use. Refs #10831 for the server rules and tests. - The basic tier now shows agent names that the previous revision withheld. The name was already recoverable from the retained `actorId` through the readable agent directory, so this closes an inconsistency rather than widening access. A security reviewer chose this outcome over stripping `actorId`. - Old audit links now redirect. The redirect keeps the agent scope, so a person who bookmarked the audit page sees the same rows. - Low migration risk. There is no database change. > The roadmap marks activity log and action attribution as shipped. This change improves that existing capability. ## Model Used Claude Opus 5 (`claude-opus-5`, 1M context) with extended thinking and tool use, run through Claude Code. ## 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 either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run 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 - [ ] 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> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
297 lines
13 KiB
TypeScript
297 lines
13 KiB
TypeScript
import {
|
|
Inbox,
|
|
ListChecks,
|
|
CircleDot,
|
|
Target,
|
|
LayoutDashboard,
|
|
DollarSign,
|
|
History,
|
|
Search,
|
|
SquarePen,
|
|
Network,
|
|
Boxes,
|
|
Repeat,
|
|
Layers,
|
|
GitBranch,
|
|
Package,
|
|
Settings,
|
|
FolderOpen,
|
|
PanelLeftClose,
|
|
PanelLeftOpen,
|
|
Pin,
|
|
AppWindow,
|
|
MessagesSquare,
|
|
GanttChartSquare,
|
|
LayoutGrid,
|
|
} from "lucide-react";
|
|
import { useState } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { SidebarSection } from "./SidebarSection";
|
|
import { SidebarNavItem } from "./SidebarNavItem";
|
|
import { SidebarAgents } from "./SidebarAgents";
|
|
import { SidebarProjects } from "./SidebarProjects";
|
|
import { SidebarStarredProjects } from "./SidebarStarredProjects";
|
|
import { useDialogActions } from "../context/DialogContext";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { useSidebar } from "../context/SidebarContext";
|
|
import { attentionApi } from "../api/attention";
|
|
import { heartbeatsApi } from "../api/heartbeats";
|
|
import { instanceSettingsApi } from "../api/instanceSettings";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import { attentionBadgeCount } from "../lib/attention";
|
|
import { useInboxBadge } from "../hooks/useInboxBadge";
|
|
import { usePublishSharedQueryData, useSharedPollingQuery } from "../hooks/useSharedPolling";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
|
import { cn, SIDEBAR_RAIL_HIDDEN_LABEL } from "../lib/utils";
|
|
import { PluginSlotOutlet } from "@/plugins/slots";
|
|
import { PluginLauncherOutlet } from "@/plugins/launchers";
|
|
import { SidebarCompanyMenu } from "./SidebarCompanyMenu";
|
|
|
|
export function Sidebar() {
|
|
const { openNewIssue } = useDialogActions();
|
|
// Every labeled section is collapsible (session-scoped, default open) —
|
|
// one policy across static nav groups and the data-driven sections.
|
|
const [workOpen, setWorkOpen] = useState(true);
|
|
const [companyOpen, setCompanyOpen] = useState(true);
|
|
const { selectedCompanyId, selectedCompany } = useCompany();
|
|
const { isMobile, collapsed, collapseLocked, peeking, toggleCollapsed, setCollapsed } = useSidebar();
|
|
const rail = collapsed && !peeking;
|
|
const inboxBadge = useInboxBadge(selectedCompanyId);
|
|
const { data: experimentalSettings } = useQuery({
|
|
queryKey: queryKeys.instance.experimentalSettings,
|
|
queryFn: () => instanceSettingsApi.getExperimental(),
|
|
});
|
|
const liveRunsQueryKey = queryKeys.liveRuns(selectedCompanyId!);
|
|
const sharedLiveRuns = useSharedPollingQuery({
|
|
companyId: selectedCompanyId,
|
|
resourceKey: "live-runs",
|
|
queryKey: liveRunsQueryKey,
|
|
enabled: !!selectedCompanyId,
|
|
// Event-sourced via LiveUpdatesProvider (GitHub issue 9627) + reconnect reconcile — no
|
|
// interval poll needed. Polling here also re-armed React Query's timer on
|
|
// every live-event cache write, a major source of steady-state churn.
|
|
refetchInterval: false,
|
|
leaderOnly: true,
|
|
});
|
|
const { data: liveRuns, dataUpdatedAt: liveRunsUpdatedAt } = useQuery({
|
|
queryKey: liveRunsQueryKey,
|
|
queryFn: () => heartbeatsApi.liveRunsForCompany(selectedCompanyId!),
|
|
enabled: sharedLiveRuns.enabled,
|
|
refetchInterval: sharedLiveRuns.refetchInterval,
|
|
});
|
|
usePublishSharedQueryData(sharedLiveRuns, liveRuns, liveRunsUpdatedAt);
|
|
const liveRunCount = liveRuns?.length ?? 0;
|
|
const showWorkspacesLink = experimentalSettings?.enableIsolatedWorkspaces === true;
|
|
const showApps = experimentalSettings?.enableApps === true;
|
|
const showPipelines = experimentalSettings?.enablePipelines === true;
|
|
const showStatusCards = experimentalSettings?.enableStatusCards === true;
|
|
const goalsLinkPending = experimentalSettings === undefined;
|
|
const showGoalsLink = experimentalSettings?.enableGoalsSidebarLink === true;
|
|
// Decisions (attention home) is an experimental surface (PAP-13481): the nav
|
|
// item is hidden entirely until the flag is enabled (same no-flash pattern as
|
|
// showWorkspacesLink — it defaults hidden, so no placeholder is needed).
|
|
const showDecisions = experimentalSettings?.enableDecisions === true;
|
|
const { data: attentionFeed } = useQuery({
|
|
queryKey: queryKeys.attention(selectedCompanyId!),
|
|
queryFn: () => attentionApi.list(selectedCompanyId!),
|
|
enabled: !!selectedCompanyId && showDecisions,
|
|
refetchInterval: 60_000,
|
|
});
|
|
const attentionCount = attentionBadgeCount(attentionFeed);
|
|
const showCases = experimentalSettings?.enableCases === true;
|
|
// Streamlined left navigation (top-level Projects link + starred children) is
|
|
// now the standard product sidebar (PAP-12472). The former experimental
|
|
// opt-out was retired; classic per-project collapsible mode is no longer
|
|
// user-selectable. Kept as a constant so the classic branch below stays as a
|
|
// documented reference until it is fully removed. Routes are unaffected.
|
|
const streamlined = true;
|
|
// Conference Room Chat flag (PAP-136/PAP-137): the Conference Room nav item
|
|
// is a new surface, hidden entirely while the flag is off (same no-flash
|
|
// pattern as showWorkspacesLink above).
|
|
const conferenceRoomChatEnabled = experimentalSettings?.enableConferenceRoomChat === true;
|
|
|
|
const pluginContext = {
|
|
companyId: selectedCompanyId,
|
|
companyPrefix: selectedCompany?.issuePrefix ?? null,
|
|
};
|
|
|
|
return (
|
|
<aside className="w-full h-full min-h-0 border-r border-border bg-background flex flex-col">
|
|
{/* Top bar: Company name (bold) + collapse control — aligned with top
|
|
sections (no visible border). Search deliberately does NOT live here:
|
|
the header's spare width goes to the workspace/organization name,
|
|
which is the user's orientation anchor and truncates otherwise.
|
|
Search is the first nav item below instead. */}
|
|
<div className="flex items-center gap-1 px-3 h-12 shrink-0">
|
|
<SidebarCompanyMenu />
|
|
{/* In the collapsed rail the toggle doesn't fit beside the logo —
|
|
keeping it would overflow the 64px rail and squeeze the logo out of
|
|
alignment with the icon column below it. It returns as
|
|
soon as the panel is expanded (pinned) or peeking. Expansion in the
|
|
rail is still reachable via hover-peek + Pin and Cmd/Ctrl+B. */}
|
|
{!rail ? (
|
|
<>
|
|
{/* Desktop-only collapse/expand affordance. While peeking (hover flyout
|
|
over the collapsed rail) it becomes a Pin that promotes the peek to a
|
|
pinned-expanded sidebar; otherwise it toggles the pinned rail. Mobile
|
|
uses the off-canvas drawer, so this control is hidden there. It is
|
|
also hidden while a secondary sidebar forces the rail (collapseLocked):
|
|
the user cannot expand the primary while a secondary sidebar is shown. */}
|
|
{!isMobile && !collapseLocked ? (
|
|
peeking ? (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="text-muted-foreground shrink-0"
|
|
aria-label="Keep sidebar expanded"
|
|
title="Keep sidebar expanded"
|
|
onClick={() => setCollapsed(false)}
|
|
>
|
|
<Pin className="h-4 w-4" />
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="text-muted-foreground shrink-0"
|
|
aria-expanded={!collapsed}
|
|
aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
|
|
title={collapsed ? "Expand sidebar" : "Collapse sidebar"}
|
|
onClick={() => toggleCollapsed()}
|
|
>
|
|
{collapsed ? <PanelLeftOpen className="h-4 w-4" /> : <PanelLeftClose className="h-4 w-4" />}
|
|
</Button>
|
|
)
|
|
) : null}
|
|
</>
|
|
) : null}
|
|
</div>
|
|
|
|
<nav className="flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide flex flex-col gap-4 pointer-coarse:gap-3 px-3 py-2">
|
|
<div className="flex flex-col gap-0.5">
|
|
{/* New Task button aligned with nav items */}
|
|
{(() => {
|
|
const newTaskButton = (
|
|
<button
|
|
onClick={() => openNewIssue()}
|
|
data-slot="icon-button"
|
|
aria-label={rail ? "New Task" : undefined}
|
|
className="flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium text-foreground/80 hover:bg-accent/50 hover:text-foreground transition-colors"
|
|
>
|
|
<SquarePen className="h-4 w-4 shrink-0" />
|
|
<span className={rail ? SIDEBAR_RAIL_HIDDEN_LABEL : "truncate"}>New Task</span>
|
|
</button>
|
|
);
|
|
return rail ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>{newTaskButton}</TooltipTrigger>
|
|
<TooltipContent side="right">New Task</TooltipContent>
|
|
</Tooltip>
|
|
) : (
|
|
newTaskButton
|
|
);
|
|
})()}
|
|
{/* Search moved out of the header so the workspace name keeps the
|
|
width; a nav row also keeps search reachable from the
|
|
collapsed rail, where the old header icon was dropped entirely.
|
|
Cmd/Ctrl+K remains the keyboard path (command palette). */}
|
|
<SidebarNavItem to="/search" label="Search" icon={Search} />
|
|
<SidebarNavItem to="/dashboard" label="Dashboard" icon={LayoutDashboard} liveCount={liveRunCount} />
|
|
<SidebarNavItem
|
|
to="/inbox"
|
|
label="Inbox"
|
|
icon={Inbox}
|
|
badge={inboxBadge.inbox}
|
|
badgeLabel="unread"
|
|
badgeTone={inboxBadge.failedRuns > 0 ? "danger" : "default"}
|
|
alert={inboxBadge.failedRuns > 0}
|
|
/>
|
|
{showDecisions ? (
|
|
<SidebarNavItem
|
|
to="/decisions"
|
|
label="Decisions"
|
|
icon={ListChecks}
|
|
badge={attentionCount}
|
|
badgeLabel="decisions"
|
|
/>
|
|
) : null}
|
|
{showStatusCards ? (
|
|
<SidebarNavItem to="/status" label="Status" icon={LayoutGrid} textBadge="beta" />
|
|
) : null}
|
|
{conferenceRoomChatEnabled ? (
|
|
<SidebarNavItem to="/board-chat" label="Conference Room" icon={MessagesSquare} />
|
|
) : null}
|
|
</div>
|
|
|
|
<SidebarSection label="Work" collapsible={{ open: workOpen, onOpenChange: setWorkOpen }}>
|
|
<SidebarNavItem to="/issues" label="Tasks" icon={CircleDot} />
|
|
{showCases ? (
|
|
<SidebarNavItem to="/cases" label="Cases" icon={Layers} textBadge="beta" />
|
|
) : null}
|
|
<SidebarNavItem to="/routines" label="Routines" icon={Repeat} />
|
|
{showPipelines ? (
|
|
<SidebarNavItem to="/pipelines" label="Pipelines" icon={GitBranch} />
|
|
) : null}
|
|
{showGoalsLink ? (
|
|
<SidebarNavItem to="/goals" label="Goals" icon={Target} />
|
|
) : goalsLinkPending ? (
|
|
<div
|
|
data-testid="sidebar-goals-placeholder"
|
|
className="h-8 pointer-coarse:h-7"
|
|
aria-hidden="true"
|
|
/>
|
|
) : null}
|
|
<SidebarNavItem to="/artifacts" label="Artifacts" icon={Package} />
|
|
<SidebarNavItem to="/skills" label="Skills" icon={Boxes} />
|
|
{showWorkspacesLink ? (
|
|
<SidebarNavItem to="/workspaces" label="Workspaces" icon={GitBranch} />
|
|
) : null}
|
|
{streamlined ? (
|
|
<>
|
|
<SidebarNavItem to="/projects" label="Projects" icon={FolderOpen} />
|
|
<SidebarStarredProjects />
|
|
</>
|
|
) : null}
|
|
<PluginSlotOutlet
|
|
slotTypes={["sidebar"]}
|
|
context={pluginContext}
|
|
className="flex flex-col gap-0.5"
|
|
itemClassName="text-(length:--text-compact) font-medium"
|
|
missingBehavior="placeholder"
|
|
/>
|
|
<PluginLauncherOutlet
|
|
placementZones={["sidebar"]}
|
|
context={pluginContext}
|
|
className="flex flex-col gap-0.5"
|
|
itemClassName="text-(length:--text-compact) font-medium"
|
|
/>
|
|
</SidebarSection>
|
|
|
|
{/* Classic mode restores the per-project collapsible below Work. */}
|
|
{streamlined ? null : <SidebarProjects />}
|
|
|
|
<SidebarAgents streamlined={streamlined} />
|
|
|
|
<SidebarSection label="Company" collapsible={{ open: companyOpen, onOpenChange: setCompanyOpen }}>
|
|
<SidebarNavItem to="/org" label="Org" icon={Network} />
|
|
{showApps ? <SidebarNavItem to="/apps" label="Apps" icon={AppWindow} /> : null}
|
|
<SidebarNavItem to="/timeline" label="Timeline" icon={GanttChartSquare} />
|
|
<SidebarNavItem to="/costs" label="Costs" icon={DollarSign} />
|
|
{/* One entry — /audit merged into the rich Activity feed (PAP-16302). */}
|
|
<SidebarNavItem to="/activity" label="Activity" icon={History} />
|
|
<SidebarNavItem to="/company/settings" label="Settings" icon={Settings} />
|
|
</SidebarSection>
|
|
|
|
<PluginSlotOutlet
|
|
slotTypes={["sidebarPanel"]}
|
|
context={pluginContext}
|
|
className="flex flex-col gap-3"
|
|
itemClassName="rounded-lg border border-border p-3"
|
|
missingBehavior="placeholder"
|
|
/>
|
|
</nav>
|
|
</aside>
|
|
);
|
|
}
|