Skip to content

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

103 linesCodeBlameRaw
1import { ArrowLeft } from "lucide-react";
2import { Link } from "react-router";
3
4import { RUN_KIND_LABEL, isActiveRun } from "@g1t/contracts";
5
6import type { Route } from "./+types/agents-run";
7import { page } from "../../lib/meta";
8import { RunCard, useLiveRefresh } from "../../components/agents";
9import { RunCaps } from "../../components/guardrails";
10import { WhatItDid } from "../../components/audit";
11import { runAudit } from "../../lib/audit.server";
12import { agents } from "../../lib/services.server";
13import { getViewer, roleIn, unwrap } from "../../lib/session.server";
14import { accessTo } from "../../lib/access.server";
15import { Card } from "../../components/ui/card";
16
17export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
18 const kind = loaderData ? RUN_KIND_LABEL[loaderData.run.kind] : "Run";
19 return page(args, { title: `${kind} run · ${params.owner}/${params.repo} · g1t` });
20}
21
22export async function loader({ params, context }: Route.LoaderArgs) {
23 const viewer = getViewer(context);
24 const run = await agents.getRun(viewer, { namespace: params.owner, name: params.repo }, params.id);
25 // What it did with its credentials, from the audit log: members only.
26 const did = await runAudit(viewer, params.owner, [params.id]);
27 // Stopping and messaging need Write; the audit log is the workspace's.
28 return { run: unwrap(run), runner: (await accessTo(context, params)).can.run, member: roleIn(viewer, params.owner) != null, did };
29}
30
31function clock(at: string): string {
32 return new Date(at).toISOString().slice(11, 19);
33}
34
35export default function AgentRunPage({ loaderData, params }: Route.ComponentProps) {
36 const { run, runner, member, did } = loaderData;
37 const active = isActiveRun(run.status);
38 useLiveRefresh(active);
39 const base = `/${params.owner}/${params.repo}`;
40 // The newest step first while it runs, so what it is doing is at the top.
41 const steps = active ? [...run.steps].reverse() : run.steps;
42 return (
43 <div className="max-w-4xl">
44 <Link to={`${base}/agents`} className="inline-flex items-center gap-1.5 text-sm text-muted hover:text-fg">
45 <ArrowLeft size={14} />
46 At work
47 </Link>
48 <ul className="mt-4">
49 <RunCard run={run} member={runner} />
50 </ul>
51 <RunCaps run={run} member={runner} />
52 <section className="mt-8">
53 <div className="flex items-baseline justify-between">
54 <h3 className="text-sm font-medium">Steps</h3>
55 <span className="text-xs text-muted">
56 {run.stepCount > run.steps.length
57 ? `The latest ${run.steps.length} of ${run.stepCount}`
58 : `${run.stepCount} ${run.stepCount === 1 ? "step" : "steps"}`}
59 {active && ", newest first"}
60 </span>
61 </div>
62 {steps.length === 0 ? (
63 <p className="mt-3 text-sm text-muted">
64 {active ? "The sandbox is starting. Steps appear here as the agent takes them." : "This run reported no steps."}
65 </p>
66 ) : (
67 <Card asChild divided className="mt-3">
68 <ol>
69 {steps.map((step, index) => (
70 <li key={`${step.at}-${index}`} className="flex gap-3 px-4 py-2 text-sm">
71 <time dateTime={step.at} className="shrink-0 font-mono text-xs leading-5 text-faint" suppressHydrationWarning>
72 {clock(step.at)}
73 </time>
74 <span className="min-w-0 font-mono text-xs leading-5 break-words text-fg/85">{step.text}</span>
75 </li>
76 ))}
77 </ol>
78 </Card>
79 )}
80 {run.number != null && (
81 <p className="mt-4 text-sm text-muted">
82 The full record, with every prompt, message, tool call and result, is in{" "}
83 <Link to={`${base}/sessions/${run.number}`} className="text-fg underline-offset-2 hover:underline">
84 the session of #{run.number}
85 </Link>
86 .
87 </p>
88 )}
89 </section>
90 {member && (
91 <section className="mt-8">
92 <div className="flex items-baseline justify-between">
93 <h3 className="text-sm font-medium">What it did</h3>
94 <Link to={`/${params.owner}/-/audit?run=${encodeURIComponent(run.id)}`} className="text-xs text-muted hover:text-fg">
95 In the audit log
96 </Link>
97 </div>
98 <WhatItDid entries={did} />
99 </section>
100 )}
101 </div>
102 );
103}