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/components/agent-instructions.tsx

95 lines4,512 bytesCodeBlame
1import { FileText, ScrollText, ShieldCheck } from "lucide-react";
2import { Link } from "react-router";
3
4import type { RepoInstructions } from "@g1t/contracts";
5
6import { Idle } from "./agents";
7import { TimeAgo } from "./ui";
8
9const ROLE: Record<RepoInstructions["files"][number]["role"], string> = {
10 root: "Every run",
11 directory: "Runs that touch this directory",
12 review: "Reviews",
13};
14
15/**
16 * The files every g1t agent run in a project reads as the repository's
17 * instructions, as they are on its default branch: which, what they say,
18 * when they last changed, and where to change them.
19 */
20export function AgentInstructions({ instructions, base }: { instructions: RepoInstructions; base: string }) {
21 const { branch, files, limits } = instructions;
22 return (
23 <section className="mt-10">
24 <div className="flex items-baseline justify-between">
25 <h3 className="flex items-center gap-2 text-sm font-medium">
26 <ScrollText size={15} className="text-muted" />
27 Instructions
28 </h3>
29 <span className="text-xs text-muted">
30 {files.length === 0 ? "None yet" : `${files.length} ${files.length === 1 ? "file" : "files"} on ${branch}`}
31 </span>
32 </div>
33 <p className="mt-1.5 max-w-2xl text-sm text-muted">
34 Every agent run here reads the repository's <code className="font-mono text-xs">AGENTS.md</code> and{" "}
35 <code className="font-mono text-xs">CLAUDE.md</code> from {branch}: the ones at the root, and the nearest
36 ones above the files its task touches. Reviews also read{" "}
37 <code className="font-mono text-xs">.g1t/review.md</code>. Each file is cut at{" "}
38 {limits.fileChars.toLocaleString()} characters, and all of them at {limits.totalChars.toLocaleString()}.
39 </p>
40 <p className="mt-2 flex max-w-2xl items-start gap-2 text-xs text-faint">
41 <ShieldCheck size={13} className="mt-px shrink-0" />
42 Only {branch} and the repository's own branches are followed. A pull request from a fork that changes these
43 files is reviewed as a change, never followed as instructions.
44 </p>
45 {files.length === 0 ? (
46 <div className="mt-3">
47 <Idle>
48 No instructions yet. Commit an AGENTS.md to {branch} with how to build, test and work in this repository,
49 and every agent run reads it.
50 </Idle>
51 </div>
52 ) : (
53 <ul className="mt-3 space-y-3">
54 {files.map((file) => (
55 <li key={file.path} className="rounded-xl border border-line bg-surface">
56 <details>
57 <summary className="flex cursor-pointer flex-wrap items-center gap-x-3 gap-y-1 px-4 py-3 text-sm">
58 <FileText size={14} className="text-muted" />
59 <span className="font-mono font-medium">{file.path}</span>
60 <span className="rounded-full bg-raised px-2 py-px text-xs text-muted">{ROLE[file.role]}</span>
61 {file.truncated && <span className="text-xs text-warn">Longer than agents are given</span>}
62 <span className="ml-auto flex items-center gap-2 text-xs text-faint">
63 {file.lastChanged && (
64 <>
65 <Link
66 to={`${base}/commit/${file.lastChanged.commit}`}
67 className="font-mono hover:text-fg"
68 title={file.lastChanged.message}
69 >
70 {file.lastChanged.commit.slice(0, 7)}
71 </Link>
72 <span>by {file.lastChanged.author}</span>
73 <TimeAgo at={file.lastChanged.at} />
74 </>
75 )}
76 <Link to={`${base}/blob/${encodeURIComponent(branch)}/${file.path}`} className="text-muted hover:text-fg">
77 Open in code
78 </Link>
79 </span>
80 </summary>
81 <pre className="max-h-96 overflow-auto border-t border-line px-4 py-3 font-mono text-xs whitespace-pre-wrap text-muted">
82 {file.text || "(empty)"}
83 </pre>
84 </details>
85 </li>
86 ))}
87 </ul>
88 )}
89 <p className="mt-3 text-xs text-faint">
90 To change them, edit the files in the repository and merge the change into {branch}. Agents read the new version
91 from their next run.
92 </p>
93 </section>
94 );
95}