mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
## Thinking Path > - Paperclip helps people manage work that agents do. > - The inbox tells a person which tasks need a decision. > - A provider usage limit can stop several attempts on one task or affect several tasks. > - Separate failure cards made it hard to tell which tasks still needed attention. > - This change groups failures using the account, reset time, or retry links that Paperclip can verify. > - A person can now see which task to retry, which tasks are waiting, and which ones recovered. ## Linked Issues or Issue Description **What existing behavior does this improve?** It improves the Coordinator inbox when a provider limits usage. **Current behavior** Repeated run failures can fill the inbox. Resolved failures can still appear beside open decisions. **Proposed behavior** Show personal actions in Needs you, automatic retries and snoozes in Waiting, and past events in History. Keep an archived retry chain hidden during automatic attempts. Return it to Needs you when a person must act. **Additional context** Related work includes #18020 on completed tasks, #9704 on archive behavior, and #21570 on usage limits in chat. ## What Changed - Group verified account and reset windows. When that evidence is missing, count linked attempts per task and show the tasks in a collapsible group. - Separate the reported reset time from each task’s retry schedule. Keep unresolved ownership recoveries visible after task closure. Use persisted native retry requests to preserve the original archive and increment the attempt count. - Keep personal archive in the card menu. Put decision receipts and run logs in History. - Align inbox filters, tabs, and history. Share empty-state artwork and placement across Inbox, Goals, Routines, and Secrets. - Index run-history pages and resumed-work lookups, and rate-limit history requests per company and viewer. Add synthetic fixtures for both grouping paths and a manual walkthrough. ## Verification - The author and a human tester completed the synthetic retry-chain walkthrough. Chromium also verified archive, repeat failure, exhaustion, and recovery. - The 64 focused server tests and the UI and server typechecks passed before rebasing. See `doc/testing/coordinator-inbox-test-drive.md` to repeat the manual checks. - The shared SDK input check and all 64 focused server tests passed after rebasing. The OpenAPI suite (59 tests), API catalog suite (2,309 tests), and both demo seed paths passed locally after the CI fixes. - The affected inbox and native-runtime suites passed locally after merging the upstream conformance test fix in #22854. The browser access-denial scenarios passed three runs each for 403 and 404. - The migration checks and 79 focused tests passed, including an index-plan regression with 5,000 unrelated runs. The migration and query plan were reverified after renumbering. [Full CI on `cf52b80161`](https://github.com/paperclipai/paperclip/actions/runs/45529834793) passed after rerunning a timed-out server shard. ## Risks The attention feed reads retry ancestry. Long chains can increase query cost. Task and company checks bound the traversal, and cycle detection stops repeated visits. Providers that omit the reset time leave the card with an unknown reset. Migration 0508 adds two indexes concurrently. Each run-history page returns at most 100 records. ## Model Used OpenAI Codex, GPT-6 family, with repository editing, local test execution, and browser verification. ## 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 - [x] 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: Scott Tong <scott@scotts-mbp-m5-max.local> Co-authored-by: Paperclip <noreply@paperclip.ing>
198 lines
7.2 KiB
TypeScript
198 lines
7.2 KiB
TypeScript
import { useState } from "react";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import type { CompanySecret } from "@paperclipai/shared";
|
|
import { Check, KeyRound, MoreHorizontal } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { QueryErrorState, useQueryView } from "@/components/QueryView";
|
|
import { EmptyState } from "../../components/EmptyState";
|
|
import { secretsApi, type MyUserSecretEntry } from "../../api/secrets";
|
|
import { queryKeys } from "../../lib/queryKeys";
|
|
import { relativeTime } from "../../lib/utils";
|
|
import { useToastActions } from "../../context/ToastContext";
|
|
import { SetMyUserSecretDialog } from "./SetMyUserSecretDialog";
|
|
import { SecretPathName } from "./SecretPathName";
|
|
import { myValueState } from "./my-value-state";
|
|
import { describeError } from "@/api/errors";
|
|
|
|
/**
|
|
* Secrets → My secrets tab. Lists every secret the organization asks each
|
|
* member to provide, with whether the signed-in person has added their value,
|
|
* and lets them add, replace or remove it.
|
|
*/
|
|
export function MyUserSecretsTab({ companyId }: { companyId: string }) {
|
|
const queryClient = useQueryClient();
|
|
const { pushToast } = useToastActions();
|
|
const [dialogFor, setDialogFor] = useState<MyUserSecretEntry | null>(null);
|
|
|
|
const mySecretsQuery = useQuery({
|
|
queryKey: queryKeys.secrets.myUserSecrets(companyId),
|
|
queryFn: () => secretsApi.listMyUserSecrets(companyId),
|
|
});
|
|
const mySecretsView = useQueryView(mySecretsQuery);
|
|
const entries = mySecretsQuery.data ?? [];
|
|
|
|
const clear = useMutation({
|
|
mutationFn: (secret: CompanySecret) => secretsApi.removeMyUserSecret(companyId, secret.id),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.secrets.myUserSecrets(companyId) });
|
|
pushToast({ title: "Your value was removed", tone: "info" });
|
|
},
|
|
onError: (err) =>
|
|
pushToast({
|
|
title: "Couldn't remove your value",
|
|
body: describeError(err).body,
|
|
tone: "error",
|
|
}),
|
|
});
|
|
|
|
const needsValue = (entry: MyUserSecretEntry) =>
|
|
entry.definition.status === "active" && !entry.secret;
|
|
const missingCount = entries.filter(needsValue).length;
|
|
// Secrets still waiting on this person come first; the rest keep the server's order.
|
|
const sortedEntries = [...entries].sort(
|
|
(a, b) => Number(needsValue(b)) - Number(needsValue(a)),
|
|
);
|
|
|
|
return (
|
|
<section aria-label="My secrets" className="flex flex-1 flex-col gap-4">
|
|
<p className="max-w-xl text-sm text-muted-foreground">
|
|
Values only you provide. Agents use them when they work for you.
|
|
{missingCount > 0 ? (
|
|
<span className="text-foreground">
|
|
{" "}
|
|
{missingCount} still {missingCount === 1 ? "needs" : "need"} your value.
|
|
</span>
|
|
) : null}
|
|
</p>
|
|
|
|
{mySecretsView.kind === "error" ? (
|
|
<QueryErrorState
|
|
error={mySecretsQuery.error}
|
|
action="load your secrets"
|
|
onRetry={mySecretsView.retry}
|
|
retrying={mySecretsView.isFetching}
|
|
/>
|
|
) : entries.length === 0 && !mySecretsQuery.isPending && mySecretsView.kind !== "reconnecting" ? (
|
|
<EmptyState placement="upper"
|
|
icon={KeyRound}
|
|
message="Nothing is asked of you yet. An admin decides which secrets each member provides."
|
|
/>
|
|
) : (
|
|
<ul className="divide-y divide-border border-y border-border">
|
|
{sortedEntries.map((entry) => (
|
|
<MyUserSecretRow
|
|
key={entry.definition.id}
|
|
entry={entry}
|
|
onSet={() => setDialogFor(entry)}
|
|
onClear={() => entry.secret && clear.mutate(entry.secret)}
|
|
clearing={clear.isPending}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
|
|
<SetMyUserSecretDialog
|
|
companyId={companyId}
|
|
definition={dialogFor?.definition ?? null}
|
|
existingSecret={dialogFor?.secret ?? null}
|
|
open={dialogFor !== null}
|
|
onOpenChange={(open) => {
|
|
if (!open) setDialogFor(null);
|
|
}}
|
|
/>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function MyUserSecretRow({
|
|
entry,
|
|
onSet,
|
|
onClear,
|
|
clearing,
|
|
}: {
|
|
entry: MyUserSecretEntry;
|
|
onSet: () => void;
|
|
onClear: () => void;
|
|
clearing: boolean;
|
|
}) {
|
|
const { definition, secret } = entry;
|
|
const state = myValueState(definition, secret);
|
|
const disabledDefinition = definition.status !== "active";
|
|
const replaced = secret ? secret.latestVersion > 1 && secret.lastRotatedAt : null;
|
|
|
|
return (
|
|
<li
|
|
className="flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-3"
|
|
data-testid={`my-secret-${definition.id}`}
|
|
data-needs-value={!secret && !disabledDefinition ? "true" : undefined}
|
|
>
|
|
<div className="flex min-w-0 flex-1 basis-64 flex-col gap-0.5">
|
|
<span className="flex min-w-0 flex-wrap items-baseline gap-x-2">
|
|
<SecretPathName name={definition.name} className="text-sm" />
|
|
{/* Agents point people at a secret by this key, so it stays visible. */}
|
|
<code className="font-mono text-xs text-muted-foreground">{definition.key}</code>
|
|
</span>
|
|
{definition.description ? (
|
|
<span className="text-xs text-muted-foreground">{definition.description}</span>
|
|
) : null}
|
|
{definition.usageGuidance ? (
|
|
<span className="text-xs text-muted-foreground">{definition.usageGuidance}</span>
|
|
) : null}
|
|
{disabledDefinition ? (
|
|
<span className="text-xs text-muted-foreground">
|
|
Turned off by an admin. Agents won't ask for it.
|
|
</span>
|
|
) : state === "inactive" ? (
|
|
<span className="text-xs text-muted-foreground">
|
|
Your value is turned off. Replace it to use it again.
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
|
|
{secret ? (
|
|
<span className="flex items-center gap-1">
|
|
<span className="mr-2 flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
<Check className="size-3.5" aria-hidden />
|
|
{replaced
|
|
? `Replaced ${relativeTime(replaced)}`
|
|
: `Added ${relativeTime(secret.createdAt)}`}
|
|
</span>
|
|
{!disabledDefinition ? (
|
|
<Button variant="ghost" size="sm" onClick={onSet}>
|
|
Replace
|
|
</Button>
|
|
) : null}
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="text-muted-foreground"
|
|
aria-label={`More actions for ${definition.name}`}
|
|
disabled={clearing}
|
|
>
|
|
<MoreHorizontal aria-hidden />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem variant="destructive" disabled={clearing} onSelect={onClear}>
|
|
Remove your value
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</span>
|
|
) : !disabledDefinition ? (
|
|
<Button size="sm" onClick={onSet}>
|
|
Set value
|
|
</Button>
|
|
) : null}
|
|
</li>
|
|
);
|
|
}
|