mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +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>
155 lines
8.6 KiB
TypeScript
155 lines
8.6 KiB
TypeScript
import { attentionReceiptText, type AttentionItem, type AttentionFeedView, type AttentionPersonalView, type DecisionHistoryItem, type DecisionHistoryOutcomeFilter, type DecisionHistoryScope } from "@paperclipai/shared";
|
|
import { queryKeys } from "./queryKeys";
|
|
import { isInlineResolvable } from "./attention";
|
|
|
|
/**
|
|
* The pending feed for one person and one view (PAP-749 plan §1). The key
|
|
* holds the user, so switching accounts never shows the previous person's
|
|
* cached list. The "For you" key is shared by the page, the sidebar, the mobile
|
|
* navigation and the Tasks filter, so the badge always agrees with the list.
|
|
*/
|
|
export const coordinatorAttentionQueryKey = (companyId: string, userId?: string | null, view?: AttentionFeedView) =>
|
|
userId === undefined && view === undefined
|
|
? [...queryKeys.attention(companyId), "coordinator", "pending"] as const
|
|
: [...queryKeys.attention(companyId), userId, view, "coordinator", "pending"] as const;
|
|
|
|
/**
|
|
* The title a Needs You card leads with, so a list of cards (the Withdraw all
|
|
* stale confirmation) names each one the way the card does (PAP-767). An
|
|
* inline interaction or stalled review card renders its own resolver, and its
|
|
* task link names it; every other card has a heading.
|
|
*/
|
|
export function coordinatorCardTitle(item: AttentionItem) {
|
|
const task = item.relatedIssue ?? (item.subject.kind === "issue" ? item.subject : null);
|
|
const inline = isInlineResolvable(item)
|
|
&& (item.sourceKind === "issue_thread_interaction"
|
|
|| (item.sourceKind === "review" && item.subject.kind === "issue" && item.subject.metadata?.reviewAttentionState === "stalled"));
|
|
if (inline && task?.title) return task.title;
|
|
return coordinatorCardAsk(item, task?.title ?? null) ?? item.subject.title ?? item.whyNow;
|
|
}
|
|
|
|
/**
|
|
* Focus (PAP-770): a card's heading says what to do. Some sources are titled
|
|
* with the bare task or agent name ("Today's weather forecast", "Chief of
|
|
* Staff"), which repeats the task link and asks nothing; those get an ask.
|
|
*/
|
|
function coordinatorCardAsk(item: AttentionItem, taskTitle: string | null): string | null {
|
|
const title = item.subject.title?.trim() || null;
|
|
if (item.sourceKind === "blocker_attention" && title) return `Get “${title}” moving again`;
|
|
if (item.sourceKind === "agent_error_alert") {
|
|
const agent = item.detail?.kind === "agent_error" ? item.detail.agentName ?? title : title;
|
|
return agent ? `${agent} hit an error and needs help` : null;
|
|
}
|
|
if (item.sourceKind === "review" && title && title === taskTitle) return `Review “${title}”`;
|
|
// PAP-775 (UI1): approvals and join requests are answered on the card now.
|
|
if (item.sourceKind === "approval" && title && !/^approve\b/i.test(title)) return `Approve “${title}”?`;
|
|
if (item.sourceKind === "join_request" && title) return `Let ${title} join the company?`;
|
|
return null;
|
|
}
|
|
|
|
/** The context under a card's heading: what happened and what you can do about it. */
|
|
export function coordinatorCardDetail(item: AttentionItem, detailLine: string | null): string | null {
|
|
if (item.sourceKind === "blocker_attention" && item.detail?.kind === "blocker" && !item.detail.blockingIssue) {
|
|
const count = item.detail.blockedTaskCount ?? 0;
|
|
const holding = count > 0 ? `It's holding up ${count} ${count === 1 ? "task" : "tasks"}, and no` : "No";
|
|
return `${holding} one is working on it. Unblock it, reassign it, or nudge its owner.`;
|
|
}
|
|
return detailLine ?? item.whyNow;
|
|
}
|
|
export const coordinatorAttentionSummaryQueryKey = (companyId: string, userId: string | null) => [...queryKeys.attention(companyId), userId, "coordinator", "summary"] as const;
|
|
export const coordinatorAttentionTasksQueryKey = (companyId: string, userId: string | null) => [...queryKeys.attention(companyId), userId, "coordinator", "tasks"] as const;
|
|
|
|
/** Presentation-only assumption from the prototype, never a retention policy. */
|
|
export const COORDINATOR_RECENT_DECISION_MS = 24 * 60 * 60 * 1_000;
|
|
export function recentDecisionReceipts(items: DecisionHistoryItem[], now: number) {
|
|
return items.filter((item) => Date.parse(item.resolvedAt) + COORDINATOR_RECENT_DECISION_MS > now);
|
|
}
|
|
|
|
/** One canonical pending feed, projected as distinct tasks on the Tasks surface. */
|
|
export function pendingDecisionTaskIds(items: AttentionItem[]) {
|
|
return new Set(items.flatMap((item) => item.relatedIssue ? [item.relatedIssue.id] : item.subject.kind === "issue" ? [item.subject.id] : []));
|
|
}
|
|
|
|
/**
|
|
* The Decision history outcome filter (PAP-749 plan §3). Withdrawn, Expired and
|
|
* Closed with task are separate: a card that closed with its task is not in
|
|
* Expired. "Handled for me" is a different filter (who the card was for), so
|
|
* it is not an outcome here.
|
|
*/
|
|
export const DECISION_HISTORY_OUTCOME_OPTIONS: ReadonlyArray<{ value: DecisionHistoryOutcomeFilter; label: string }> = [
|
|
{ value: "accepted", label: "Approved" },
|
|
{ value: "answered", label: "Answered" },
|
|
{ value: "rejected", label: "Changes requested" },
|
|
{ value: "decided", label: "Decided" },
|
|
{ value: "withdrawn", label: "Withdrawn" },
|
|
{ value: "expired", label: "Expired" },
|
|
{ value: "issue_closed", label: "Closed with task" },
|
|
{ value: "cancelled", label: "Cancelled" },
|
|
];
|
|
|
|
/**
|
|
* Whose decisions Decision history and Recent Decisions list (PAP-768). Your
|
|
* own is the default: what you answered, withdrew or transferred, what a
|
|
* different person handled for you, and the cards that were for you.
|
|
*/
|
|
export const DECISION_HISTORY_SCOPE_OPTIONS: ReadonlyArray<{ value: DecisionHistoryScope; label: string }> = [
|
|
{ value: "mine", label: "Handled by me or for me" },
|
|
{ value: "all", label: "Everyone" },
|
|
];
|
|
export const DEFAULT_DECISION_HISTORY_SCOPE: DecisionHistoryScope = "mine";
|
|
|
|
/**
|
|
* A history entry's headline. When a person acted, it names them with the
|
|
* receipt's verb for the same action ("Approved by @scott", "Kept paused by
|
|
* @dotta"; PAP-749 plan §3, PAP-767). A decision adds the option chosen and an
|
|
* item review its verdict counts. Everything else keeps the server's label.
|
|
*/
|
|
export function decisionHistoryHeadline(item: DecisionHistoryItem, userLabelMap?: ReadonlyMap<string, string> | null) {
|
|
const actorLabel = item.resolvedByUserId ? userLabelMap?.get(item.resolvedByUserId) ?? "someone" : null;
|
|
if (item.action && actorLabel) {
|
|
const line = attentionReceiptText({ outcome: item.action.outcome, actorLabel });
|
|
return item.action.detail ? `${line}: ${item.action.detail}` : line;
|
|
}
|
|
if (item.resultOutcome === "withdrawn" && actorLabel) return `Withdrawn by @${actorLabel}`;
|
|
return item.label;
|
|
}
|
|
|
|
/** The task line of a history entry; an approval with no task names itself instead. */
|
|
export function decisionHistoryContext(item: DecisionHistoryItem) {
|
|
if (!item.issueId) return item.sourceKind === "approval" ? `Approval · ${item.title}` : item.title;
|
|
return [item.issueIdentifier, item.issueTitle].filter(Boolean).join(" · ");
|
|
}
|
|
|
|
/**
|
|
* The toolbar's assignee filter (PAP-775): "Assigned to you" by default, every
|
|
* card the viewer may see ("all", a board member's Everyone), one person, the
|
|
* cards with no owner yet, or company alerts. Each value is one personal view
|
|
* of the feed, plus a person for "user:<id>"; the server routes every card and
|
|
* re-checks every action, so this only picks which cards to list.
|
|
*/
|
|
export type CoordinatorAssignee = "me" | "all" | "unassigned" | "company" | `user:${string}`;
|
|
|
|
/** The URL parameter that names the person in a `user:<id>` filter. */
|
|
export const COORDINATOR_ASSIGNEE_PARAM = "for";
|
|
|
|
export function coordinatorAudienceKey(item: Pick<AttentionItem, "audience">): Exclude<CoordinatorAssignee, "me" | "all"> {
|
|
const audience = item.audience;
|
|
if (audience?.kind === "user" && audience.userId) return `user:${audience.userId}`;
|
|
if (audience?.kind === "pool") return "unassigned";
|
|
return "company";
|
|
}
|
|
|
|
/** The filter a URL shows: its view, narrowed to one person in Everyone. */
|
|
export function coordinatorAssignee(view: AttentionPersonalView, forUserId: string | null | undefined): CoordinatorAssignee | null {
|
|
if (view === "archived") return null;
|
|
if (view === "all") return forUserId ? `user:${forUserId}` : "all";
|
|
return view === "mine" ? "me" : view;
|
|
}
|
|
|
|
/** The view (and person) to load for a filter value; your own name is "Assigned to you". */
|
|
export function coordinatorAssigneeTarget(assignee: CoordinatorAssignee, currentUserId: string | null | undefined): { view: AttentionPersonalView; forUserId: string | null } {
|
|
if (assignee === "me" || assignee === `user:${currentUserId}`) return { view: "mine", forUserId: null };
|
|
if (assignee.startsWith("user:")) return { view: "all", forUserId: assignee.slice(5) };
|
|
return { view: assignee as "all" | "unassigned" | "company", forUserId: null };
|
|
}
|