g1t/apps/web/app/routes/repo/agents.tsx
| 1 | import { env } from "cloudflare:workers"; |
| 2 | import { Bot } from "lucide-react"; |
| 3 | import { Link } from "react-router"; |
| 4 | |
| 5 | import type { Route } from "./+types/agents"; |
| 6 | import { page } from "../../lib/meta"; |
| 7 | import { Idle, RunCard, splitRuns, useLiveRefresh } from "../../components/agents"; |
| 8 | import { AgentInstructions } from "../../components/agent-instructions"; |
| 9 | import { agents } from "../../lib/services.server"; |
| 10 | import { getViewer, roleIn, unwrap } from "../../lib/session.server"; |
| 11 | |
| 12 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 13 | return page(args, { title: `Agents at work · ${params.owner}/${params.repo} · g1t` }); |
| 14 | } |
| 15 | |
| 16 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 17 | const viewer = getViewer(context); |
| 18 | const repo = { namespace: params.owner, name: params.repo }; |
| 19 | const [runs, instructions] = await Promise.all([ |
| 20 | agents.listRuns(viewer, { repo, limit: 60 }), |
| 21 | // What every run here reads; never holds up the page. |
| 22 | env.RUNNER.instructions(viewer, repo).catch(() => null), |
| 23 | ]); |
| 24 | return { |
| 25 | runs: unwrap(runs), |
| 26 | member: roleIn(viewer, params.owner) != null, |
| 27 | instructions: instructions?.ok ? instructions.value : null, |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | export default function AgentsAtWork({ loaderData, params }: Route.ComponentProps) { |
| 32 | const { runs, member, instructions } = loaderData; |
| 33 | const { live, done } = splitRuns(runs); |
| 34 | useLiveRefresh(live.length > 0); |
| 35 | const base = `/${params.owner}/${params.repo}`; |
| 36 | return ( |
| 37 | <div className="max-w-4xl"> |
| 38 | <h2 className="flex items-center gap-2 text-xl font-semibold tracking-tight"> |
| 39 | <Bot size={19} className="text-merged" /> |
| 40 | At work |
| 41 | </h2> |
| 42 | <p className="mt-1.5 max-w-2xl text-sm text-muted"> |
| 43 | Every agent g1t has running on this project, and what each is doing this minute. Each run |
| 44 | works on one pull request in a sandbox of its own: making the change, revising it, reviewing, |
| 45 | catching up, answering another agent, or planning. Checks and merge queue sandboxes show here |
| 46 | too.{member && " Message a run to steer it, or stop it and take over."} |
| 47 | </p> |
| 48 | |
| 49 | <section className="mt-8"> |
| 50 | <div className="flex items-baseline justify-between"> |
| 51 | <h3 className="text-sm font-medium">Now</h3> |
| 52 | <span className="text-xs text-muted"> |
| 53 | {live.length === 0 ? "Nothing running" : `${live.length} running`} |
| 54 | </span> |
| 55 | </div> |
| 56 | {live.length === 0 ? ( |
| 57 | <div className="mt-3"> |
| 58 | <Idle> |
| 59 | No agent is at work here right now. Assign an issue to g1t-agent from the{" "} |
| 60 | <Link to={`${base}/issues`} className="text-fg underline-offset-2 hover:underline"> |
| 61 | issues |
| 62 | </Link>{" "} |
| 63 | to start one. |
| 64 | </Idle> |
| 65 | </div> |
| 66 | ) : ( |
| 67 | <ul className="mt-3 space-y-3"> |
| 68 | {live.map((run) => ( |
| 69 | <RunCard key={run.id} run={run} member={member} /> |
| 70 | ))} |
| 71 | </ul> |
| 72 | )} |
| 73 | </section> |
| 74 | |
| 75 | {done.length > 0 && ( |
| 76 | <section className="mt-10"> |
| 77 | <div className="flex items-baseline justify-between"> |
| 78 | <h3 className="text-sm font-medium">Recently finished</h3> |
| 79 | <Link to={`${base}/sessions`} className="text-xs text-muted hover:text-fg"> |
| 80 | All sessions |
| 81 | </Link> |
| 82 | </div> |
| 83 | <ul className="mt-3 space-y-3"> |
| 84 | {done.slice(0, 20).map((run) => ( |
| 85 | <RunCard key={run.id} run={run} member={member} /> |
| 86 | ))} |
| 87 | </ul> |
| 88 | </section> |
| 89 | )} |
| 90 | |
| 91 | {instructions && <AgentInstructions instructions={instructions} base={base} />} |
| 92 | </div> |
| 93 | ); |
| 94 | } |