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/agents-run.tsx

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