mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-15 18:56:05 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The board UI reads the company project list in many places: the
sidebar, starred projects, the command palette, the new-task dialog, and
archive-aware pages such as the Mine inbox
> - Active-only consumers read `GET /projects`, and archive-aware ones
read `GET /projects?includeArchived=true`, under two React Query keys
> - A Mine load therefore fetched the same large payload twice (580–590
KB each on our dev instance)
> - The two responses differ only by archived rows; the server's active
list is exactly the rows where `archivedAt` is null
> - This pull request makes every consumer share the
`includeArchived=true` query, and active-only consumers filter it with
`select`
> - The benefit is one project read per page instead of two
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Duplicate project list reads on page load.
**Subsystem affected**
Board UI project queries (`ui/src/lib/company-projects-query.ts` and its
consumers).
**Current behavior**
A cold Mine load sends both `/companies/:id/projects` (sidebar) and
`/companies/:id/projects?includeArchived=true` (inbox).
**Proposed behavior**
One `includeArchived=true` read serves both. Active-only consumers apply
`selectActiveProjects`.
**Reason and benefit**
The project list is one of the largest shell payloads. Reading it once
saves a large response on every page that has both kinds of consumer.
## What Changed
- New `companyProjectsQuery(companyId, { includeArchived? })` in
`ui/src/lib/company-projects-query.ts`. It always uses the
`includeArchived: true` key and fetch. For active-only use it adds a
stable, module-level `select` that keeps rows without `archivedAt`.
- 22 files that read the active list now spread
`companyProjectsQuery(...)`, and so do the plugin SDK project picker and
16 archive-aware pages that wrote the shared key and fetcher inline.
Their `enabled` and other options are unchanged. `OnboardingWizard`'s
one imperative read is unchanged. `pages/Inbox.tsx` already reads the
same key and fetcher, so it shares the entry without an edit.
- Invalidation: project mutations and live events invalidate
`queryKeys.projects.all(companyId)`, which matches the shared key. The
onboarding wizard invalidated the old active-only key; it now
invalidates `projects.all`.
- Tests: new `company-projects-query.test.tsx` (one request for both
consumers, correct filtering, and one refetch after `projects.all`
invalidation). Three existing tests (`CommandPalette`, `CompanyExport`,
`GitHubBotManagement`) now seed or expect the shared key.
- New browser check
`tests/perf/collections/shared-project-list.spec.ts`: after the Mine
inbox read completes, the page has sent no active-only project request.
## Verification
- `pnpm verify` passes.
- `ui`: the consumer suites (`CoordinatorSidebar`, `SidebarProjects`,
`SidebarStarredProjects`, `CommandPalette`, `NewIssueDialog`,
`AgentWorkPanels`, `CoordinatorNeedsYou`, `IssueDetail`,
`ProjectDetail`, `Projects`, `CompanyExport`, `ChatExecutionDefaults`,
`GatewaysList`, `Search`, `IssueProperties`, `persisted-query-cache`)
pass.
- Browser check:
`PAPERCLIP_COLLECTION_PERF_BASE_URL=http://127.0.0.1:<port> pnpm exec
playwright test --config tests/perf/collections/playwright.config.ts
shared-project-list.spec.ts`. It passes on this branch and fails on
`master`.
## Risks
- A page that needs only active projects now downloads archived rows
too. For most companies that is a small difference; the duplicate read
it removes is a full copy.
- The server does not order either list, and consumers sort for display,
so filtering on the client keeps behavior.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edits, browser). 1M-token context window. Extended
thinking was off.
## 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
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
7.1 KiB
TypeScript
112 lines
7.1 KiB
TypeScript
import { useEffect, useId, useState } from "react";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import type { ChatExecutionDefaults as Defaults, TaskWorkspaceSelection } from "@paperclipai/shared";
|
||
import { executionWorkspacesApi } from "@/api/execution-workspaces";
|
||
import { Button } from "@/components/ui/button";
|
||
import { NativeSelect } from "@/components/ui/select";
|
||
import { companyProjectsQuery } from "@/lib/company-projects-query";
|
||
|
||
function selectionKey(value: TaskWorkspaceSelection | null | undefined): string {
|
||
if (value === undefined) return "inherit";
|
||
if (value === null) return "clear";
|
||
if (value.kind === "task_directory") return "task";
|
||
if (value.kind === "existing") return `existing:${value.workspaceId}`;
|
||
return `source:${value.projectWorkspaceId}:${value.mode}`;
|
||
}
|
||
|
||
export function ChatExecutionDefaults({ companyId, value, resource = false, onSave }: {
|
||
companyId: string;
|
||
value: Defaults | null | undefined;
|
||
resource?: boolean;
|
||
onSave: (defaults: Defaults | null) => Promise<void>;
|
||
}) {
|
||
const id = useId();
|
||
const [draft, setDraft] = useState<Defaults | null>(null);
|
||
const [pending, setPending] = useState(false);
|
||
const [error, setError] = useState<string | null>(null);
|
||
const [savedFrom, setSavedFrom] = useState<string | null>(null);
|
||
const projects = useQuery({ ...companyProjectsQuery(companyId) });
|
||
const workspaces = useQuery({
|
||
queryKey: ["channel-workspace-choices", companyId],
|
||
queryFn: () => executionWorkspacesApi.listSummaries(companyId, { selectableForTask: true }),
|
||
});
|
||
const current = draft ?? value ?? {};
|
||
const valueKey = JSON.stringify(value ?? {});
|
||
const saved = savedFrom !== null;
|
||
// Keep the accepted selections until the parent publishes refreshed defaults.
|
||
useEffect(() => {
|
||
if (savedFrom !== null && savedFrom !== valueKey) setDraft(null);
|
||
}, [savedFrom, valueKey]);
|
||
const projectValue = current.projectId === undefined ? "inherit" : current.projectId ?? "none";
|
||
const workspaceValue = selectionKey(current.workspace);
|
||
const choices = new Map<string, TaskWorkspaceSelection>();
|
||
choices.set("task", { kind: "task_directory" });
|
||
for (const project of projects.data ?? []) {
|
||
for (const source of project.workspaces ?? []) {
|
||
for (const mode of ["managed_isolated", "shared"] as const) {
|
||
choices.set(`source:${source.id}:${mode}`, { kind: "configured_source", projectWorkspaceId: source.id, mode });
|
||
}
|
||
}
|
||
}
|
||
for (const workspace of workspaces.data ?? []) {
|
||
choices.set(`existing:${workspace.id}`, { kind: "existing", workspaceId: workspace.id });
|
||
}
|
||
const dirty = !saved && JSON.stringify(current) !== valueKey;
|
||
const change = (next: Defaults) => { setDraft(next); setSavedFrom(null); setError(null); };
|
||
return <form className="space-y-3" aria-labelledby={`${id}-title`} onSubmit={async (event) => {
|
||
event.preventDefault();
|
||
if (pending || !dirty) return;
|
||
setPending(true); setError(null); setSavedFrom(null);
|
||
try { await onSave(Object.keys(current).length ? current : null); setSavedFrom(valueKey); }
|
||
catch (cause) { setError(cause instanceof Error ? cause.message : "Couldn’t save task defaults. Try again."); }
|
||
finally { setPending(false); }
|
||
}}>
|
||
<div className="space-y-1">
|
||
<h3 id={`${id}-title`} className="text-sm font-semibold">Task defaults</h3>
|
||
<p className="text-sm text-muted-foreground">Applies to new conversations. Existing tasks keep their files and project.</p>
|
||
</div>
|
||
{(projects.isError || workspaces.isError) && <p role="alert" className="text-sm text-destructive">Couldn’t load available projects or workspaces. <button type="button" className="underline" onClick={() => { void projects.refetch(); void workspaces.refetch(); }}>Try again</button></p>}
|
||
<div className="space-y-2">
|
||
<label htmlFor={`${id}-project`} className="text-sm font-medium">Project</label>
|
||
<NativeSelect id={`${id}-project`} value={projectValue} disabled={pending || projects.isPending} onChange={(event) => {
|
||
const { projectId: _previous, ...rest } = current;
|
||
change(event.target.value === "inherit" ? rest : { ...rest, projectId: event.target.value === "none" ? null : event.target.value });
|
||
}}>
|
||
<option value="inherit">{resource ? "Use connection defaults" : "Use task defaults"}</option>
|
||
<option value="none">No project</option>
|
||
{current.projectId && !projects.data?.some((project) => project.id === current.projectId) && <option value={current.projectId}>Saved project (unavailable)</option>}
|
||
{(projects.data ?? []).map((project) => <option key={project.id} value={project.id}>{project.name}</option>)}
|
||
</NativeSelect>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<label htmlFor={`${id}-workspace`} className="text-sm font-medium">Workspace</label>
|
||
<NativeSelect id={`${id}-workspace`} value={workspaceValue} disabled={pending || projects.isPending || workspaces.isPending} onChange={(event) => {
|
||
const key = event.target.value;
|
||
const { workspace: _previous, ...rest } = current;
|
||
if (key === "inherit") change(rest);
|
||
else if (key === "clear") change({ ...rest, workspace: null });
|
||
else { const workspace = choices.get(key); if (workspace) change({ ...rest, workspace }); }
|
||
}}>
|
||
<option value="inherit">{resource ? "Use connection defaults" : "Use project or task defaults"}</option>
|
||
{resource && <option value="clear">Use project or task defaults</option>}
|
||
{!resource && workspaceValue === "clear" && <option value="clear">Use project or task defaults</option>}
|
||
<option value="task">Task files — separate folder</option>
|
||
{current.workspace && !choices.has(workspaceValue) && <option value={workspaceValue}>Saved workspace (unavailable)</option>}
|
||
{(projects.data ?? []).filter((project) => project.workspaces?.length).map((project) => <optgroup key={project.id} label={project.name}>
|
||
{project.workspaces.flatMap((source) => [
|
||
<option key={`${source.id}:isolated`} value={`source:${source.id}:managed_isolated`}>{source.name} — isolated checkout</option>,
|
||
<option key={`${source.id}:shared`} value={`source:${source.id}:shared`}>{source.name} — shared folder</option>,
|
||
])}
|
||
</optgroup>)}
|
||
{(workspaces.data?.length ?? 0) > 0 && <optgroup label="Existing workspaces">{workspaces.data!.map((workspace) => <option key={workspace.id} value={`existing:${workspace.id}`}>{workspace.name}</option>)}</optgroup>}
|
||
</NativeSelect>
|
||
<p className="text-xs text-muted-foreground">Project and workspace access is checked for each task. A shared folder must also be allowed by the agent’s execution policy.</p>
|
||
</div>
|
||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>{dirty ? <Button type="button" variant="ghost" disabled={pending} onClick={() => { setDraft(null); setError(null); }}>Cancel</Button> : saved ? <span role="status" className="text-sm text-muted-foreground">Saved for new tasks.</span> : null}</div>
|
||
<Button type="submit" disabled={!dirty || pending}>{pending ? "Saving…" : "Save defaults"}</Button>
|
||
</div>
|
||
</form>;
|
||
}
|