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

251 lines10,558 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Agents as a team: lifecycle, merge queue, billing and a new shell1import { env } from "cloudflare:workers";
2import { GitPullRequest, MessageSquare, Plus, Sparkles, X } from "lucide-react";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look3import { Form, Link, useNavigation, useRouteLoaderData } from "react-router";
Issues and pull requests replace intents and attempts4
5import type { Route } from "./+types/issues";
Social cards for every page: og.g1t.sh6import { page } from "../../lib/meta";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look7import { Button, ButtonLink, ComputeNote, EmptyState, ErrorText, TimeAgo } from "../../components/ui";
Workspace names and icons, and a component kit for every control8import { Checkbox } from "../../components/ui/checkbox";
Agents as a team: lifecycle, merge queue, billing and a new shell9import {
10 Assignee,
11 AssigneeStack,
12 IssueIcon,
13 Label,
14 StateTabs,
15} from "../../components/work";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look16import { computeNoteFor } from "../../lib/compute.server";
17import { isWaitingMessage } from "../../lib/compute";
Issues and pull requests replace intents and attempts18import { work } from "../../lib/services.server";
Agents as a team: lifecycle, merge queue, billing and a new shell19import { assertSameOrigin, getViewer, requireUser, unwrap } from "../../lib/session.server";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look20import { accessTo, refusal } from "../../lib/access.server";
Agents as a team: lifecycle, merge queue, billing and a new shell21
22/** As many sandboxes as one request may start. */
23const MAX_ASSIGNED_AT_ONCE = 10;
Issues and pull requests replace intents and attempts24
Social cards for every page: og.g1t.sh25export function meta({ params, ...args }: Route.MetaArgs) {
26 return page(args, { title: `Issues · ${params.owner}/${params.repo} · g1t` });
Issues and pull requests replace intents and attempts27}
28
29export async function loader({ params, context, request }: Route.LoaderArgs) {
30 const viewer = getViewer(context);
31 const path = { namespace: params.owner, name: params.repo };
32 const query = new URL(request.url).searchParams;
33 const state = query.get("state") === "closed" ? "closed" : "open";
34 const label = query.get("label") ?? "";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look35 // Assigning agents needs Write: Read cannot spend compute.
36 const { can } = await accessTo(context, params);
37 const [issues, labels, agentsEnabled, computeNote] = await Promise.all([
Issues and pull requests replace intents and attempts38 work.listIssues(path, viewer, { state, label: label || undefined }),
39 work.listLabels(path, viewer),
g1t's agents only for listed workspaces, whatever the state of billing40 env.RUNNER.enabled(viewer, path),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look41 // Before a member assigns: whether the workspace's plan lets agents start.
42 can.run ? computeNoteFor(params.owner, "agent") : null,
Issues and pull requests replace intents and attempts43 ]);
Agents as a team: lifecycle, merge queue, billing and a new shell44 return {
45 issues: unwrap(issues),
46 labels: unwrap(labels),
47 state,
48 label,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look49 agentsEnabled: agentsEnabled && can.run,
50 computeNote,
Agents as a team: lifecycle, merge queue, billing and a new shell51 } as const;
52}
53
54/** Assigns each selected issue to a g1t agent of its own. */
55export async function action({ request, params, context }: Route.ActionArgs) {
56 assertSameOrigin(request);
57 const user = requireUser(context, request);
58 const path = { namespace: params.owner, name: params.repo };
59 const numbers = (await request.formData())
60 .getAll("issue")
61 .map(Number)
62 .filter((number) => Number.isInteger(number) && number > 0);
63 if (numbers.length === 0) return { error: "Select the issues to assign first." };
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look64 const denied = await refusal(context, params, "run");
65 if (denied) return { error: denied };
Agents as a team: lifecycle, merge queue, billing and a new shell66 if (numbers.length > MAX_ASSIGNED_AT_ONCE) {
67 return { error: `Assign at most ${MAX_ASSIGNED_AT_ONCE} issues at a time.` };
68 }
69 const results = await Promise.all(
70 numbers.map((number) => env.RUNNER.run(user, path, number)),
71 );
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look72 // Over the workspace's agents-at-once cap, the rest wait in the queue.
73 const waiting = results.filter((result) => !result.ok && isWaitingMessage(result.error.message)).length;
74 const refused = results.find((result) => !result.ok && !isWaitingMessage(result.error.message));
Agents as a team: lifecycle, merge queue, billing and a new shell75 const started = results.filter((result) => result.ok).length;
76 return {
77 started,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look78 waiting,
Agents as a team: lifecycle, merge queue, billing and a new shell79 error:
80 refused && !refused.ok
81 ? `${started} of ${numbers.length} assigned. ${refused.error.message}`
82 : null,
83 };
Issues and pull requests replace intents and attempts84}
85
Agents as a team: lifecycle, merge queue, billing and a new shell86export default function Issues({ loaderData, actionData, params }: Route.ComponentProps) {
87 const { issues, labels, state, label, agentsEnabled } = loaderData;
Issues and pull requests replace intents and attempts88 const repo = `/${params.owner}/${params.repo}`;
89 const base = `${repo}/issues`;
90 const stateQuery = state === "closed" ? "state=closed" : "";
Agents as a team: lifecycle, merge queue, billing and a new shell91 const assignable = agentsEnabled && state === "open" && issues.length > 0;
92 const assigning = useNavigation().state === "submitting";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look93 // An archived repository's issues are locked: no new ones.
94 const layout = useRouteLoaderData("routes/repo/layout") as { repo?: { archivedAt?: string | null } } | undefined;
95 const archived = Boolean(layout?.repo?.archivedAt);
Issues and pull requests replace intents and attempts96 return (
97 <div>
98 <StateTabs
99 to={base}
100 state={state}
101 query={label ? `label=${encodeURIComponent(label)}` : ""}
102 action={
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look103 archived ? undefined : (
104 <ButtonLink to={`${base}/new`}>
105 <Plus size={15} />
106 New issue
107 </ButtonLink>
108 )
Issues and pull requests replace intents and attempts109 }
110 />
111 <div className="mt-3 flex flex-wrap items-center gap-1.5">
112 {labels.map((name) => {
113 const active = name === label;
114 const query = [stateQuery, active ? "" : `label=${encodeURIComponent(name)}`]
115 .filter(Boolean)
116 .join("&");
117 return (
118 <Link
119 key={name}
120 to={`${base}?${query}`}
121 className={`flex items-center gap-1 rounded-full transition-opacity ${
122 label && !active ? "opacity-45 hover:opacity-100" : ""
123 }`}
124 >
125 <Label name={name} />
126 {active && <X size={12} className="text-muted" />}
127 </Link>
128 );
129 })}
130 </div>
Agents as a team: lifecycle, merge queue, billing and a new shell131 <Form method="post" className="mt-4">
132 {assignable && (
133 <div className="mb-3 flex flex-wrap items-center gap-3 rounded-xl border border-accent/30 bg-accent/5 px-4 py-2.5">
134 <Sparkles size={15} className="shrink-0 text-accent" />
135 <p className="min-w-0 grow text-sm text-muted">
136 Tick the issues to hand over. Each gets a g1t agent of its own,
137 and they all work at once.
138 </p>
139 <Button variant="accent" type="submit" disabled={assigning}>
140 {assigning ? "Starting sandboxes…" : "Assign to g1t agent"}
141 </Button>
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look142 {loaderData.computeNote && (
143 <div className="basis-full">
144 <ComputeNote note={loaderData.computeNote} />
145 </div>
146 )}
Agents as a team: lifecycle, merge queue, billing and a new shell147 </div>
148 )}
149 {actionData?.error ? (
150 <div className="mb-3">
151 <ErrorText>{actionData.error}</ErrorText>
152 </div>
153 ) : (
154 actionData?.started != null && (
155 <p className="mb-3 text-sm text-muted">
156 {actionData.started}{" "}
157 {actionData.started === 1 ? "agent is" : "agents are"} starting. Each
158 issue shows its pull request as it appears.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look159 {actionData.waiting
160 ? ` ${actionData.waiting} more ${actionData.waiting === 1 ? "waits" : "wait"} for a free slot and start by themselves.`
161 : ""}
Agents as a team: lifecycle, merge queue, billing and a new shell162 </p>
163 )
164 )}
Issues and pull requests replace intents and attempts165 {issues.length === 0 ? (
166 <EmptyState
167 title={
168 label
169 ? `No ${state} issues labelled ${label}`
170 : state === "open"
171 ? "No open issues"
172 : "No closed issues"
173 }
174 >
175 An issue says what should change: a bug, a feature, a question.
176 Agents and people open pull requests against it.
177 </EmptyState>
178 ) : (
179 <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line">
180 {issues.map((issue) => (
Agents as a team: lifecycle, merge queue, billing and a new shell181 <li key={issue.id} className="flex items-start transition-colors hover:bg-surface">
182 {assignable && (
Workspace names and icons, and a component kit for every control183 <Checkbox
Agents as a team: lifecycle, merge queue, billing and a new shell184 name="issue"
Workspace names and icons, and a component kit for every control185 value={String(issue.number)}
Agents as a team: lifecycle, merge queue, billing and a new shell186 // Already being worked on: nothing more to hand over.
187 disabled={issue.agent != null || issue.queued}
188 aria-label={`Select issue #${issue.number}`}
Workspace names and icons, and a component kit for every control189 className="mt-4 ml-4 disabled:opacity-30"
Agents as a team: lifecycle, merge queue, billing and a new shell190 />
191 )}
Issues and pull requests replace intents and attempts192 <Link
Agents as a team: lifecycle, merge queue, billing and a new shell193 prefetch="intent"
Issues and pull requests replace intents and attempts194 to={`${base}/${issue.number}`}
Agents as a team: lifecycle, merge queue, billing and a new shell195 className="flex min-w-0 grow items-start gap-3 px-4 py-3"
Issues and pull requests replace intents and attempts196 >
197 <span className="mt-0.5">
198 <IssueIcon issue={issue} />
199 </span>
200 <span className="min-w-0 grow">
201 <span className="flex flex-wrap items-center gap-x-2 gap-y-1">
202 <span className="font-medium">{issue.title}</span>
203 {issue.labels.map((name) => (
204 <Label key={name} name={name} />
205 ))}
Agents as a team: lifecycle, merge queue, billing and a new shell206 {issue.state === "open" && issue.agent && (
207 <Assignee agent={issue.agent} />
208 )}
209 {issue.state === "open" && issue.queued && !issue.agent && (
210 <span className="rounded-full border border-line px-2 py-px text-xs text-muted">
211 queued for g1t-agent
212 {issue.blockedBy.length > 0 &&
213 `, after ${issue.blockedBy.map((number) => `#${number}`).join(", ")}`}
214 </span>
215 )}
Issues and pull requests replace intents and attempts216 </span>
217 <span className="mt-0.5 block text-xs text-faint">
218 #{issue.number} opened <TimeAgo at={issue.createdAt} /> by{" "}
219 {issue.author.username}
220 {issue.resolvedBy != null && (
221 <span className="text-merged"> · resolved by #{issue.resolvedBy}</span>
222 )}
223 </span>
224 </span>
225 <span className="mt-0.5 flex shrink-0 items-center gap-3 text-xs text-muted">
Agents as a team: lifecycle, merge queue, billing and a new shell226 <AssigneeStack people={issue.assignees} />
Issues and pull requests replace intents and attempts227 {issue.pullCount > 0 && (
228 <span
229 className="flex items-center gap-1"
230 title={`${issue.pullCount} pull ${issue.pullCount === 1 ? "request" : "requests"}`}
231 >
232 <GitPullRequest size={13} />
233 {issue.pullCount}
234 </span>
235 )}
236 {issue.commentCount > 0 && (
237 <span className="flex items-center gap-1">
238 <MessageSquare size={13} />
239 {issue.commentCount}
240 </span>
241 )}
242 </span>
243 </Link>
244 </li>
245 ))}
246 </ul>
247 )}
Agents as a team: lifecycle, merge queue, billing and a new shell248 </Form>
Issues and pull requests replace intents and attempts249 </div>
250 );
251}