mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-24 01:41:42 +02:00
## Thinking Path > - Paperclip manages agent work as tasks and runs. > - GitHub chat brings repository conversations into those tasks. > - A review bot needs the assigned agent, its authority, and governed provider tools. > - The existing channel connection did not supply that review workflow or a complete setup journey. > - This pull request adds GitHub App setup, account access, event prompts, task-bound review tools, and exact-commit checks. > - Operators can inspect each review through the same task, run, and activity systems. ## Linked Issues or Issue Description **Subsystem affected** GitHub chat, governed connection tools, task execution, shared/database contracts, and connector setup UI. **Problem or motivation** Operators need a GitHub review bot that runs their assigned Paperclip agent. Mentions and PR events must preserve task ownership and requester authority. Provider publication must use the bot App identity and enforce the configured permissions. **Proposed solution** Extend the existing GitHub chat connector with resumable App onboarding, linked-member and sponsored-guest access, editable event prompts, and governed review operations. Validate structured assessments on the server and compute a stable Paperclip Review check for the exact head commit. **Alternatives considered** A separate review scheduler would duplicate Paperclip execution and permissions. Reusing personal GitHub credentials would change the bot identity and credential boundary. **Roadmap alignment** This extends the existing Connected Apps and governed-tool infrastructure. The project owner requested and approved this design. Related PR #8645 imports external Codex review feedback; this change runs an assigned Paperclip agent and publishes its results through the existing chat connector. ## What Changed - Include the current Paperclip instance origin in the copied setup prompt. Storybook uses its configured Paperclip origin; callback parameters and URL credentials are excluded. - Add a Claude/Codex copy button in the real setup and Storybook opening step. Its detailed prompt asks four setup questions and guides embedded-browser setup, verification, and optional required checks. Clipboard failure exposes selectable instructions. - Add a tutorial that explains why App installation, review scheduling, and required checks are separate choices. - Add manifest registration, an existing-App path, separate installation and repository selection, repository refresh, and explicit account confirmation. - Add low-trust agent guidance, effective capability verification, member selection, and explicit restricted guests with a sponsor. - Add configurable PR events, prompts, repository overrides, rating thresholds, and separate formal-review permissions. - Give the assigned agent governed App tools to read PRs, comment, begin an assessment, submit findings, and optionally submit a formal review. - Bind review history, root PR events, and inline replies to ordinary tasks. Deduplicate deliveries/findings and reject stale publication. - Link check Details to the underlying task on the current trusted hostname, or to Reviews before task creation. - Add schema migration 0283, API contracts, production UI, and 49 interactive Storybook states. - Repair local lease recovery. Keep the Cloud Dockerfile identical to master; no provider-pack layer or runtime-default environment variable is added. - Retry only rolled-back wake-admission transactions after transient endpoint-lock contention. A deterministic held-lock regression proves one accepted wake. ## Verification - Current head: `7ba761fe007bb798400d3e62346fa964f607f0f8`, rebased on master `d9b3a5653e41f2ee5a1345b97c86a238f7a5c8e9`. Dockerfile has zero diff against master. Final workspace typecheck and build passed. The new PostgreSQL migration regression passed and preserves existing relation and constraint identities after replay. - Greptile reviewed this exact head at 5/5. There are zero unresolved review threads and no merge conflicts. - All current-head checks are green: 54 passed and two conditional Storybook jobs skipped. This includes complete server/workspace test suites, build, typechecks, policy checks, Runner suites, browser suites, and security status. One timing-sensitive callback-ordering test passed in isolation and its CI shard passed one retry. The duplicate local full-suite run was stopped after CI completed; it is not counted as a local full-suite pass. - Before the final Slack rebase and migration renumbering, 186 focused GitHub tests, 14 native bootstrap cases, token gates, and Storybook build passed. The final rebase retained the new Slack communication guidance. - The embedded-browser setup test copied the full detailed prompt, including the configured Paperclip instance URL. Desktop and narrow layouts were checked. Component tests cover successful copying and clipboard failure with selectable text and retry. - Live local and hosted GitHub acceptance evidence refers to application revision `cb703ac959876a07ebf3d7a295847f9f351eb6fc`. Real agent tasks exercised issue mentions, automatic PR reviews, inline findings, repeated mentions, task continuation, and failing-to-passing checks after a push. The Storybook agent generated, built, and browser-rendered pages; missing acceptance text failed, matching text passed, and broken JSX produced an incomplete result. - Live cases also covered independently disabled push events, prompt injection, duplicate signed deliveries, rapid pushes, stale-result rejection, finding deduplication, and restart recovery. Formal reviews were denied while disabled and published only after explicit enablement. Check Details links pointed to the underlying task on the trusted hostname. - Those hosted native Claude runs used the provider-pack layer now removed from this PR. They do not prove native Claude works on the standard Cloud image. A replacement hosted native Codex run is not yet verified: the disposable QA tenant has only an Anthropic AI connection. No new staging or production deployment was made for the packaging removal. - Required-check merge enforcement could not be tested because the private disposable repository's GitHub plan rejected the rules configuration. Published success/failure/incomplete check states were verified directly. ## Risks - Latest master allocated migration 0282 to Slack. The GitHub migration is regenerated as 0283 with replay-safe table/index/constraint creation; a PostgreSQL regression verifies existing relations and constraints are preserved. Existing preview tenants remain subject to the fleet migration-history compatibility preflight; no bypass is introduced. - Migration 0283 adds company-scoped configuration, registration, review, and publication records. Existing connections retain their behavior until reviews/tools are enabled. - Signed webhooks and expiring registration state remain required. Hosted installations also need the companion narrow Cloud gateway exemptions. - Agent assessments can be incomplete or wrong. The server enforces coverage/result structure, current-head publication, rating policy, and separate formal-review permission; it does not replace code-review judgment. - No Cloud image packaging changes are included. Remote native ACPX/Claude and OpenCode retain their existing operator-supplied provider-pack prerequisite. Native Codex and Codex with managed MCP tools do not require that pack. Earlier staging deployment evidence refers to its stated revision, not this packaging-removal head. Production rollout and merging remain outside this change. ## Model Used OpenAI GPT-6 through Codex, with repository, code execution, API, and embedded-browser tools. The exact serving model ID and context-window size were not exposed by the environment. ## 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: Paperclip <noreply@paperclip.ing>
714 lines
24 KiB
TypeScript
714 lines
24 KiB
TypeScript
import { copyTextToClipboard } from "@/lib/clipboard";
|
||
import { useRef, useState } from "react";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import {
|
||
GITHUB_REVIEW_EVENTS,
|
||
type GitHubChatConfiguration,
|
||
type GitHubReviewPolicy,
|
||
type GitHubAllowedPerson,
|
||
} from "@paperclipai/shared";
|
||
import { accessApi } from "@/api/access";
|
||
import { chatEndpointsApi } from "@/api/chatEndpoints";
|
||
import { githubChatApi } from "@/api/githubChat";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input } from "@/components/ui/input";
|
||
import { Textarea } from "@/components/ui/textarea";
|
||
import { Label } from "@/components/ui/label";
|
||
import { ToggleSwitch } from "@/components/ui/toggle-switch";
|
||
import { Link } from "@/lib/router";
|
||
|
||
export const githubSelectClass =
|
||
"w-full rounded-md border border-input bg-background px-3 py-2 text-sm";
|
||
const eventLabels = {
|
||
opened: "New pull request",
|
||
synchronize: "Updated commits",
|
||
reopened: "Reopened",
|
||
ready_for_review: "Ready for review",
|
||
mention: "Mention",
|
||
comment: "Follow-up comment",
|
||
};
|
||
export function GitHubToggle({
|
||
label,
|
||
description,
|
||
checked,
|
||
onChange,
|
||
}: {
|
||
label: string;
|
||
description?: string;
|
||
checked: boolean;
|
||
onChange: (checked: boolean) => void;
|
||
}) {
|
||
return (
|
||
<div className="flex items-center justify-between gap-4 py-2">
|
||
<div>
|
||
<p className="text-sm font-medium">{label}</p>
|
||
{description && (
|
||
<p className="mt-1 text-xs text-muted-foreground">{description}</p>
|
||
)}
|
||
</div>
|
||
<ToggleSwitch
|
||
aria-label={label}
|
||
checked={checked}
|
||
onCheckedChange={onChange}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|
||
export function GitHubPolicyEditor({
|
||
policy,
|
||
onChange,
|
||
}: {
|
||
policy: GitHubReviewPolicy;
|
||
onChange: (policy: GitHubReviewPolicy) => void;
|
||
}) {
|
||
const [prompt, setPrompt] =
|
||
useState<(typeof GITHUB_REVIEW_EVENTS)[number]>("opened");
|
||
const set = <K extends keyof GitHubReviewPolicy>(
|
||
key: K,
|
||
value: GitHubReviewPolicy[K],
|
||
) => onChange({ ...policy, [key]: value });
|
||
return (
|
||
<div className="space-y-6">
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-invocation">
|
||
When should this agent review?
|
||
</Label>
|
||
<select
|
||
id="github-invocation"
|
||
className={githubSelectClass}
|
||
value={policy.invocation}
|
||
onChange={(e) =>
|
||
set(
|
||
"invocation",
|
||
e.target.value as GitHubReviewPolicy["invocation"],
|
||
)
|
||
}
|
||
>
|
||
<option value="linked_authors">
|
||
Linked members’ PRs and authorized mentions
|
||
</option>
|
||
<option value="mentions_only">Authorized mentions only</option>
|
||
<option value="allowed_authors">
|
||
Allowed authors’ PRs and authorized mentions
|
||
</option>
|
||
</select>
|
||
<p className="text-xs text-muted-foreground">
|
||
Newly added people have a separate automatic-review setting in Access.
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<h3 className="text-sm font-medium">Automatic review events</h3>
|
||
{GITHUB_REVIEW_EVENTS.slice(0, 4).map((event) => (
|
||
<GitHubToggle
|
||
key={event}
|
||
label={eventLabels[event]}
|
||
checked={policy.events.includes(event)}
|
||
onChange={(enabled) =>
|
||
set(
|
||
"events",
|
||
enabled
|
||
? [...new Set([...policy.events, event])]
|
||
: policy.events.filter((value) => value !== event),
|
||
)
|
||
}
|
||
/>
|
||
))}
|
||
<GitHubToggle
|
||
label="Include draft PRs"
|
||
checked={policy.reviewDrafts}
|
||
onChange={(value) => set("reviewDrafts", value)}
|
||
/>
|
||
<GitHubToggle
|
||
label="Include bot authors"
|
||
description="Also allow the bot account in Access with a sponsor and automatic reviews enabled."
|
||
checked={policy.reviewBotAuthors}
|
||
onChange={(value) => set("reviewBotAuthors", value)}
|
||
/>
|
||
</div>
|
||
<details className="rounded-lg border border-border p-4">
|
||
<summary className="cursor-pointer text-sm font-medium">
|
||
Author, branch, label, and file filters
|
||
</summary>
|
||
<div className="mt-4 grid gap-4 sm:grid-cols-2">
|
||
{(
|
||
[
|
||
[
|
||
"includeAuthors",
|
||
"Included authors",
|
||
"Leave empty to include any authorized author. One username or glob per line.",
|
||
],
|
||
[
|
||
"excludeAuthors",
|
||
"Excluded authors",
|
||
"One username or glob per line.",
|
||
],
|
||
[
|
||
"targetBranches",
|
||
"Target branches",
|
||
"Leave empty for all branches. Supports * and **.",
|
||
],
|
||
[
|
||
"excludedBranches",
|
||
"Excluded target branches",
|
||
"Never automatically review these branches. Supports * and **.",
|
||
],
|
||
[
|
||
"requiredLabels",
|
||
"Required labels",
|
||
"All listed labels must be present.",
|
||
],
|
||
[
|
||
"excludedLabels",
|
||
"Excluded labels",
|
||
"Any listed label prevents automatic review.",
|
||
],
|
||
[
|
||
"ignoredPaths",
|
||
"Ignored file paths",
|
||
"Excluded from manual and automatic analysis. Supports * and **.",
|
||
],
|
||
] as const
|
||
).map(([key, label, help]) => (
|
||
<div className="space-y-2" key={key}>
|
||
<Label htmlFor={`github-${key}`}>{label}</Label>
|
||
<Textarea
|
||
id={`github-${key}`}
|
||
value={policy[key].join("\n")}
|
||
onChange={(e) =>
|
||
set(key, e.target.value.split("\n").filter(Boolean))
|
||
}
|
||
/>
|
||
<p className="text-xs text-muted-foreground">{help}</p>
|
||
</div>
|
||
))}
|
||
</div>
|
||
<p className="mt-3 text-xs text-muted-foreground">
|
||
Authorized manual requests bypass automatic scheduling filters.
|
||
Repository restrictions and ignored files still apply.
|
||
</p>
|
||
</details>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-instructions">Review instructions</Label>
|
||
<Textarea
|
||
id="github-instructions"
|
||
value={policy.instructions}
|
||
onChange={(e) => set("instructions", e.target.value)}
|
||
/>
|
||
<p className="text-xs text-muted-foreground">
|
||
Additional guidance for the assigned agent. Provider content cannot
|
||
change its permissions.
|
||
</p>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-prompt-event">Event prompts</Label>
|
||
<select
|
||
id="github-prompt-event"
|
||
className={githubSelectClass}
|
||
value={prompt}
|
||
onChange={(e) => setPrompt(e.target.value as typeof prompt)}
|
||
>
|
||
{GITHUB_REVIEW_EVENTS.map((event) => (
|
||
<option key={event} value={event}>
|
||
{eventLabels[event]}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<Textarea
|
||
aria-label={`${eventLabels[prompt]} prompt`}
|
||
value={policy.prompts[prompt]}
|
||
onChange={(e) =>
|
||
set("prompts", { ...policy.prompts, [prompt]: e.target.value })
|
||
}
|
||
/>
|
||
<p className="text-xs text-muted-foreground">
|
||
Paperclip supplies repository, PR, base and head commits, sender, and
|
||
prior head as typed context. Saved revisions remain attached to review
|
||
activity.
|
||
</p>
|
||
</div>
|
||
<div className="grid gap-4 sm:grid-cols-2">
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-categories">Finding categories</Label>
|
||
<Input
|
||
id="github-categories"
|
||
value={policy.findingCategories.join(", ")}
|
||
onChange={(e) =>
|
||
set(
|
||
"findingCategories",
|
||
e.target.value
|
||
.split(",")
|
||
.map((value) => value.trim())
|
||
.filter(Boolean),
|
||
)
|
||
}
|
||
/>
|
||
<p className="text-xs text-muted-foreground">
|
||
Comma-separated assessment categories.
|
||
</p>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-severity">
|
||
Minimum inline comment severity
|
||
</Label>
|
||
<select
|
||
id="github-severity"
|
||
className={githubSelectClass}
|
||
value={policy.minimumCommentSeverity}
|
||
onChange={(e) =>
|
||
set(
|
||
"minimumCommentSeverity",
|
||
e.target.value as GitHubReviewPolicy["minimumCommentSeverity"],
|
||
)
|
||
}
|
||
>
|
||
<option value="info">Info</option>
|
||
<option value="warning">Warning</option>
|
||
<option value="error">Error</option>
|
||
</select>
|
||
<p className="text-xs text-muted-foreground">
|
||
Hidden comments still count in the assessment.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<h3 className="text-sm font-medium">Publication permissions</h3>
|
||
<GitHubToggle
|
||
label="Publish summary"
|
||
checked={policy.publishSummary}
|
||
onChange={(value) => set("publishSummary", value)}
|
||
/>
|
||
<GitHubToggle
|
||
label="Publish inline findings"
|
||
checked={policy.publishInline}
|
||
onChange={(value) => set("publishInline", value)}
|
||
/>
|
||
<GitHubToggle
|
||
label="Allow formal approvals"
|
||
description="A separate agent action; a 5/5 score never automatically approves."
|
||
checked={policy.allowApprove}
|
||
onChange={(value) => set("allowApprove", value)}
|
||
/>
|
||
<GitHubToggle
|
||
label="Allow formal request changes"
|
||
checked={policy.allowRequestChanges}
|
||
onChange={(value) => set("allowRequestChanges", value)}
|
||
/>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-rating">Paperclip Review check</Label>
|
||
<select
|
||
id="github-rating"
|
||
className={githubSelectClass}
|
||
value={policy.ratingThreshold ?? "report"}
|
||
onChange={(e) =>
|
||
set(
|
||
"ratingThreshold",
|
||
e.target.value === "report"
|
||
? null
|
||
: (Number(e.target.value) as 1 | 2 | 3 | 4 | 5),
|
||
)
|
||
}
|
||
>
|
||
{[5, 4, 3, 2, 1].map((score) => (
|
||
<option key={score} value={score}>
|
||
Require at least {score}/5
|
||
</option>
|
||
))}
|
||
<option value="report">Report only</option>
|
||
</select>
|
||
<p className="text-xs text-muted-foreground">
|
||
Paperclip computes the result for the exact reviewed commit.
|
||
Incomplete reviews cannot pass. To require it before merging, select
|
||
“Paperclip Review” in your GitHub branch protection or ruleset
|
||
settings and choose this bot’s GitHub App as the expected source. Run
|
||
a review first so the check appears in GitHub’s selector.
|
||
</p>
|
||
<a
|
||
className="text-xs underline"
|
||
href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/creating-rulesets-for-a-repository"
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
>
|
||
Set up a required check on GitHub
|
||
</a>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export function GitHubAccessEditor({
|
||
endpointId,
|
||
companyId,
|
||
configuration,
|
||
onChange,
|
||
}: {
|
||
endpointId: string;
|
||
companyId: string;
|
||
configuration: GitHubChatConfiguration;
|
||
onChange: (configuration: GitHubChatConfiguration) => void;
|
||
}) {
|
||
const accountLink = useRef<HTMLAnchorElement>(null);
|
||
const [linkCopied, setLinkCopied] = useState(false);
|
||
const members = useQuery({
|
||
queryKey: ["github-members", companyId],
|
||
queryFn: () => accessApi.listMembers(companyId),
|
||
});
|
||
const links = useQuery({
|
||
queryKey: ["github-linked-members", endpointId],
|
||
queryFn: () => chatEndpointsApi.listPrincipals(endpointId),
|
||
});
|
||
const [kind, setKind] = useState<"member" | "guest" | null>(null);
|
||
const [login, setLogin] = useState("");
|
||
const [sponsor, setSponsor] = useState(configuration.responsibleUserId);
|
||
const [candidate, setCandidate] = useState<{
|
||
githubUserId: string;
|
||
login: string;
|
||
} | null>(null);
|
||
const [error, setError] = useState("");
|
||
const [busy, setBusy] = useState(false);
|
||
const add = (person: GitHubAllowedPerson) => {
|
||
if (
|
||
configuration.people.some((p) => p.githubUserId === person.githubUserId)
|
||
)
|
||
return;
|
||
onChange({
|
||
...configuration,
|
||
...(person.kind === "member" ? { memberAccess: "selected" } : {}),
|
||
people: [...configuration.people, person],
|
||
});
|
||
setKind(null);
|
||
setCandidate(null);
|
||
setLogin("");
|
||
};
|
||
const activeMembers = (members.data?.members ?? []).filter(
|
||
(member) =>
|
||
member.status === "active" && member.membershipRole !== "viewer",
|
||
);
|
||
return (
|
||
<div className="space-y-5">
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-responsible">
|
||
Responsible user for automatic events
|
||
</Label>
|
||
<select
|
||
id="github-responsible"
|
||
className={githubSelectClass}
|
||
value={configuration.responsibleUserId}
|
||
onChange={(e) =>
|
||
onChange({ ...configuration, responsibleUserId: e.target.value })
|
||
}
|
||
>
|
||
{activeMembers.map((member) => (
|
||
<option key={member.principalId} value={member.principalId}>
|
||
{member.user?.name ?? member.user?.email ?? member.principalId}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<p className="text-xs text-muted-foreground">
|
||
Accountable for automatic tasks. The PR author and webhook sender
|
||
remain recorded separately.
|
||
</p>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-member-access">Company member access</Label>
|
||
<select
|
||
id="github-member-access"
|
||
className={githubSelectClass}
|
||
value={configuration.memberAccess}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...configuration,
|
||
memberAccess: e.target.value as "all_linked" | "selected",
|
||
})
|
||
}
|
||
>
|
||
<option value="all_linked">All linked company members</option>
|
||
<option value="selected">Only selected linked members</option>
|
||
</select>
|
||
<p className="text-xs text-muted-foreground">
|
||
Members connect their own GitHub account.{" "}
|
||
<Link
|
||
className="underline"
|
||
ref={accountLink}
|
||
to={`/apps/chat/connect?provider=github&resume=${endpointId}&stage=identity`}
|
||
>
|
||
Open account linking
|
||
</Link>
|
||
<Button
|
||
variant="link"
|
||
size="sm"
|
||
onClick={() => {
|
||
if (accountLink.current)
|
||
void copyTextToClipboard(accountLink.current.href).then(
|
||
() => setLinkCopied(true),
|
||
() =>
|
||
setError(
|
||
"Could not copy the link. Open account linking and copy the address.",
|
||
),
|
||
);
|
||
}}
|
||
>
|
||
{linkCopied ? "Link copied" : "Copy link for teammates"}
|
||
</Button>
|
||
.
|
||
</p>
|
||
</div>
|
||
<div className="space-y-3">
|
||
<h3 className="text-sm font-medium">Linked GitHub accounts</h3>
|
||
{links.isError && (
|
||
<p role="alert" className="text-sm text-destructive">
|
||
Could not load linked accounts.
|
||
</p>
|
||
)}
|
||
{(links.data ?? [])
|
||
.filter((link) => link.status === "linked")
|
||
.map((link) => (
|
||
<div
|
||
key={link.principalId}
|
||
className="flex items-center justify-between gap-3 rounded-lg border border-border p-3"
|
||
>
|
||
<p className="text-sm">
|
||
@{link.githubLogin ?? link.externalLabel}
|
||
</p>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
disabled={busy}
|
||
onClick={async () => {
|
||
setBusy(true);
|
||
setError("");
|
||
try {
|
||
await chatEndpointsApi.revokeLink(
|
||
endpointId,
|
||
link.principalId,
|
||
);
|
||
await links.refetch();
|
||
} catch (e) {
|
||
setError(
|
||
e instanceof Error
|
||
? e.message
|
||
: "Could not unlink this account.",
|
||
);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
>
|
||
Unlink account
|
||
</Button>
|
||
</div>
|
||
))}
|
||
{!links.isPending &&
|
||
!links.isError &&
|
||
!(links.data ?? []).some((link) => link.status === "linked") && (
|
||
<p className="text-sm text-muted-foreground">
|
||
No accounts linked yet. Each teammate confirms their own GitHub
|
||
identity.
|
||
</p>
|
||
)}
|
||
</div>
|
||
<div className="divide-y divide-border rounded-lg border border-border">
|
||
{configuration.people.length === 0 && (
|
||
<p className="p-4 text-sm text-muted-foreground">
|
||
No individual access entries. Unlinked people cannot invoke this
|
||
bot.
|
||
</p>
|
||
)}
|
||
{configuration.people.map((person) => (
|
||
<div key={person.githubUserId} className="space-y-2 p-4">
|
||
<div className="flex items-center justify-between gap-3">
|
||
<div>
|
||
<p className="text-sm font-medium">@{person.login}</p>
|
||
<p className="text-xs text-muted-foreground">
|
||
{person.kind === "member"
|
||
? "Linked company member"
|
||
: "External contributor · restricted guest permissions"}
|
||
</p>
|
||
</div>
|
||
<Button
|
||
variant="ghost"
|
||
size="sm"
|
||
onClick={() =>
|
||
onChange({
|
||
...configuration,
|
||
people: configuration.people.filter(
|
||
(p) => p.githubUserId !== person.githubUserId,
|
||
),
|
||
})
|
||
}
|
||
>
|
||
Remove
|
||
</Button>
|
||
</div>
|
||
<GitHubToggle
|
||
label={`Automatic PR reviews for @${person.login}`}
|
||
checked={person.automaticReviews}
|
||
onChange={(value) =>
|
||
onChange({
|
||
...configuration,
|
||
people: configuration.people.map((p) =>
|
||
p.githubUserId === person.githubUserId
|
||
? { ...p, automaticReviews: value }
|
||
: p,
|
||
),
|
||
})
|
||
}
|
||
/>
|
||
{person.kind === "guest" && (
|
||
<p className="text-xs text-muted-foreground">
|
||
Sponsor:{" "}
|
||
{activeMembers.find(
|
||
(member) => member.principalId === person.sponsorUserId,
|
||
)?.user?.name ?? person.sponsorUserId}
|
||
. No company membership or personal credentials are granted.
|
||
</p>
|
||
)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
<Button variant="outline" onClick={() => setKind("member")}>
|
||
Add linked member
|
||
</Button>
|
||
<Button variant="outline" onClick={() => setKind("guest")}>
|
||
Allow external contributor
|
||
</Button>
|
||
</div>
|
||
{kind === "member" && (
|
||
<div className="space-y-3 rounded-lg border border-border p-4">
|
||
<p className="text-sm">
|
||
Adding a member switches access to the selected-member list.
|
||
Automatic PR reviews start off.
|
||
</p>
|
||
{(links.data ?? [])
|
||
.filter((link) => link.status === "linked" && link.paperclipUserId)
|
||
.map((link) => (
|
||
<Button
|
||
className="mr-2"
|
||
key={link.id}
|
||
variant="outline"
|
||
disabled={configuration.people.some(
|
||
(p) =>
|
||
p.kind === "member" && p.userId === link.paperclipUserId,
|
||
)}
|
||
onClick={() => {
|
||
const id = link.githubUserId;
|
||
if (!id) {
|
||
setError(
|
||
"Refresh linked identities before adding this member.",
|
||
);
|
||
return;
|
||
}
|
||
add({
|
||
kind: "member",
|
||
userId: link.paperclipUserId!,
|
||
githubUserId: id,
|
||
login: link.githubLogin ?? link.externalLabel,
|
||
automaticReviews: false,
|
||
});
|
||
}}
|
||
>
|
||
{link.paperclipUserLabel ?? link.externalLabel}
|
||
</Button>
|
||
))}
|
||
<Button variant="ghost" onClick={() => setKind(null)}>
|
||
Cancel
|
||
</Button>
|
||
</div>
|
||
)}
|
||
{kind === "guest" && (
|
||
<div className="space-y-4 rounded-lg border border-border p-4">
|
||
<p className="text-sm">
|
||
Allow one GitHub account to mention the bot with restricted guest
|
||
permissions. A sponsor is required.
|
||
</p>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-guest-login">GitHub username</Label>
|
||
<div className="flex gap-2">
|
||
<Input
|
||
id="github-guest-login"
|
||
value={login}
|
||
onChange={(e) => {
|
||
setLogin(e.target.value);
|
||
setCandidate(null);
|
||
}}
|
||
/>
|
||
<Button
|
||
variant="outline"
|
||
disabled={busy || !login}
|
||
onClick={async () => {
|
||
setBusy(true);
|
||
setError("");
|
||
try {
|
||
setCandidate(await githubChatApi.lookup(endpointId, login));
|
||
} catch (error) {
|
||
setError(
|
||
error instanceof Error ? error.message : "Lookup failed",
|
||
);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
>
|
||
Look up
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Label htmlFor="github-guest-sponsor">Sponsor</Label>
|
||
<select
|
||
id="github-guest-sponsor"
|
||
className={githubSelectClass}
|
||
value={sponsor}
|
||
onChange={(e) => setSponsor(e.target.value)}
|
||
>
|
||
{activeMembers.map((member) => (
|
||
<option key={member.principalId} value={member.principalId}>
|
||
{member.user?.name ?? member.principalId}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
{candidate && (
|
||
<p className="text-sm">
|
||
@{candidate.login} · GitHub ID {candidate.githubUserId}
|
||
</p>
|
||
)}
|
||
<div className="flex justify-between">
|
||
<Button variant="ghost" onClick={() => setKind(null)}>
|
||
Cancel
|
||
</Button>
|
||
<Button
|
||
disabled={
|
||
!candidate ||
|
||
!sponsor ||
|
||
configuration.people.some(
|
||
(p) => p.githubUserId === candidate.githubUserId,
|
||
)
|
||
}
|
||
onClick={() =>
|
||
candidate &&
|
||
add({
|
||
...candidate,
|
||
kind: "guest",
|
||
sponsorUserId: sponsor,
|
||
permissionProfile: "restricted",
|
||
automaticReviews: false,
|
||
})
|
||
}
|
||
>
|
||
Allow this account
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
{(error || members.error || links.error) && (
|
||
<p role="alert" className="text-sm text-destructive">
|
||
{error ||
|
||
"Could not load members or linked accounts. Refresh to try again."}
|
||
</p>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|