flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/routes/repo/pull.tsx

1,206 lines49,658 bytesCodeBlame
1import { env } from "cloudflare:workers";
2import {
3 Bot,
4 ChevronRight,
5 FileDiff,
6 GitBranch,
7 GitCommitHorizontal,
8 CircleCheck,
9 CircleSlash,
10 GitMerge,
11 Layers,
12 GitPullRequestArrow,
13 Hand,
14 Loader,
15 Radar,
16 Sparkles,
17 MessageSquare,
18 ArrowUpRight,
19 MessagesSquare,
20 Rocket,
21 Network,
22 StickyNote,
23 User,
24 Wrench,
25} from "lucide-react";
26import { useEffect, useState } from "react";
27import { Form, Link, redirect, useRevalidator } from "react-router";
28
29import {
30 type Comparison,
31 type Deployment,
32 type LiveApp,
33 type SessionEntry,
34 type Viewer,
35 pullComparison,
36} from "@g1t/contracts";
37
38import type { Route } from "./+types/pull";
39import { excerpt, page } from "../../lib/meta";
40import { DiffView } from "../../components/diff-view";
41import { LifecyclePanel } from "../../components/lifecycle";
42import { Markdown } from "../../components/markdown";
43import {
44 Avatar,
45 Button,
46 ButtonLink,
47 CopyLine,
48 EmptyState,
49 ErrorText,
50 Textarea,
51 TimeAgo,
52} from "../../components/ui";
53import { CheckboxOption } from "../../components/ui/checkbox";
54import { WorkflowStatuses } from "../../components/actions";
55import { ChecksPanel } from "../../components/checks";
56import {
57 CommentForm,
58 CommentList,
59 IssueIcon,
60 PeoplePicker,
61 PullState,
62 TimelineItem,
63 verdicts,
64} from "../../components/work";
65import { deployments, identity, projects, repos, work } from "../../lib/services.server";
66import { assertSameOrigin, getViewer, requireUser } from "../../lib/session.server";
67
68const REFRESH_MS = 4000;
69const EMPTY_COMPARISON: Comparison = { base: null, head: "", files: [], truncated: false };
70const TABS = ["conversation", "session", "changes"] as const;
71type Tab = (typeof TABS)[number];
72
73export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
74 const pull = loaderData?.pull;
75 const title = pull ? `${pull.title} · Pull request #${pull.number} · ` : "";
76 const state = { draft: "Draft", open: "Open", merged: "Merged", closed: "Closed" }[pull?.status ?? "open"];
77 const body = excerpt(pull?.body);
78 return page(args, {
79 title: `${title}${params.owner}/${params.repo} · g1t`,
80 description: pull
81 ? `${state} pull request #${pull.number} on ${params.owner}/${params.repo} by ${pull.author.username}.${body ? ` ${body}` : ""}`
82 : null,
83 // The card shows the title and the state.
84 version: pull ? [pull.title, pull.status] : undefined,
85 type: "article",
86 });
87}
88
89export async function loader({ params, context, request }: Route.LoaderArgs) {
90 const viewer = getViewer(context);
91 const path = { namespace: params.owner, name: params.repo };
92 const number = Number(params.number);
93 const asked = new URL(request.url).searchParams.get("tab");
94 const tab: Tab = TABS.find((name) => name === asked) ?? "conversation";
95
96 const member = (viewer?.workspaces ?? []).some(
97 (membership) => membership.slug === params.owner,
98 );
99 // At once: none of these depends on another.
100 const ref = { workspace: params.owner, slug: params.repo };
101 const [found, repo, settings, agentsEnabled, members, deps, deployed] = await Promise.all([
102 work.getPull(path, number, viewer),
103 repos.get(path, viewer),
104 work.getSettings(path, viewer),
105 env.RUNNER.enabled(viewer, path),
106 // A member picks reviewers and assignees from the workspace's people.
107 member ? identity.listMembers(params.owner, viewer) : null,
108 // The projects that use this one: what a change here can affect.
109 projects.dependencies(params.owner, params.repo, viewer),
110 member ? deployments.list(ref, viewer) : null,
111 ]);
112 if (!found.ok) {
113 // Issues and pull requests share numbers; this one may be an issue.
114 const issue = await work.getIssue(path, number, viewer);
115 if (issue.ok) throw redirect(`/${params.owner}/${params.repo}/issues/${number}`);
116 throw new Response("Pull request not found.", { status: 404 });
117 }
118 const { pull } = found.value;
119 const range = pullComparison(pull);
120 const [session, comparison] = await Promise.all([
121 tab === "session" ? work.readSession(path, number, viewer) : null,
122 tab === "changes"
123 ? repos.compare(range.repoId, viewer, range.base, range.head)
124 : null,
125 ]);
126 return {
127 ...found.value,
128 tab,
129 session: session?.ok ? session.value : [],
130 // An empty comparison if it could not be made.
131 comparison: comparison && (comparison.ok ? comparison.value : EMPTY_COMPARISON),
132 viewer,
133 // Members of the repository's workspace can merge.
134 canMerge: member,
135 canManage: member || viewer?.id === pull.author.id,
136 // A catch-up is pushed as the viewer: a fork takes pushes only from
137 // whoever opened it, a branch from any member.
138 canUpdate: pull.fork ? viewer?.id === pull.author.id : member,
139 agentsEnabled,
140 members: members?.ok ? members.value.map((person) => person.username) : [],
141 requireUpToDate: settings.ok && settings.value.requireUpToDate,
142 mergeQueue: settings.ok && settings.value.mergeQueue,
143 requiredApprovals: settings.ok ? settings.value.requiredApprovals : 0,
144 canIgnoreChecks: !settings.ok || settings.value.allowIgnoringChecks,
145 defaultBranch: repo.ok ? repo.value.defaultBranch : "main",
146 affects: deps.ok ? deps.value.usedBy : [],
147 ...(await deploymentOf(deployed?.ok ? deployed.value : null, number, params.owner, deps.ok ? deps.value.usedBy : [], viewer)),
148 };
149}
150
151/**
152 * Where this pull request is live: its preview (or its latest build, while
153 * one is going or after one failed), and the previews of the projects
154 * that use this one, built against it.
155 */
156async function deploymentOf(
157 list: { deployments: Deployment[]; live: LiveApp[] } | null,
158 number: number,
159 owner: string,
160 affects: { slug: string; name: string }[],
161 viewer: Viewer,
162) {
163 if (!list) return { preview: null, build: null, stacked: [] };
164 const preview = list.live.find((app) => app.kind === "preview" && app.number === number) ?? null;
165 const build = list.deployments.find((d) => d.kind === "preview" && d.number === number) ?? null;
166 const branch = preview?.branch ?? build?.branch ?? null;
167 const stacked = branch
168 ? (
169 await Promise.all(
170 affects.slice(0, 5).map(async (project) => {
171 const theirs = await deployments.list({ workspace: owner, slug: project.slug }, viewer);
172 const app = theirs.ok ? theirs.value.live.find((a) => a.kind === "preview" && a.branch === branch) : undefined;
173 return app ? { name: project.name, slug: project.slug, url: app.url } : null;
174 }),
175 )
176 ).filter((entry) => entry != null)
177 : [];
178 return { preview, build, stacked };
179}
180
181export async function action({ request, params, context }: Route.ActionArgs) {
182 assertSameOrigin(request);
183 const user = requireUser(context, request);
184 const form = await request.formData();
185 const path = { namespace: params.owner, name: params.repo };
186 const number = Number(params.number);
187 const action = form.get("action");
188 const verdict = form.get("verdict");
189 const line = Number(form.get("line"));
190 /** Names ticked in a people picker, plus those typed beside it. */
191 const picked = (field: string) => [
192 ...form.getAll(field).map(String),
193 ...String(form.get("others") ?? "").split(/[\s,]+/),
194 ];
195 // The projects that use this one, built against this pull request's preview.
196 if (action === "stack") {
197 const built = await deployments.stack(user, { workspace: params.owner, slug: params.repo }, String(form.get("branch") ?? ""));
198 return built.ok
199 ? { action, notice: `Building ${built.value.join(", ")} against this preview. They appear on their Deployments pages.` }
200 : { action, error: built.error.message };
201 }
202 // Asking a g1t agent for its review records the request, then starts it.
203 if (action === "agent-review") {
204 const asked = await work.updatePull(user, path, number, {
205 reviewers: [...form.getAll("reviewer").map(String), "g1t-agent"],
206 });
207 if (!asked.ok) return { error: asked.error.message, action };
208 }
209 const result =
210 action === "merge"
211 ? await work.mergePull(user, path, number, {
212 keepIssueOpen: form.get("keepIssueOpen") === "on",
213 ignoreChecks: form.get("ignoreChecks") === "on",
214 })
215 : action === "unqueue"
216 ? await work.removeFromQueue(user, path, number)
217 : action === "message"
218 ? await work.messageAgent(user, path, number, String(form.get("body") ?? ""))
219 : action === "close"
220 ? await work.closePull(user, path, number)
221 : action === "recheck"
222 ? await env.RUNNER.recheck(user, path, number)
223 : action === "update"
224 ? await env.RUNNER.update(user, path, number)
225 : action === "agent-review"
226 ? await env.RUNNER.review(user, path, number)
227 : action === "reviewers"
228 ? await work.updatePull(user, path, number, { reviewers: picked("reviewer") })
229 : action === "assign"
230 ? await work.updatePull(user, path, number, { assignees: picked("assignee") })
231 : action === "comment"
232 ? await work.addComment(user, path, number, {
233 body: String(form.get("body") ?? ""),
234 path: String(form.get("path") ?? "") || undefined,
235 line: line > 0 ? line : undefined,
236 verdict:
237 verdict === "approve" || verdict === "request_changes" ? verdict : undefined,
238 })
239 : await work.readyPull(user, path, number, String(form.get("summary") ?? ""));
240 return result.ok ? null : { error: result.error.message, action };
241}
242
243function TabLink({
244 to,
245 active,
246 children,
247}: {
248 to: string;
249 active: boolean;
250 children: React.ReactNode;
251}) {
252 return (
253 <Link
254 to={to}
255 preventScrollReset
256 className={
257 "-mb-px flex items-center gap-2 border-b-2 px-1 pb-2.5 text-sm transition-colors " +
258 (active
259 ? "border-accent font-medium text-fg"
260 : "border-transparent text-muted hover:text-fg")
261 }
262 >
263 {children}
264 </Link>
265 );
266}
267
268/** One step of the session, on the timeline's rail. */
269function Entry({ entry, agent }: { entry: SessionEntry; agent: string }) {
270 const isTool = entry.kind === "tool_call" || entry.kind === "tool_result";
271 const Icon =
272 entry.kind === "prompt"
273 ? User
274 : entry.kind === "note"
275 ? StickyNote
276 : isTool
277 ? Wrench
278 : Bot;
279 return (
280 <li className="relative pl-10">
281 <span
282 className={`absolute top-0.5 left-0 flex size-7 items-center justify-center rounded-full border bg-bg ${
283 entry.kind === "prompt"
284 ? "border-accent/50 text-accent"
285 : "border-line text-faint"
286 }`}
287 >
288 <Icon size={14} />
289 </span>
290 {isTool ? (
291 <details className="group rounded-lg border border-line bg-surface">
292 <summary className="flex cursor-pointer list-none items-center gap-2 px-3 py-1.5 text-sm">
293 <ChevronRight
294 size={14}
295 className="text-faint transition-transform group-open:rotate-90"
296 />
297 <span className="font-mono text-xs text-accent">
298 {entry.tool ?? "tool"}
299 </span>
300 <span className="truncate font-mono text-xs text-muted">
301 {entry.kind === "tool_result" ? "→ " : ""}
302 {entry.text.split("\n")[0]}
303 </span>
304 </summary>
305 <pre className="overflow-x-auto border-t border-line p-3 font-mono text-xs whitespace-pre-wrap text-muted">
306 <code>{entry.text}</code>
307 </pre>
308 </details>
309 ) : (
310 <div>
311 <p className="text-xs font-medium text-faint">
312 {entry.kind === "prompt"
313 ? "Prompt"
314 : entry.kind === "note"
315 ? "Note"
316 : agent}
317 </p>
318 {entry.kind === "message" ? (
319 <div className="mt-1">
320 <Markdown source={entry.text} />
321 </div>
322 ) : entry.kind === "prompt" ? (
323 <div className="mt-1.5 max-h-[32rem] overflow-y-auto rounded-xl border border-line bg-surface p-4">
324 <Markdown source={entry.text} />
325 </div>
326 ) : (
327 <p className="mt-1 text-[0.9375rem] leading-relaxed wrap-break-word whitespace-pre-wrap">
328 {entry.text}
329 </p>
330 )}
331 </div>
332 )}
333 {entry.commit && (
334 <p className="mt-1.5 flex items-center gap-1 font-mono text-xs text-faint">
335 <GitCommitHorizontal size={12} />
336 {entry.commit.slice(0, 7)}
337 </p>
338 )}
339 </li>
340 );
341}
342
343/** The box at the foot of the conversation saying what stands before a merge. */
344function StatusBox({ children }: { children: React.ReactNode }) {
345 return (
346 <div className="flex gap-3">
347 <span className="hidden w-8 shrink-0 sm:block" />
348 <section className="min-w-0 grow divide-y divide-line overflow-hidden rounded-xl border border-line-strong bg-surface">
349 {children}
350 </section>
351 </div>
352 );
353}
354
355function StatusRow({
356 icon,
357 title,
358 children,
359}: {
360 icon: React.ReactNode;
361 title: string;
362 children?: React.ReactNode;
363}) {
364 return (
365 <div className="flex gap-3 px-4 py-3 text-sm">
366 <span className="mt-0.5 shrink-0">{icon}</span>
367 <div className="min-w-0">
368 <p className="font-medium">{title}</p>
369 {children && <div className="mt-0.5 text-muted">{children}</div>}
370 </div>
371 </div>
372 );
373}
374
375export default function PullPage({ loaderData, actionData, params }: Route.ComponentProps) {
376 const {
377 pull,
378 issue,
379 comments,
380 checks,
381 overlaps,
382 behind,
383 reviewPending,
384 lifecycle,
385 messages,
386 statuses = [],
387 affects,
388 preview,
389 build,
390 stacked,
391 landing,
392 stalled,
393 requireUpToDate,
394 mergeQueue,
395 requiredApprovals,
396 canIgnoreChecks,
397 canUpdate,
398 agentsEnabled,
399 members,
400 tab,
401 session,
402 comparison,
403 viewer,
404 canMerge,
405 canManage,
406 defaultBranch,
407 } = loaderData;
408 const base = `/${params.owner}/${params.repo}`;
409 const here = `${base}/pull/${pull.number}`;
410 const remote = pull.fork
411 ? `https://g1t.sh/${pull.fork.namespace}/${pull.fork.name}.git`
412 : `https://g1t.sh/${params.owner}/${params.repo}.git`;
413 const active = pull.status === "draft" || pull.status === "open";
414
415 // Follow an agent at work, or checks in progress, without a manual reload.
416 const revalidator = useRevalidator();
417 const working = pull.status === "draft";
418 const checking =
419 checks?.status === "queued" || checks?.status === "running" || statuses.some((status) => status.state === "pending");
420 const reviews = verdicts(comments);
421 // What stands between this pull request and a merge, if anything.
422 const unchecked = checks && checks.status !== "passed";
423 // Pull requests for other issues changing the same files will conflict;
424 // ones for the same issue are alternatives, and expected to.
425 const collisions = overlaps.filter((other) => other.issue == null || other.issue !== pull.issue);
426 const review = {
427 changesUrl: here + "?tab=changes",
428 // Nobody reviews their own pull request.
429 canJudge: active && viewer != null && viewer.id !== pull.author.id,
430 };
431 // Everyone whose review was asked for, then anyone who reviewed unasked.
432 const reviewerNames = [
433 ...new Set([...pull.reviewers, ...reviews.map(({ reviewer }) => reviewer)]),
434 ];
435 const [submitted, setSubmitted] = useState<string | null>(null);
436 const catchingUp = submitted === "update" && behind;
437 // g1t is taking a step of its own accord, so the page will change.
438 const moving =
439 lifecycle != null && lifecycle.stage !== "ready" && lifecycle.stage !== "needs_you";
440 useEffect(() => {
441 if (!working && !checking && !reviewPending && !catchingUp && !moving && !landing) return;
442 const timer = setInterval(() => {
443 if (document.visibilityState === "visible") revalidator.revalidate();
444 }, REFRESH_MS);
445 return () => clearInterval(timer);
446 }, [working, checking, reviewPending, catchingUp, moving, landing, revalidator]);
447
448 return (
449 // The changes get the whole width; people and settings are a tab away.
450 <div className={`grid gap-8 ${tab === "changes" ? "" : "lg:grid-cols-[1fr_19rem]"}`}>
451 <div className="min-w-0">
452 <h2 className="text-2xl font-semibold tracking-tight text-balance">
453 {pull.title} <span className="font-normal text-faint">#{pull.number}</span>
454 </h2>
455 <div className="mt-3 flex flex-wrap items-center gap-x-3 gap-y-2 text-sm text-muted">
456 <PullState status={pull.status} />
457 <span className="flex items-center gap-2">
458 <Avatar
459 name={(pull.status === "merged" && pull.mergedBy) || pull.author.username}
460 size={18}
461 />
462 <span>
463 <span className="font-medium text-fg">
464 {(pull.status === "merged" && pull.mergedBy) || pull.author.username}
465 </span>{" "}
466 {pull.status === "merged" ? "merged" : "wants to merge"}
467 {pull.branch && (
468 <>
469 {" "}
470 <span className="font-mono text-fg">{pull.branch}</span>
471 </>
472 )}{" "}
473 into <span className="font-mono text-fg">{defaultBranch}</span>
474 </span>
475 </span>
476 {/* A pull request from a branch was made by its author, not an agent. */}
477 {!pull.branch && (
478 <span className="flex items-center gap-1.5 font-mono text-xs">
479 <Bot size={14} />
480 {pull.agent}
481 {pull.runtime === "hosted" && <span className="text-faint">on g1t</span>}
482 </span>
483 )}
484 </div>
485
486 {reviews.length > 0 && (
487 <p className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
488 {reviews.map(({ reviewer, verdict }) => (
489 <span
490 key={reviewer}
491 className={`flex items-center gap-1.5 ${
492 verdict === "approve" ? "text-accent" : "text-danger"
493 }`}
494 >
495 {verdict === "approve" ? <CircleCheck size={15} /> : <CircleSlash size={15} />}
496 {verdict === "approve" ? "Approved by" : "Changes requested by"}{" "}
497 <span className="font-medium">{reviewer}</span>
498 </span>
499 ))}
500 </p>
501 )}
502
503 {lifecycle && <LifecyclePanel lifecycle={lifecycle} />}
504
505 {/* Steering: while its agent works, people can tell it things. */}
506 {canManage &&
507 pull.runtime === "hosted" &&
508 (working || ["working", "revising", "catching_up", "answering"].includes(lifecycle?.stage ?? "")) && (
509 <Form method="post" className="mt-4 rounded-2xl bg-surface p-4 ring-1 ring-merged/30">
510 <p className="flex items-center gap-2 text-sm font-medium">
511 <Sparkles size={15} className="text-merged" />
512 Message the agent
513 </p>
514 <p className="mt-1 text-xs text-muted">
515 A correction, a hint, a change of plan. It reads it at its next step, without
516 starting over.
517 </p>
518 <div className="mt-3 flex gap-2">
519 <input type="hidden" name="action" value="message" />
520 <input
521 name="body"
522 required
523 autoComplete="off"
524 data-1p-ignore
525 placeholder="Keep the old flag working too…"
526 className="h-9 min-w-0 grow rounded-md bg-bg px-3 text-sm ring-1 ring-line outline-none placeholder:text-faint focus:ring-merged/60"
527 />
528 <Button type="submit">Send</Button>
529 </div>
530 </Form>
531 )}
532 {messages.length > 0 && (
533 <ul className="mt-3 space-y-1.5">
534 {messages.map((message) => (
535 <li key={message.id} className="flex items-start gap-2 text-sm">
536 <Avatar name={message.author} size={18} />
537 <span className="min-w-0 grow">
538 <span className="font-medium">
539 {message.fromNumber != null ? `The agent on #${message.fromNumber}` : message.author}
540 </span>{" "}
541 <span className="text-muted">
542 {message.kind === "question"
543 ? "asked:"
544 : message.kind === "handoff"
545 ? "handed over:"
546 : message.kind === "answer"
547 ? "answered:"
548 : "to the agent:"}
549 </span>{" "}
550 {message.body}
551 {message.answer && (
552 <span className="mt-1 block border-l-2 border-merged/40 pl-2 text-muted">
553 {message.declined ? "Declined: " : "Answer: "}
554 {message.answer}
555 </span>
556 )}
557 </span>
558 <span className={`shrink-0 text-xs ${message.deliveredAt ? "text-accent" : "text-faint"}`}>
559 {message.deliveredAt ? "read by the agent" : "waiting for its next step"}
560 </span>
561 </li>
562 ))}
563 </ul>
564 )}
565
566 {issue && (
567 <Link
568 to={`${base}/issues/${issue.number}`}
569 className="mt-4 flex items-center gap-2.5 rounded-xl border border-line bg-surface px-4 py-2.5 text-sm transition-colors hover:border-line-strong"
570 >
571 <IssueIcon issue={issue} />
572 <span className="text-muted">
573 {pull.status === "merged" && issue.resolvedBy === pull.number
574 ? "Resolved"
575 : "For issue"}
576 </span>
577 <span className="truncate font-medium">{issue.title}</span>
578 <span className="text-faint">#{issue.number}</span>
579 {issue.pullCount > 1 && (
580 <span className="ml-auto shrink-0 text-xs text-faint">
581 1 of {issue.pullCount} pull requests
582 </span>
583 )}
584 </Link>
585 )}
586
587 {pull.status === "merged" && (
588 <p className="mt-4 flex items-center gap-2.5 rounded-xl border border-merged/40 bg-merged/5 px-4 py-2.5 text-sm">
589 <GitMerge size={16} className="shrink-0 text-merged" />
590 <span>
591 Merged into <span className="font-mono">{defaultBranch}</span> by{" "}
592 <span className="font-medium">{pull.mergedBy}</span>{" "}
593 {/* Not an account: the repository's settings said to merge it. */}
594 {pull.mergedBy === "g1t" && "automatically, once it was ready, "}
595 {pull.mergedAt && <TimeAgo at={pull.mergedAt} />}
596 {pull.headCommit && (
597 <span className="font-mono text-muted"> · {pull.headCommit.slice(0, 7)}</span>
598 )}
599 </span>
600 </p>
601 )}
602 {pull.supersededBy != null && (
603 <p className="mt-4 rounded-xl border border-line bg-surface px-4 py-2.5 text-sm text-muted">
604 Closed because{" "}
605 <Link
606 to={`${base}/pull/${pull.supersededBy}`}
607 className="font-medium text-fg hover:underline"
608 >
609 #{pull.supersededBy}
610 </Link>{" "}
611 was merged for this issue instead.
612 </p>
613 )}
614
615 {collisions.length > 0 && active && (
616 <div className="mt-4 rounded-xl border border-line bg-surface px-4 py-3 text-sm">
617 <p className="flex items-center gap-2.5 font-medium">
618 <Radar size={16} className="shrink-0 text-info" />
619 Other work is changing the same files
620 </p>
621 <ul className="mt-2 space-y-1.5">
622 {collisions.map((other) => (
623 <li key={other.number} className="flex flex-wrap items-baseline gap-x-2 text-muted">
624 <Link
625 to={`${base}/pull/${other.number}`}
626 className="font-medium text-fg hover:underline"
627 >
628 {other.title} <span className="font-normal text-faint">#{other.number}</span>
629 </Link>
630 <span className="font-mono text-xs">{other.paths.join(", ")}</span>
631 </li>
632 ))}
633 </ul>
634 <p className="mt-2 text-xs text-faint">
635 Whichever merges second will have to catch up, and may conflict.
636 </p>
637 </div>
638 )}
639
640 <nav className="mt-8 flex gap-6 border-b border-line">
641 <TabLink to={here} active={tab === "conversation"}>
642 <MessageSquare size={15} />
643 Conversation
644 </TabLink>
645 <TabLink to={here + "?tab=session"} active={tab === "session"}>
646 <MessagesSquare size={15} />
647 Session
648 </TabLink>
649 <TabLink to={here + "?tab=changes"} active={tab === "changes"}>
650 <FileDiff size={15} />
651 Changes
652 </TabLink>
653 </nav>
654 <div className="mt-5">
655 {comparison ? (
656 <DiffView
657 comparison={comparison}
658 review={{
659 comments: comments.filter((comment) => comment.path),
660 canComment: Boolean(viewer),
661 }}
662 />
663 ) : tab === "session" ? (
664 session.length === 0 ? (
665 <EmptyState title="Nothing recorded yet">
666 The agent's prompts, reasoning and tool calls appear here as it
667 works.
668 </EmptyState>
669 ) : (
670 <ol className="relative space-y-5 before:absolute before:top-2 before:bottom-2 before:left-3.25 before:w-px before:bg-line">
671 {session.map((entry) => (
672 <Entry key={entry.seq} entry={entry} agent={pull.agent} />
673 ))}
674 </ol>
675 )
676 ) : (
677 <div className="space-y-4">
678 <TimelineItem
679 author={pull.author.username}
680 at={pull.createdAt}
681 action={
682 <span>
683 opened this pull request
684 {!pull.branch && (
685 <>
686 {" "}
687 with <span className="font-mono text-xs">{pull.agent}</span>
688 </>
689 )}
690 </span>
691 }
692 >
693 {pull.body ? (
694 <Markdown source={pull.body} repo={{ namespace: params.owner, name: params.repo }} />
695 ) : (
696 <p className="text-sm text-muted">
697 {working
698 ? "No description yet. It is written when the pull request is marked ready for review."
699 : "No description."}
700 </p>
701 )}
702 {canManage && pull.status === "open" && (
703 <details className="mt-3 border-t border-line pt-3 text-sm">
704 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
705 Edit description
706 </summary>
707 <Form method="post" className="mt-3 space-y-2">
708 <Textarea
709 name="summary"
710 rows={6}
711 placeholder="What changed and why"
712 defaultValue={pull.body ?? ""}
713 />
714 <Button type="submit">Save</Button>
715 </Form>
716 </details>
717 )}
718 </TimelineItem>
719
720 <CommentList comments={comments} review={review} base={base} />
721
722 {(preview || build) && (
723 <DeploymentCard preview={preview} build={build} stacked={stacked} base={base} />
724 )}
725
726 {pull.status === "draft" && (
727 <StatusBox>
728 <StatusRow icon={<Loader size={16} className="text-faint" />} title="This is a draft">
729 It is still being worked on. It can be reviewed and merged once it is
730 marked ready.
731 </StatusRow>
732 {canManage && (
733 <Form method="post" className="space-y-2 px-4 py-3">
734 <Textarea name="summary" rows={3} placeholder="What changed and why" />
735 <Button type="submit">Mark ready for review</Button>
736 </Form>
737 )}
738 </StatusBox>
739 )}
740
741 {pull.status === "open" && (
742 <StatusBox>
743 {checks && (
744 <StatusRow
745 icon={
746 checks.status === "passed" ? (
747 <CircleCheck size={16} className="text-accent" />
748 ) : checking ? (
749 <Loader size={16} className="animate-spin text-faint" />
750 ) : (
751 <CircleSlash size={16} className="text-danger" />
752 )
753 }
754 title={
755 checks.status === "passed"
756 ? "Acceptance checks passed"
757 : checking
758 ? "Acceptance checks are running"
759 : checks.status === "failed"
760 ? "Acceptance checks failed"
761 : "Acceptance checks could not be run"
762 }
763 >
764 {checks.results.length > 0 &&
765 `${checks.results.filter((result) => result.passed).length} of ${checks.results.length} passed, in a clean sandbox.`}
766 </StatusRow>
767 )}
768 <StatusRow
769 icon={
770 reviews.some(({ verdict }) => verdict === "request_changes") ? (
771 <CircleSlash size={16} className="text-danger" />
772 ) : reviews.length > 0 ? (
773 <CircleCheck size={16} className="text-accent" />
774 ) : (
775 <MessageSquare size={16} className="text-faint" />
776 )
777 }
778 title={
779 reviews.length === 0
780 ? "No reviews yet"
781 : reviews
782 .map(
783 ({ reviewer, verdict }) =>
784 `${verdict === "approve" ? "Approved by" : "Changes requested by"} ${reviewer}`,
785 )
786 .join(" · ")
787 }
788 >
789 {reviewPending && "A g1t agent is reviewing it now. "}
790 {requiredApprovals > 0 &&
791 `This repository requires ${requiredApprovals} approving ${
792 requiredApprovals === 1 ? "review" : "reviews"
793 } before merging.`}
794 </StatusRow>
795 {landing ? (
796 <StatusRow
797 icon={<Loader size={16} className="animate-spin text-accent" />}
798 title="Merging"
799 >
800 {defaultBranch} has moved, so g1t is bringing this up to date first. It
801 lands as soon as that is done. Watch it in the Session tab.
802 </StatusRow>
803 ) : behind ? (
804 <StatusRow
805 icon={<GitPullRequestArrow size={16} className="text-info" />}
806 title={`${defaultBranch} has moved since this was made`}
807 >
808 {requireUpToDate
809 ? "This repository requires pull requests to be up to date, so it has to catch up before it can merge."
810 : "That does not stop it merging: it is brought up to date as part of the merge."}
811 {canUpdate && agentsEnabled && (
812 <Form
813 method="post"
814 className="mt-2"
815 onSubmit={() => setSubmitted("update")}
816 >
817 <input type="hidden" name="action" value="update" />
818 <Button variant="quiet" type="submit" disabled={catchingUp}>
819 {catchingUp ? "Catching up…" : `Catch up with ${defaultBranch} now`}
820 </Button>
821 </Form>
822 )}
823 {actionData?.action === "update" && (
824 <ErrorText>{actionData.error}</ErrorText>
825 )}
826 </StatusRow>
827 ) : (
828 pull.headCommit && (
829 <StatusRow
830 icon={<CircleCheck size={16} className="text-accent" />}
831 title={`Up to date with ${defaultBranch}`}
832 />
833 )
834 )}
835 {stalled && !lifecycle && (
836 <StatusRow icon={<Hand size={16} className="text-warn" />} title="Needs you">
837 {stalled}
838 </StatusRow>
839 )}
840 {canMerge && lifecycle?.stage === "queued" && (
841 <Form method="post" className="flex flex-wrap items-center gap-3 px-4 py-3">
842 <ButtonLink to={`${base}/queue`}>
843 <Layers size={15} />
844 See the queue
845 </ButtonLink>
846 <Button variant="quiet" type="submit" name="action" value="unqueue">
847 Remove from the queue
848 </Button>
849 </Form>
850 )}
851 {canMerge && !landing && lifecycle?.stage !== "queued" && (
852 <Form method="post" className="space-y-3 px-4 py-3">
853 {issue?.state === "open" && (
854 <CheckboxOption
855 name="keepIssueOpen"
856 label={`Keep #${issue.number} open. This is only part of the work.`}
857 labelClassName="text-xs text-muted"
858 />
859 )}
860 {unchecked && canIgnoreChecks && (
861 <CheckboxOption
862 name="ignoreChecks"
863 label={`Merge although the checks ${checking ? "have not finished" : "did not pass"}.`}
864 labelClassName="text-xs text-muted"
865 />
866 )}
867 <div className="flex flex-wrap items-center gap-3">
868 <Button
869 variant="accent"
870 type="submit"
871 name="action"
872 value="merge"
873 disabled={behind && requireUpToDate}
874 >
875 {mergeQueue ? <Layers size={15} /> : <GitMerge size={15} />}
876 {mergeQueue ? "Add to the merge queue" : `Merge into ${defaultBranch}`}
877 </Button>
878 <span className="text-xs text-muted">
879 {mergeQueue
880 ? `Tested together with everything ahead of it, then lands on ${defaultBranch}.`
881 : issue?.state === "open"
882 ? `Closes issue #${issue.number}, and any other pull requests still open for it.`
883 : `Lands its commits on ${defaultBranch}.`}
884 </span>
885 </div>
886 {actionData?.action === "merge" && (
887 <ErrorText>{actionData.error}</ErrorText>
888 )}
889 </Form>
890 )}
891 </StatusBox>
892 )}
893
894 <CommentForm
895 author={viewer?.username ?? null}
896 resetKey={comments.length}
897 review={review}
898 />
899 {canManage && active && (
900 <Form method="post" className="flex justify-end">
901 <Button variant="quiet" type="submit" name="action" value="close">
902 Close pull request
903 </Button>
904 </Form>
905 )}
906 {actionData &&
907 !["merge", "comment", "recheck", "update", "agent-review", "reviewers", "assign"].includes(
908 String(actionData.action),
909 ) && <ErrorText>{actionData.error}</ErrorText>}
910 </div>
911 )}
912 {actionData?.action === "comment" && (
913 <div className="mt-2">
914 <ErrorText>{actionData.error}</ErrorText>
915 </div>
916 )}
917 </div>
918 </div>
919
920 <aside className={tab === "changes" ? "hidden" : "space-y-6"}>
921 <ChecksPanel
922 run={checks}
923 commands={issue?.checks ?? []}
924 canRerun={canManage && pull.status === "open"}
925 />
926 {actionData?.action === "recheck" && <ErrorText>{actionData.error}</ErrorText>}
927 <WorkflowStatuses statuses={statuses} />
928 {affects.length > 0 && (
929 <section>
930 <h3 className="flex items-center gap-1.5 text-sm font-medium">
931 <Network size={14} className="text-faint" />
932 Affects
933 </h3>
934 <p className="mt-1 text-xs text-muted">Projects that use this one, and so may feel this change:</p>
935 <ul className="mt-2 space-y-1 text-sm">
936 {affects.map((project) => (
937 <li key={project.slug} className="flex items-center justify-between gap-2">
938 <Link to={`/${params.owner}/${project.slug}`} className="hover:underline">
939 {project.name}
940 </Link>
941 {project.as && <code className="font-mono text-xs text-faint">{project.as}</code>}
942 </li>
943 ))}
944 </ul>
945 {preview?.branch && canMerge && (
946 <Form method="post" className="mt-3">
947 <input type="hidden" name="action" value="stack" />
948 <input type="hidden" name="branch" value={preview.branch} />
949 <button
950 type="submit"
951 className="w-full rounded-md border border-line px-3 py-1.5 text-xs text-muted transition-colors hover:border-line-strong hover:text-fg"
952 >
953 Preview them against this change
954 </button>
955 </Form>
956 )}
957 {actionData?.action === "stack" &&
958 ("notice" in actionData ? (
959 <p className="mt-2 text-xs text-accent">{String(actionData.notice)}</p>
960 ) : (
961 <ErrorText>{actionData.error}</ErrorText>
962 ))}
963 </section>
964 )}
965
966 <section>
967 <h3 className="text-sm font-medium">Reviewers</h3>
968 <ul className="mt-2 space-y-1.5 text-sm">
969 {reviewerNames.map((name) => {
970 const verdict = reviews.find(({ reviewer }) => reviewer === name)?.verdict;
971 const pending = name === "g1t-agent" && reviewPending;
972 return (
973 <li key={name} className="flex items-center gap-2 px-1">
974 {name === "g1t-agent" ? (
975 <Sparkles size={16} className="shrink-0 text-accent" />
976 ) : (
977 <Avatar name={name} size={20} />
978 )}
979 <span className="grow truncate font-mono text-xs">{name}</span>
980 {pending ? (
981 <span className="flex items-center gap-1.5 text-xs text-muted">
982 <span className="size-1.5 animate-pulse rounded-full bg-accent" />
983 Reviewing
984 </span>
985 ) : verdict === "approve" ? (
986 <span className="flex items-center gap-1 text-xs text-accent">
987 <CircleCheck size={13} /> Approved
988 </span>
989 ) : verdict === "request_changes" ? (
990 <span className="flex items-center gap-1 text-xs text-danger">
991 <CircleSlash size={13} /> Changes requested
992 </span>
993 ) : (
994 <span className="text-xs text-faint">Review requested</span>
995 )}
996 </li>
997 );
998 })}
999 {reviewerNames.length === 0 && (
1000 <li className="px-1 text-xs text-faint">No reviews requested yet.</li>
1001 )}
1002 </ul>
1003 {pull.status === "open" && canManage && (
1004 <div className="mt-3 space-y-2">
1005 {agentsEnabled && !reviewPending && (
1006 <Form method="post">
1007 <input type="hidden" name="action" value="agent-review" />
1008 {pull.reviewers.map((name) => (
1009 <input key={name} type="hidden" name="reviewer" value={name} />
1010 ))}
1011 <div className="*:w-full">
1012 <Button variant="quiet" type="submit">
1013 <Sparkles size={14} className="text-accent" />
1014 Request review from g1t agent
1015 </Button>
1016 </div>
1017 </Form>
1018 )}
1019 <details>
1020 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
1021 Request review from people
1022 </summary>
1023 <Form method="post" className="mt-2 space-y-2" key={pull.reviewers.join()}>
1024 <input type="hidden" name="action" value="reviewers" />
1025 {pull.reviewers.includes("g1t-agent") && (
1026 <input type="hidden" name="reviewer" value="g1t-agent" />
1027 )}
1028 <PeoplePicker
1029 name="reviewer"
1030 members={members.filter((name) => name !== pull.author.username)}
1031 chosen={pull.reviewers.filter((name) => name !== "g1t-agent")}
1032 />
1033 <Button variant="quiet" type="submit">
1034 Save reviewers
1035 </Button>
1036 </Form>
1037 </details>
1038 </div>
1039 )}
1040 {["agent-review", "reviewers"].includes(String(actionData?.action)) && (
1041 <ErrorText>{actionData?.error}</ErrorText>
1042 )}
1043 </section>
1044
1045 <section>
1046 <h3 className="text-sm font-medium">Assignees</h3>
1047 <ul className="mt-2 space-y-1.5 text-sm">
1048 {pull.assignees.map((name) => (
1049 <li key={name} className="flex items-center gap-2 px-1">
1050 <Avatar name={name} size={20} />
1051 <span className="grow truncate font-mono text-xs">{name}</span>
1052 </li>
1053 ))}
1054 {pull.assignees.length === 0 && (
1055 <li className="px-1 text-xs text-faint">No one yet.</li>
1056 )}
1057 </ul>
1058 {viewer && canManage && active && (
1059 <div className="mt-3 space-y-2">
1060 {!pull.assignees.includes(viewer.username) && (
1061 <Form method="post">
1062 <input type="hidden" name="action" value="assign" />
1063 {pull.assignees.map((name) => (
1064 <input key={name} type="hidden" name="assignee" value={name} />
1065 ))}
1066 <input type="hidden" name="assignee" value={viewer.username} />
1067 <div className="*:w-full">
1068 <Button variant="quiet" type="submit">
1069 Assign yourself
1070 </Button>
1071 </div>
1072 </Form>
1073 )}
1074 <details>
1075 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
1076 Assign people
1077 </summary>
1078 <Form method="post" className="mt-2 space-y-2" key={pull.assignees.join()}>
1079 <input type="hidden" name="action" value="assign" />
1080 <PeoplePicker name="assignee" members={members} chosen={pull.assignees} />
1081 <Button variant="quiet" type="submit">
1082 Save assignees
1083 </Button>
1084 </Form>
1085 </details>
1086 </div>
1087 )}
1088 {actionData?.action === "assign" && <ErrorText>{actionData.error}</ErrorText>}
1089 </section>
1090
1091 <section>
1092 <h3 className="text-sm font-medium">Working copy</h3>
1093 {pull.branch ? (
1094 <>
1095 <p className="mt-1 text-xs text-muted">
1096 <GitBranch size={13} className="mr-1 inline align-[-2px]" />
1097 Branch <span className="font-mono text-fg">{pull.branch}</span> of this
1098 repository. Pushes to it show up here.
1099 </p>
1100 <div className="mt-2">
1101 <CopyLine text={`git clone -b ${pull.branch} ${remote}`} />
1102 </div>
1103 </>
1104 ) : (
1105 <>
1106 <p className="mt-1 text-xs text-muted">
1107 This fork belongs to the pull request. Pushes to it show up here.
1108 </p>
1109 <div className="mt-2">
1110 <CopyLine text={`git clone ${remote}`} />
1111 </div>
1112 </>
1113 )}
1114 <p className="mt-3 flex items-center gap-1.5 font-mono text-xs text-faint">
1115 <GitCommitHorizontal size={13} />
1116 {pull.headCommit?.slice(0, 12) ?? "no commits pushed yet"}
1117 </p>
1118 </section>
1119 </aside>
1120 </div>
1121 );
1122}
1123
1124/** Where the pull request's change is live, as GitHub shows a deployment. */
1125function DeploymentCard({
1126 preview,
1127 build,
1128 stacked,
1129 base,
1130}: {
1131 preview: LiveApp | null;
1132 build: Deployment | null;
1133 stacked: { name: string; slug: string; url: string }[];
1134 base: string;
1135}) {
1136 const building = build?.status === "queued" || build?.status === "building";
1137 const failed = build?.status === "failed";
1138 return (
1139 <section className="ml-12 overflow-hidden rounded-xl border border-line bg-surface">
1140 <div className="flex flex-wrap items-center gap-3 px-4 py-3">
1141 <span
1142 className={`flex size-8 shrink-0 items-center justify-center rounded-full ring-1 ${
1143 failed ? "text-danger ring-danger/40" : building ? "text-warn ring-warn/40" : "text-accent ring-accent/40"
1144 }`}
1145 >
1146 {building ? <Loader size={15} className="animate-spin" /> : <Rocket size={15} />}
1147 </span>
1148 <div className="min-w-0 grow">
1149 <p className="text-sm font-medium">
1150 {building
1151 ? preview
1152 ? "Deploying the latest push. The last preview is still live."
1153 : "Deploying a preview"
1154 : failed
1155 ? "The preview failed to deploy"
1156 : "This branch is live"}
1157 </p>
1158 {preview ? (
1159 <a href={preview.url} className="mt-0.5 block truncate font-mono text-xs text-muted hover:text-accent">
1160 {preview.url.replace(/^https?:[/][/]/, "")}
1161 </a>
1162 ) : (
1163 build?.error && <p className="mt-0.5 truncate text-xs text-muted">{build.error}</p>
1164 )}
1165 </div>
1166 <div className="flex shrink-0 items-center gap-2">
1167 {build && (
1168 <Link to={`${base}/deployments/${build.id}`} className="text-xs text-muted hover:text-fg">
1169 {failed ? "See why" : "Build log"}
1170 </Link>
1171 )}
1172 {preview && (
1173 <a
1174 href={preview.url}
1175 className="inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-bg hover:opacity-90"
1176 >
1177 Visit preview
1178 <ArrowUpRight size={13} />
1179 </a>
1180 )}
1181 </div>
1182 </div>
1183 {preview && (
1184 <p className="border-t border-line px-4 py-2 text-xs text-faint">
1185 <span className="font-mono">{preview.commit.slice(0, 7)}</span> · deployed <TimeAgo at={preview.deployedAt} />
1186 {preview.branch && ` · from ${preview.branch}`}
1187 </p>
1188 )}
1189 {stacked.length > 0 && (
1190 <div className="border-t border-line px-4 py-2.5">
1191 <p className="text-xs text-muted">Built against this change:</p>
1192 <ul className="mt-1.5 space-y-1">
1193 {stacked.map((entry) => (
1194 <li key={entry.slug} className="flex items-center gap-2 text-xs">
1195 <span className="font-medium">{entry.name}</span>
1196 <a href={entry.url} className="truncate font-mono text-muted hover:text-accent">
1197 {entry.url.replace(/^https?:[/][/]/, "")}
1198 </a>
1199 </li>
1200 ))}
1201 </ul>
1202 </div>
1203 )}
1204 </section>
1205 );
1206}