The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
feat(ui): badge the review policy when it constrains approval (#10938)
Dotta8ee1fb21a653
diff --git a/server/src/__tests__/attention-service.test.ts b/server/src/__tests__/attention-service.test.tsindex b2cd6bc649..88847833ff 100644--- a/server/src/__tests__/attention-service.test.ts+++ b/server/src/__tests__/attention-service.test.ts@@ -172,6 +172,7 @@ describeEmbeddedPostgres("attention service", () => {unblockDescriptor?: { owner: { userId: string } | "board"; action: string } | null;blockedTransitionAt?: Date | null;harnessKind?: string | null;+ reviewPolicy?: "anyone" | "not_creator" | "human_only" | null;}) {const id = input.id ?? randomUUID();await db.insert(issues).values({@@ -181,6 +182,7 @@ describeEmbeddedPostgres("attention service", () => {title: input.title,status: input.status,priority: input.priority ?? "medium",+ reviewPolicy: input.reviewPolicy ?? null,parentId: input.parentId ?? null,projectId: input.projectId ?? null,projectWorkspaceId: input.projectWorkspaceId ?? null,@@ -314,6 +316,9 @@ describeEmbeddedPostgres("attention service", () => {title: "Stalled review blocker",status: "in_review",assigneeAgentId: reviewerId,+ // PAP-16506: the /decisions review card states who may give the verdict,+ // so the subject has to carry the issue's opt-in constraint.+ reviewPolicy: "human_only",updatedAt: new Date("2026-07-09T12:05:00.000Z"),});await db.insert(issueRelations).values({@@ -673,7 +678,10 @@ describeEmbeddedPostgres("attention service", () => {// A stalled review resolves in-row on the /decisions card (PAP-16080 §4.4).inlineResolvable: true,subject: expect.objectContaining({- metadata: expect.objectContaining({ reviewAttentionState: "stalled" }),+ metadata: expect.objectContaining({+ reviewAttentionState: "stalled",+ reviewPolicy: "human_only",+ }),}),decisionVerbs: expect.arrayContaining([expect.objectContaining({ id: "choose_review_path", label: "Choose review path" }),diff --git a/server/src/services/attention.ts b/server/src/services/attention.tsindex 0b4b72688e..123b73411b 100644--- a/server/src/services/attention.ts+++ b/server/src/services/attention.ts@@ -43,6 +43,7 @@ import type {AttentionSubject,AttentionTriageAttribution,AttentionWorkspaceRef,+ IssueReviewPolicy,} from "@paperclipai/shared";import { badRequest } from "../errors.js";import { PRODUCTIVITY_REVIEW_ORIGIN_KIND } from "./productivity-review.js";@@ -123,6 +124,8 @@ type IssueSummaryRow = {title: string;status: string;priority: string;+ /** Who may give the `in_review` verdict; `null`/absent ≡ "anyone" (PAP-16506). */+ reviewPolicy?: IssueReviewPolicy | null;assigneeAgentId: string | null;assigneeUserId: string | null;createdAt: Date;@@ -341,6 +344,9 @@ function issueSubject(prefix: string, issue: IssueSubjectRow): AttentionSubjectpriority: issue.priority,assigneeAgentId: issue.assigneeAgentId,assigneeUserId: issue.assigneeUserId,+ // Only present when the row was selected with the column, so subjects+ // built from narrower selects do not claim a policy they never read.+ ...(issue.reviewPolicy !== undefined ? { reviewPolicy: issue.reviewPolicy } : {}),},};}@@ -776,6 +782,7 @@ async function issueSummaryMap(db: Db, companyId: string, issueIds: Array<stringtitle: issues.title,status: issues.status,priority: issues.priority,+ reviewPolicy: issues.reviewPolicy,assigneeAgentId: issues.assigneeAgentId,assigneeUserId: issues.assigneeUserId,createdAt: issues.createdAt,@@ -801,6 +808,7 @@ async function issueSummaryMap(db: Db, companyId: string, issueIds: Array<stringtitle: row.title,status: row.status,priority: row.priority,+ reviewPolicy: row.reviewPolicy ?? null,assigneeAgentId: row.assigneeAgentId,assigneeUserId: row.assigneeUserId,createdAt: row.createdAt,diff --git a/ui/src/components/AttentionQueueRow.test.tsx b/ui/src/components/AttentionQueueRow.test.tsxindex f6ba608fc3..0cd2b2a6c1 100644--- a/ui/src/components/AttentionQueueRow.test.tsx+++ b/ui/src/components/AttentionQueueRow.test.tsx@@ -180,6 +180,90 @@ describe("AttentionQueueRow", () => {expect(el.textContent).toContain("Send back to work");});+ // PAP-16506 P4: an opt-in policy warns before the card offers Approve, because+ // the server refuses the verdict. The default earns no pixels.+ const reviewItemWithPolicy = (reviewPolicy?: unknown) =>+ buildItem({+ sourceKind: "review" as AttentionSourceKind,+ inlineResolvable: true,+ subject: {+ kind: "issue",+ id: "issue-1",+ companyId: "c1",+ title: "PR ready for review",+ identifier: null,+ status: "in_review",+ href: "/PAP/issues/PAP-1",+ metadata: {+ reviewAttentionState: "stalled",+ ...(reviewPolicy === undefined ? {} : { reviewPolicy }),+ },+ },+ });++ it("says nothing about who can approve on a review with no policy set", () => {+ const el = render(+ <AttentionQueueRow+ item={reviewItemWithPolicy()}+ companyId="c1"+ expanded+ onToggleExpand={noop}+ onDismiss={noop}+ />,+ );+ expect(el.querySelector('[data-testid="review-policy-badge"]')).toBeNull();+ expect(el.textContent).not.toContain("Anyone else");+ expect(el.textContent).not.toContain("Human only");+ // The verbs still render — suppressing the badge must not suppress the card.+ expect(el.textContent).toContain("Send back to work");+ });++ it("badges the opt-in constraint when the issue carries one", () => {+ const el = render(+ <AttentionQueueRow+ item={reviewItemWithPolicy("human_only")}+ companyId="c1"+ expanded+ onToggleExpand={noop}+ onDismiss={noop}+ />,+ );+ const badge = el.querySelector('[data-testid="review-policy-badge"]');+ expect(badge?.getAttribute("data-review-policy")).toBe("human_only");+ expect(badge?.textContent).toContain("Human only");+ expect(badge?.getAttribute("title")).toContain("Agents cannot");+ });++ it("badges a not_creator policy as 'Anyone else'", () => {+ const el = render(+ <AttentionQueueRow+ item={reviewItemWithPolicy("not_creator")}+ companyId="c1"+ expanded+ onToggleExpand={noop}+ onDismiss={noop}+ />,+ );+ const badge = el.querySelector('[data-testid="review-policy-badge"]');+ expect(badge?.getAttribute("data-review-policy")).toBe("not_creator");+ expect(badge?.textContent).toContain("Anyone else");+ });++ it("shows no badge for an explicit default or an unrecognised policy", () => {+ for (const policy of ["anyone", "board_only"]) {+ const el = render(+ <AttentionQueueRow+ item={reviewItemWithPolicy(policy)}+ companyId="c1"+ expanded+ onToggleExpand={noop}+ onDismiss={noop}+ />,+ );+ expect(el.querySelector('[data-testid="review-policy-badge"]')).toBeNull();+ }+ });+it("deep-links a covered review instead of inlining", () => {const el = render(<AttentionQueueRowdiff --git a/ui/src/components/AttentionQueueRow.tsx b/ui/src/components/AttentionQueueRow.tsxindex f8943521f6..555b8e9352 100644--- a/ui/src/components/AttentionQueueRow.tsx+++ b/ui/src/components/AttentionQueueRow.tsx@@ -47,6 +47,7 @@ import {import { AttentionInteractionResolver } from "./AttentionInteractionResolver";import { DecisionResolver } from "./DecisionResolver";import { StalledReviewActions } from "./StalledReviewActions";+import { readIssueReviewPolicyMetadata } from "../lib/review-policy";const HOUR_MS = 60 * 60 * 1000;const DAY_MS = 24 * HOUR_MS;@@ -787,6 +788,7 @@ function InlineResolver({issueId={item.subject.id}companyId={companyId}footerSlot={toggle}+ reviewPolicy={readIssueReviewPolicyMetadata(item.subject.metadata)}/>);}diff --git a/ui/src/components/IssueProperties.test.tsx b/ui/src/components/IssueProperties.test.tsxindex 0427bfb6bc..ee3a1a6900 100644--- a/ui/src/components/IssueProperties.test.tsx+++ b/ui/src/components/IssueProperties.test.tsx@@ -2900,6 +2900,74 @@ describe("IssueProperties", () => {Array.from(container.querySelectorAll("button")).some((button) => button.textContent?.includes("Unarchive")),).toBe(false);+ act(() => root.unmount());+ });+ // PAP-16506 P4: only an agent sets `reviewPolicy`, so the panel shows it and+ // never offers a control. The default — a NULL column, meaning anyone with+ // write access can approve — is what every issue already does, so it shows+ // nothing at all rather than a row reading "Anyone" or "None".+ const findApprovalsRow = () =>+ container.querySelector('[data-property-label="Approvals"]')?.closest('[data-property-row="true"]') ?? null;++ it("shows no approvals row on an issue that has never set a policy", async () => {+ const root = renderProperties(container, {+ issue: createIssue({ reviewPolicy: null }),+ childIssues: [],+ onUpdate: vi.fn(),+ inline: true,+ });+ await flush();++ expect(findApprovalsRow()).toBeNull();+ expect(container.textContent).not.toContain("Review policy");++ act(() => root.unmount());+ });++ it("shows no approvals row when the policy is the explicit default", async () => {+ const root = renderProperties(container, {+ issue: createIssue({ reviewPolicy: "anyone" }),+ childIssues: [],+ onUpdate: vi.fn(),+ inline: true,+ });+ await flush();++ expect(findApprovalsRow()).toBeNull();++ act(() => root.unmount());+ });++ it("badges an opt-in constraint read-only, with no control to change it", async () => {+ const onUpdate = vi.fn();+ const root = renderProperties(container, {+ issue: createIssue({ reviewPolicy: "human_only" }),+ childIssues: [],+ onUpdate,+ inline: true,+ });+ await flush();++ const row = findApprovalsRow();+ expect(row?.textContent).toContain("Human only");+ // Read-only: the row is a chip, not a picker — nothing here can PATCH.+ expect(row?.querySelector("button")).toBeNull();+ expect(onUpdate).not.toHaveBeenCalled();++ act(() => root.unmount());+ });++ it("badges a not_creator policy as 'Anyone else'", async () => {+ const root = renderProperties(container, {+ issue: createIssue({ reviewPolicy: "not_creator" }),+ childIssues: [],+ onUpdate: vi.fn(),+ inline: true,+ });+ await flush();++ expect(findApprovalsRow()?.textContent).toContain("Anyone else");+act(() => root.unmount());});});diff --git a/ui/src/components/StalledReviewActions.tsx b/ui/src/components/StalledReviewActions.tsxindex ab3aadc562..d2b801c627 100644--- a/ui/src/components/StalledReviewActions.tsx+++ b/ui/src/components/StalledReviewActions.tsx@@ -1,11 +1,13 @@import { useState, type ReactNode } from "react";import { useMutation, useQueryClient } from "@tanstack/react-query";import { CheckCircle2, Loader2, RotateCcw, Undo2 } from "lucide-react";-import type { StalledReviewDecisionAction } from "@paperclipai/shared";+import type { IssueReviewPolicy, StalledReviewDecisionAction } from "@paperclipai/shared";import { issuesApi } from "../api/issues";import { useToastActions } from "../context/ToastContext";import { queryKeys } from "../lib/queryKeys";+import { issueReviewPolicyBadge } from "../lib/review-policy";import { cn } from "../lib/utils";+import { Badge } from "./ui/badge";import { Button } from "./ui/button";import { Textarea } from "./ui/textarea";@@ -16,6 +18,12 @@ interface StalledReviewActionsProps {footerSlot?: ReactNode;/** Fired after a decision lands so the surface can navigate / close / refetch extras. */onResolved?: (action: StalledReviewDecisionAction) => void;+ /**+ * The issue's `reviewPolicy` (PAP-16506). Only an opt-in constraint is shown;+ * the default — `null`/`"anyone"` — renders nothing, because "anyone can+ * approve" is what every issue already does.+ */+ reviewPolicy?: IssueReviewPolicy | null;className?: string;}@@ -40,6 +48,7 @@ export function StalledReviewActions({companyId,footerSlot,onResolved,+ reviewPolicy,className,}: StalledReviewActionsProps) {const queryClient = useQueryClient();@@ -73,9 +82,25 @@ export function StalledReviewActions({const noteEmpty = note.trim().length === 0;const runningFor = (action: StalledReviewDecisionAction) =>pending && decide.variables === action;+ const policyBadge = issueReviewPolicyBadge(reviewPolicy);return (<div className={cn("flex flex-col gap-3", className)}>+ {/* Only a constrained policy gets a badge: the server refuses a verdict+ from the wrong actor, so the card has to warn before offering Approve.+ The default needs no line — anyone with write access can approve. */}+ {policyBadge ? (+ <Badge+ variant="outline"+ className="max-w-full min-w-0 self-start font-normal"+ data-testid="review-policy-badge"+ data-review-policy={policyBadge.value}+ title={policyBadge.description}+ >+ <policyBadge.Icon aria-hidden />+ <span className="min-w-0 truncate">{policyBadge.label}</span>+ </Badge>+ ) : null}<Textareavalue={note}onChange={(event) => setNote(event.target.value)}diff --git a/ui/src/components/issue-properties/IssueProperties.tsx b/ui/src/components/issue-properties/IssueProperties.tsxindex 5fa9ada2be..5fa13daff4 100644--- a/ui/src/components/issue-properties/IssueProperties.tsx+++ b/ui/src/components/issue-properties/IssueProperties.tsx@@ -93,6 +93,7 @@ import {} from "./helpers";import { PropertyPicker } from "./property-picker";import { PropertyChip, PropertyRow, PropertySection } from "./primitives";+import { issueReviewPolicyBadge } from "../../lib/review-policy";import { IssueCasesPanel } from "../IssueCasesPanel";import { ExpandRelationListButton, RemovableIssueReferencePill } from "./relation-controls";import { Badge } from "@/components/ui/badge";@@ -848,6 +849,10 @@ export function IssueProperties({const approverTrigger = approverValues.length > 0? <span className="text-sm truncate min-w-0" title={approverLabel}>{approverLabel}</span>: <span className="text-sm text-muted-foreground">None</span>;+ // PAP-16506 P4: who may give the `in_review` verdict. Only an agent sets this,+ // and only the two opt-in constraints are worth a row — the default (`null` ≡+ // "anyone can approve") is what every issue already does, so it shows nothing.+ const reviewPolicyBadge = issueReviewPolicyBadge(issue.reviewPolicy);const nextRunnableExecutionStage = (() => {if (issue.executionState?.status === "changes_requested" && issue.executionState.currentStageType) {return issue.executionState.currentStageType;@@ -2302,6 +2307,16 @@ export function IssueProperties({</PropertySection><PropertySection title="Execution">+ {/* Read-only: agents set the policy, the board does not. */}+ {reviewPolicyBadge ? (+ <PropertyRow label="Approvals">+ <PropertyChip title={reviewPolicyBadge.description}>+ <reviewPolicyBadge.Icon className="shrink-0 text-muted-foreground" aria-hidden />+ <span className="min-w-0 truncate">{reviewPolicyBadge.label}</span>+ </PropertyChip>+ </PropertyRow>+ ) : null}+<PropertyPickerinline={inline}label="Reviewers"diff --git a/ui/src/components/issue-properties/primitives.tsx b/ui/src/components/issue-properties/primitives.tsxindex d2fcb94223..aaf057016e 100644--- a/ui/src/components/issue-properties/primitives.tsx+++ b/ui/src/components/issue-properties/primitives.tsx@@ -69,10 +69,13 @@ export function PropertyChip({children,className,style,+ title,}: {children: ReactNode;className?: string;style?: CSSProperties;+ /** Tooltip override for chips whose children are not a bare string. */+ title?: string;}) {return (<Badge@@ -80,7 +83,7 @@ export function PropertyChip({// Badge chassis; keep this chip's truncation + normal weight + start alignment.className={cn("max-w-full min-w-0 justify-start truncate font-normal", className)}style={style}- title={typeof children === "string" ? children : undefined}+ title={title ?? (typeof children === "string" ? children : undefined)}>{children}</Badge>diff --git a/ui/src/lib/activity-format.test.ts b/ui/src/lib/activity-format.test.tsindex a58605f974..e314e9e116 100644--- a/ui/src/lib/activity-format.test.ts+++ b/ui/src/lib/activity-format.test.ts@@ -66,6 +66,72 @@ describe("activity formatting", () => {expect(formatIssueActivityAction("issue.monitor_recovery_issue_created")).toBe("created a monitor recovery issue");});+ // PAP-16506 P4: agents can now resolve an interaction, including a review of+ // their own work, so an outcome has to read as an outcome in the timeline+ // instead of leaking the raw action id.+ it("reads an interaction outcome as an outcome, whoever gave it", () => {+ expect(formatIssueActivityAction("issue.thread_interaction_accepted")).toBe("accepted the request");+ expect(formatIssueActivityAction("issue.thread_interaction_rejected")).toBe("rejected the request");+ expect(formatIssueActivityAction("issue.thread_interaction_withdrawn")).toBe("withdrew the request");+ expect(formatIssueActivityAction("issue.thread_interaction_expired")).toBe("expired the request");+ expect(formatActivityVerb("issue.thread_interaction_accepted")).toBe("accepted the request on");+ expect(formatActivityVerb("issue.thread_interaction_rejected")).toBe("rejected the request on");+ });++ // The accepted/rejected actions fire for every interaction kind, so only a+ // confirmation may read as an approval.+ it("says 'approved' only for a confirmation, never for a suggestion or a question", () => {+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "request_confirmation" }))+ .toBe("approved the request");+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "request_checkbox_confirmation" }))+ .toBe("approved the request");+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "suggest_tasks" }))+ .toBe("accepted the task suggestions");+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "ask_user_questions" }))+ .toBe("accepted the answers");+ expect(formatIssueActivityAction("issue.thread_interaction_rejected", { interactionKind: "request_confirmation" }))+ .toBe("rejected the request");+ expect(formatIssueActivityAction("issue.thread_interaction_rejected", { interactionKind: "suggest_tasks" }))+ .toBe("declined the task suggestions");+ expect(formatActivityVerb("issue.thread_interaction_accepted", { interactionKind: "suggest_tasks" }))+ .toBe("accepted the task suggestions on");+ });++ it("keeps the neutral wording for a kind it does not know", () => {+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "request_item_verdicts" }))+ .toBe("accepted the request");+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: "future_kind" }))+ .toBe("accepted the request");+ expect(formatIssueActivityAction("issue.thread_interaction_accepted", { interactionKind: 7 }))+ .toBe("accepted the request");+ });++ it("names the verb an actor chose on a stalled review", () => {+ expect(formatIssueActivityAction("issue.stalled_review_decided", { action: "approve" }))+ .toBe("approved the review");+ expect(formatIssueActivityAction("issue.stalled_review_decided", { action: "request_changes" }))+ .toBe("requested changes on the review");+ expect(formatIssueActivityAction("issue.stalled_review_decided", { action: "send_back" }))+ .toBe("sent the review back to work");+ expect(formatActivityVerb("issue.stalled_review_decided", { action: "approve" }))+ .toBe("approved the review on");+ });++ it("falls back to a generic verdict line when the decision verb is missing", () => {+ expect(formatIssueActivityAction("issue.stalled_review_decided")).toBe("recorded a review verdict");+ expect(formatIssueActivityAction("issue.stalled_review_decided", { action: "shrug" }))+ .toBe("recorded a review verdict");+ });++ it("describes a review-policy change without calling the default 'none'", () => {+ expect(formatIssueActivityAction("issue.updated", { reviewPolicy: null }))+ .toBe("changed who can approve to anyone");+ expect(formatIssueActivityAction("issue.updated", { reviewPolicy: "human_only" }))+ .toBe("changed who can approve to human only");+ expect(formatIssueActivityAction("issue.updated", { reviewPolicy: "not_creator" }))+ .toBe("changed who can approve to anyone else");+ });+it("uses plain next-step copy for successful-run handoff activity", () => {expect(formatActivityVerb("issue.successful_run_handoff_required")).toBe("flagged missing next step on");expect(formatIssueActivityAction("issue.successful_run_handoff_required")).toBe("Run finished without a clear next step");diff --git a/ui/src/lib/activity-format.ts b/ui/src/lib/activity-format.tsindex 6ff6c0c4eb..0d4f015de6 100644--- a/ui/src/lib/activity-format.ts+++ b/ui/src/lib/activity-format.ts@@ -1,5 +1,6 @@import type { Agent } from "@paperclipai/shared";import type { CompanyUserProfile } from "./company-members";+import { formatReviewPolicyValue } from "./review-policy";type ActivityDetails = Record<string, unknown> | null | undefined;@@ -69,6 +70,19 @@ const ACTIVITY_ROW_VERBS: Record<string, string> = {"approval.created": "requested approval","approval.approved": "approved","approval.rejected": "rejected",+ // Interaction outcomes (PAP-16506). An agent may now resolve one — including a+ // review of its own work — so these must read as outcomes in the feed instead+ // of falling through to the raw "issue thread interaction accepted" action id.+ // `details.interactionKind` sharpens the wording; see INTERACTION_OUTCOME_LABELS.+ "issue.thread_interaction_created": "asked for a decision on",+ "issue.thread_interaction_accepted": "accepted the request on",+ "issue.thread_interaction_rejected": "rejected the request on",+ "issue.thread_interaction_answered": "answered the request on",+ "issue.thread_interaction_withdrawn": "withdrew the request on",+ "issue.thread_interaction_cancelled": "cancelled the request on",+ "issue.thread_interaction_expired": "expired the request on",+ "issue.thread_interaction_item_verdicts_submitted": "submitted verdicts on",+ "issue.stalled_review_decided": "recorded a review verdict on","project.created": "created","project.updated": "updated","project.deleted": "deleted",@@ -133,8 +147,64 @@ const ISSUE_ACTIVITY_LABELS: Record<string, string> = {"approval.created": "requested approval","approval.approved": "approved","approval.rejected": "rejected",+ "issue.thread_interaction_created": "asked for a decision",+ "issue.thread_interaction_accepted": "accepted the request",+ "issue.thread_interaction_rejected": "rejected the request",+ "issue.thread_interaction_answered": "answered the request",+ "issue.thread_interaction_withdrawn": "withdrew the request",+ "issue.thread_interaction_cancelled": "cancelled the request",+ "issue.thread_interaction_expired": "expired the request",+ "issue.thread_interaction_item_verdicts_submitted": "submitted verdicts on the request",+ "issue.stalled_review_decided": "recorded a review verdict",};+/**+ * `issue.stalled_review_decided` carries the verb the actor chose, so the line+ * names the verdict ("approved the review") rather than the generic action.+ * Mirrors `StalledReviewDecisionAction` in shared.+ */+const STALLED_REVIEW_DECISION_LABELS: Record<string, string> = {+ approve: "approved the review",+ request_changes: "requested changes on the review",+ send_back: "sent the review back to work",+};++/**+ * `issue.thread_interaction_accepted` / `_rejected` fire for *every* interaction+ * kind, not only for a review. A task suggestion or a question is accepted, not+ * approved, so the kind on the event picks the verb. Kinds absent from a map+ * keep the neutral "accepted the request" wording from the tables above, which+ * is also the fallback for an event that carries no kind.+ */+const INTERACTION_ACCEPTED_LABELS: Record<string, string> = {+ request_confirmation: "approved the request",+ request_checkbox_confirmation: "approved the request",+ suggest_tasks: "accepted the task suggestions",+ ask_user_questions: "accepted the answers",+};++const INTERACTION_REJECTED_LABELS: Record<string, string> = {+ request_confirmation: "rejected the request",+ request_checkbox_confirmation: "rejected the request",+ suggest_tasks: "declined the task suggestions",+ ask_user_questions: "declined the questions",+};++/**+ * Kind-aware wording for an interaction outcome, or `null` when the tables+ * above already say it well enough.+ */+function formatInteractionOutcomeLabel(action: string, details: ActivityDetails): string | null {+ const table = action === "issue.thread_interaction_accepted"+ ? INTERACTION_ACCEPTED_LABELS+ : action === "issue.thread_interaction_rejected"+ ? INTERACTION_REJECTED_LABELS+ : null;+ if (!table) return null;+ const kind = typeof details?.interactionKind === "string" ? details.interactionKind : null;+ return kind ? table[kind] ?? null : null;+}+function asRecord(value: unknown): Record<string, unknown> | null {if (!value || typeof value !== "object" || Array.isArray(value)) return null;return value as Record<string, unknown>;@@ -284,6 +354,11 @@ function formatIssueUpdatedAction(details: ActivityDetails, options: ActivityForconst assigneeName = formatAssigneeName(details, options);parts.push(assigneeName ? `made ${assigneeName} responsible for the task` : "cleared the responsible");}+ if (details.reviewPolicy !== undefined) {+ // `null` is the default ("anyone can approve"), so it must not read as+ // "changed the review policy to none" (PAP-16506).+ parts.push(`changed who can approve to ${formatReviewPolicyValue(details.reviewPolicy)}`);+ }if (details.title !== undefined) parts.push("updated the title");if (details.description !== undefined) parts.push("updated the description");@@ -342,6 +417,15 @@ export function formatActivityVerb(if (issueUpdatedVerb) return issueUpdatedVerb;}+ if (action === "issue.stalled_review_decided") {+ const decision = typeof details?.action === "string" ? details.action : null;+ const label = decision ? STALLED_REVIEW_DECISION_LABELS[decision] : null;+ if (label) return `${label} on`;+ }++ const outcomeLabel = formatInteractionOutcomeLabel(action, details);+ if (outcomeLabel) return `${outcomeLabel} on`;+const structuredChange = formatStructuredIssueChange({action,details,@@ -376,6 +460,15 @@ export function formatIssueActivityAction(if (detail) return detail;}+ if (action === "issue.stalled_review_decided") {+ const decision = typeof details?.action === "string" ? details.action : null;+ const label = decision ? STALLED_REVIEW_DECISION_LABELS[decision] : null;+ if (label) return label;+ }++ const outcomeLabel = formatInteractionOutcomeLabel(action, details);+ if (outcomeLabel) return outcomeLabel;+if (action.startsWith("issue.monitor_") && details) {const serviceName = typeof details.serviceName === "string" && details.serviceName.trim()? details.serviceName.trim()diff --git a/ui/src/lib/issue-change-receipt.test.ts b/ui/src/lib/issue-change-receipt.test.tsindex b7d43c447a..af4b4c9561 100644--- a/ui/src/lib/issue-change-receipt.test.ts+++ b/ui/src/lib/issue-change-receipt.test.ts@@ -12,6 +12,7 @@ describe("issueChangeFieldLabel", () => {expect(issueChangeFieldLabel("assigneeAgentId")).toBe("Assignee");expect(issueChangeFieldLabel("blockedByIssueIds")).toBe("Blockers");expect(issueChangeFieldLabel("workMode")).toBe("Work mode");+ expect(issueChangeFieldLabel("reviewPolicy")).toBe("Who can approve");});it("humanizes unknown camelCase and snake_case fields", () => {@@ -35,6 +36,14 @@ describe("formatIssueChangeValue", () => {expect(formatIssueChangeValue("high")).toBe("high");});+ // A cleared `reviewPolicy` means "anyone can approve" (PAP-16506), so the+ // receipt must not report the default as an absent value.+ it("reads a cleared review policy as 'anyone', not 'none'", () => {+ expect(formatIssueChangeValue(null, { field: "reviewPolicy" })).toBe("anyone");+ expect(formatIssueChangeValue("human_only", { field: "reviewPolicy" })).toBe("human only");+ expect(formatIssueChangeValue("not_creator", { field: "reviewPolicy" })).toBe("anyone else");+ });+it("renders booleans and numbers plainly", () => {expect(formatIssueChangeValue(true)).toBe("yes");expect(formatIssueChangeValue(false)).toBe("no");diff --git a/ui/src/lib/issue-change-receipt.ts b/ui/src/lib/issue-change-receipt.tsindex 7f58a2c231..f5f5a08623 100644--- a/ui/src/lib/issue-change-receipt.ts+++ b/ui/src/lib/issue-change-receipt.ts@@ -1,4 +1,5 @@import type { IssueChangeReceiptEntry } from "@paperclipai/shared";+import { formatReviewPolicyValue } from "./review-policy";/*** Read + format the field-level change receipts carried on an `issue.updated`@@ -25,6 +26,7 @@ const FIELD_LABELS: Record<string, string> = {projectId: "Project",goalId: "Goal",workMode: "Work mode",+ reviewPolicy: "Who can approve",billingCode: "Billing code",checkoutRunId: "Checkout run",executionRunId: "Execution run",@@ -64,6 +66,9 @@ export function formatIssueChangeValue(resolveUserLabel?: (id: string) => string | null | undefined;field?: string } = {},): string {+ // `reviewPolicy` is nullable-by-default: a cleared column means "anyone can+ // approve", not "no value" (PAP-16506), so it resolves before the null branch.+ if (options.field === "reviewPolicy") return formatReviewPolicyValue(value);if (value === null || value === undefined || value === "") return "none";if (typeof value === "boolean") return value ? "yes" : "no";if (typeof value === "number") return String(value);diff --git a/ui/src/lib/review-policy.test.ts b/ui/src/lib/review-policy.test.tsnew file mode 100644index 0000000000..a6667dc5f7--- /dev/null+++ b/ui/src/lib/review-policy.test.ts@@ -0,0 +1,64 @@+import { describe, expect, it } from "vitest";++import {+ formatReviewPolicyValue,+ issueReviewPolicyBadge,+ readIssueReviewPolicyMetadata,+} from "./review-policy";++describe("issueReviewPolicyBadge", () => {+ // The default is what every issue already does, so it earns no pixels.+ it("shows nothing for the default, however the column spells it", () => {+ expect(issueReviewPolicyBadge(null)).toBeNull();+ expect(issueReviewPolicyBadge(undefined)).toBeNull();+ expect(issueReviewPolicyBadge("anyone")).toBeNull();+ });++ it("badges each opt-in constraint in the board's words", () => {+ expect(issueReviewPolicyBadge("not_creator")?.label).toBe("Anyone else");+ expect(issueReviewPolicyBadge("human_only")?.label).toBe("Human only");+ });++ it("spells the rule out in the tooltip so the badge is recoverable", () => {+ expect(issueReviewPolicyBadge("not_creator")?.description).toContain("asked for the review");+ expect(issueReviewPolicyBadge("human_only")?.description).toContain("Agents cannot");+ });++ it("shows nothing for a policy this build does not know", () => {+ expect(issueReviewPolicyBadge("board_only" as never)).toBeNull();+ });+});++describe("formatReviewPolicyValue", () => {+ it("reads a cleared policy as 'anyone', never as 'none'", () => {+ expect(formatReviewPolicyValue(null)).toBe("anyone");+ expect(formatReviewPolicyValue(undefined)).toBe("anyone");+ expect(formatReviewPolicyValue("anyone")).toBe("anyone");+ });++ it("uses the badge wording mid-sentence so a receipt matches the badge", () => {+ expect(formatReviewPolicyValue("not_creator")).toBe("anyone else");+ expect(formatReviewPolicyValue("human_only")).toBe("human only");+ });++ it("humanizes an unknown policy rather than hiding it", () => {+ expect(formatReviewPolicyValue("board_only")).toBe("board only");+ });+});++describe("readIssueReviewPolicyMetadata", () => {+ it("reads the policy off an attention subject's metadata bag", () => {+ expect(readIssueReviewPolicyMetadata({ reviewPolicy: "human_only" })).toBe("human_only");+ });++ it("returns null when the subject carries no policy", () => {+ expect(readIssueReviewPolicyMetadata(null)).toBeNull();+ expect(readIssueReviewPolicyMetadata(undefined)).toBeNull();+ expect(readIssueReviewPolicyMetadata({ priority: "high" })).toBeNull();+ });++ it("rejects a value outside the enum instead of trusting the wire", () => {+ expect(readIssueReviewPolicyMetadata({ reviewPolicy: "board_only" })).toBeNull();+ expect(readIssueReviewPolicyMetadata({ reviewPolicy: 3 })).toBeNull();+ });+});diff --git a/ui/src/lib/review-policy.ts b/ui/src/lib/review-policy.tsnew file mode 100644index 0000000000..a97f23ba26--- /dev/null+++ b/ui/src/lib/review-policy.ts@@ -0,0 +1,88 @@+import { UserCheck, UserMinus, type LucideIcon } from "lucide-react";+import { ISSUE_REVIEW_POLICIES, type IssueReviewPolicy } from "@paperclipai/shared";++/**+ * Copy for an issue's `reviewPolicy` (PAP-16506 P4).+ *+ * `in_review` means the work needs a verdict, and by default anyone with write+ * access can give it — people and agents alike, including the agent that did the+ * work. That default needs no UI at all: it is what every issue already does,+ * and there is no control for changing it. Only an agent sets the column, and+ * only the two opt-in constraints are worth showing:+ *+ * - `not_creator` — "Anyone else": the reviewer must not be the requester.+ * - `human_only` — "Human only": an agent cannot give the verdict.+ *+ * A `null` or `"anyone"` column renders nothing. Every surface that shows the+ * policy routes through {@link issueReviewPolicyBadge} so the review card, the+ * issue properties row, and the activity receipt cannot drift from each other or+ * from the server's refusal copy in `server/src/services/issue-review-policy.ts`.+ */++export interface IssueReviewPolicyBadge {+ value: IssueReviewPolicy;+ /** Badge text. */+ label: string;+ /** Tooltip — the rule the server enforces, spelled out. */+ description: string;+ Icon: LucideIcon;+}++/** Only the constrained policies are shown; `anyone` is the silent default. */+const BADGES: Partial<Record<IssueReviewPolicy, IssueReviewPolicyBadge>> = {+ not_creator: {+ value: "not_creator",+ label: "Anyone else",+ description: "Anyone except whoever asked for the review can approve it.",+ Icon: UserMinus,+ },+ human_only: {+ value: "human_only",+ label: "Human only",+ description: "Only a person can approve this review. Agents cannot give the verdict.",+ Icon: UserCheck,+ },+};++/** Mid-sentence wording for activity lines and field-change receipts. */+const VALUE_LABELS: Record<IssueReviewPolicy, string> = {+ anyone: "anyone",+ not_creator: "anyone else",+ human_only: "human only",+};++/**+ * The badge for a policy, or `null` when there is nothing to show — which is the+ * common case, since an unset column means the default "anyone can approve".+ */+export function issueReviewPolicyBadge(+ policy: IssueReviewPolicy | null | undefined,+): IssueReviewPolicyBadge | null {+ if (typeof policy !== "string") return null;+ return BADGES[policy as IssueReviewPolicy] ?? null;+}++/**+ * Mid-sentence wording for an activity line or a field-change receipt, where a+ * cleared column must read "anyone" rather than "none".+ */+export function formatReviewPolicyValue(value: unknown): string {+ if (value === null || value === undefined) return VALUE_LABELS.anyone;+ if (typeof value !== "string") return VALUE_LABELS.anyone;+ // Forward-compatible: a policy this build does not know reads as itself.+ return VALUE_LABELS[value as IssueReviewPolicy] ?? value.replace(/_/g, " ");+}++/**+ * Read the policy off an untyped `AttentionSubject.metadata` bag. Absent or+ * unrecognised → `null`, which every consumer treats as the default.+ */+export function readIssueReviewPolicyMetadata(+ metadata: Record<string, unknown> | null | undefined,+): IssueReviewPolicy | null {+ const raw = metadata?.reviewPolicy;+ if (typeof raw !== "string") return null;+ return (ISSUE_REVIEW_POLICIES as readonly string[]).includes(raw)+ ? (raw as IssueReviewPolicy)+ : null;+}