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.

g1t.sh
171 linesCodeBlameRaw

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.

The phone app: Chat in full with phone notifications, plus Code and Customize (#4)1import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
3import { useSignedIn } from "./session";
4
5/**
6 * Code, through the REST API (docs.g1t.sh/reference/api/). The API
7 * answers in snake_case, so these are its shapes, not the camelCase ones
8 * in @g1t/contracts that the services use among themselves. Only the
9 * fields the app shows are named.
10 */
11
Merge branch 'mobile-agent-leftovers' into rm-agents12/** `agent` only on what g1t's own agents wrote before they were retired; shown with an Agent badge. */
The phone app: Chat in full with phone notifications, plus Code and Customize (#4)13export type ApiUser = { id: string; username: string; display_username?: string; kind?: "user" | "workspace" | "agent" | "system" };
14
15export type ApiRepo = {
16 id: string;
17 namespace: string;
18 name: string;
19 description: string | null;
20 is_private: boolean;
21 default_branch: string;
22 created_at: string;
23 archived_at?: string | null;
24};
25
26export type ApiIssue = {
27 id: string;
28 number: number;
29 title: string;
30 body: string;
31 labels: string[];
32 state: "open" | "closed";
33 reason: "completed" | "not_planned" | null;
34 author: ApiUser;
35 created_at: string;
36 updated_at: string;
37 comment_count: number;
38 pull_count: number;
39};
40
41export type CheckStatus = "queued" | "running" | "passed" | "failed" | "errored" | null;
42
43export type ApiPull = {
44 id: string;
45 number: number;
46 issue: number | null;
47 title: string;
48 body: string | null;
Merge branch 'mobile-agent-leftovers' into rm-agents49 /** The coding agent it was made with (`claude-code`, `codex`), from the session recorded on it; null when none was. */
50 agent: string | null;
The phone app: Chat in full with phone notifications, plus Code and Customize (#4)51 status: "draft" | "open" | "merged" | "closed";
52 branch: string | null;
53 base: string;
54 check_status: CheckStatus;
55 files: { path: string; additions: number; deletions: number }[];
56 reviewers: string[];
57 labels: string[];
58 author: ApiUser;
59 created_at: string;
60 updated_at: string;
61 merged_at: string | null;
62};
63
64export type ApiComment = {
65 id: string;
66 kind: "comment" | "event";
67 author: ApiUser;
68 body: string;
69 path: string | null;
70 line: number | null;
71 verdict: string | null;
72 created_at: string;
73};
74
75export type ApiChanges = {
76 base: string;
77 head: string;
78 truncated: boolean;
79 files: {
80 path: string;
81 status: "added" | "modified" | "deleted";
82 additions: number;
83 deletions: number;
84 binary: boolean;
Large pull requests, commits and comparisons open quickly and no longer risk failing: the Files changed tab of a 206-file pull request sent every file's diff at once, 14,366 table rows drawn on the server (6.7 MB of its 8.7 MB of HTML) and the same lines again in the data the page hydrates from (1.6 MB), with 300 KB of highlighting sent twice. Now the page arrives with the whole file list, tree and counts, and the lines of its first files, about 2,000; every later file holds its place at its height and loads as you scroll near it, eight or so to a request (diff-files.json, cached by the two commits compared, here and in the browser), and a refresh keeps what was loaded. A file with a diff over 1,000 lines (a lockfile, generated code) waits for Load diff; files with comments on their lines come with the page wherever they are; a link to a file (#file-<path>, or #diff-<path>) opens it, loads it at once however large, and keeps it at the top while the files above it fill in. Small changes are sent exactly as before. Highlighting done on the server stops after 16,000 characters rather than 40,000; the rest is coloured in the browser as it comes near, as it already was. The repos service listed the files past its 20,000-line read as binary with no counts, so 126 of this pull request's files said "Binary or large file"; they are now marked omitted, show no counts until read ("126 files not counted" in the toolbar), and load like the rest, read on their own by compare's new paths (at most 50); truncated now means only that more than 300 files changed. get_pull_request_changes and GET /repos/{owner}/{name}/pulls/{number}/changes take paths too, and the mobile app says an omitted file is too large to show there. The pull requests guide gains Files changed, and limitations says how large changes are shown. Checked: the site's typecheck, its 914 tests (new: the first-screens budget, large and commented files, omitted and binary ones, links to a file, and fetching in batches, once, with retries) and a production build; cargo test for contracts, repos (new: omitted files and reading by path), actions, security, work and api; the mobile typecheck; the docs build. Measured on flagon-io/g1t pull 1's real response, before → after: single-fetch data 1,592,101 → 236,252 bytes; the diff's server-rendered HTML 6,694,038 → 1,698,300 bytes (renderToString 62 → 15 ms), so the page's HTML about 8.7 MB → 2.0 MB; in a harness mounting the real routes in Chrome at 1280 px, first render 600 → 270 ms, settled 2,250 → 750 ms, long tasks 1,700 → 500 ms, 84,605 → 17,982 elements; scrolling to the bottom loads all 72 waiting files in 9 requests, and refreshes with the same data remove no elements, before and after files load. Screenshots at 1280 and 390 px looked at.85 /** Past what one answer reads: listed without its lines or counts. */
86 omitted?: boolean;
The phone app: Chat in full with phone notifications, plus Code and Customize (#4)87 hunks?: { lines: { kind: "context" | "add" | "delete"; old: number | null; new: number | null; text: string }[] }[];
88 }[];
89};
90
91const repoPath = (owner: string, name: string) => `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`;
92
93/** Repositories you can see, newest first (at most 50), in the workspace chosen. */
94export function useRepos(search: string) {
95 const { client, workspace } = useSignedIn();
96 return useQuery({
97 queryKey: ["code", "repos", search],
98 queryFn: () => client.api<ApiRepo[]>(`/repos${search ? `?q=${encodeURIComponent(search)}` : ""}`),
99 select: (repos) => (workspace ? repos.filter((repo) => repo.namespace.toLowerCase() === workspace.slug.toLowerCase()) : repos),
100 });
101}
102
103export function useRepo(owner: string, name: string) {
104 const { client } = useSignedIn();
105 return useQuery({ queryKey: ["code", "repo", owner, name], queryFn: () => client.api<ApiRepo>(repoPath(owner, name)) });
106}
107
108export function usePulls(owner: string, name: string, state: "open" | "closed" | "all") {
109 const { client } = useSignedIn();
110 return useQuery({
111 queryKey: ["code", "pulls", owner, name, state],
112 queryFn: () => client.api<ApiPull[]>(`${repoPath(owner, name)}/pulls?state=${state}`),
113 });
114}
115
116export function useIssues(owner: string, name: string, state: "open" | "closed" | "all") {
117 const { client } = useSignedIn();
118 return useQuery({
119 queryKey: ["code", "issues", owner, name, state],
120 queryFn: () => client.api<ApiIssue[]>(`${repoPath(owner, name)}/issues?state=${state}`),
121 });
122}
123
124export function usePull(owner: string, name: string, number: number) {
125 const { client } = useSignedIn();
126 return useQuery({
127 queryKey: ["code", "pull", owner, name, number],
128 queryFn: () =>
129 client.api<{ pull: ApiPull; issue: ApiIssue | null; comments: ApiComment[] }>(`${repoPath(owner, name)}/pulls/${number}`),
130 });
131}
132
133export function usePullChanges(owner: string, name: string, number: number, enabled: boolean) {
134 const { client } = useSignedIn();
135 return useQuery({
136 queryKey: ["code", "pull-changes", owner, name, number],
137 queryFn: () => client.api<ApiChanges>(`${repoPath(owner, name)}/pulls/${number}/changes`),
138 enabled,
139 });
140}
141
142export function useIssue(owner: string, name: string, number: number) {
143 const { client } = useSignedIn();
144 return useQuery({
145 queryKey: ["code", "issue", owner, name, number],
146 queryFn: () =>
147 client.api<{ issue: ApiIssue; pulls: ApiPull[]; comments: ApiComment[] }>(`${repoPath(owner, name)}/issues/${number}`),
148 });
149}
150
151/** Comments on an issue (`POST /repos/{owner}/{name}/issues/{number}/comments`). */
152export function useComment(owner: string, name: string, number: number) {
153 const { client } = useSignedIn();
154 const queries = useQueryClient();
155 return useMutation({
156 mutationFn: (body: string) =>
157 client.api<ApiComment>(`${repoPath(owner, name)}/issues/${number}/comments`, { method: "POST", body: JSON.stringify({ body }) }),
158 onSuccess: () => queries.invalidateQueries({ queryKey: ["code", "issue", owner, name, number] }),
159 });
160}
161
162/** Reviews a pull request (`POST /repos/{owner}/{name}/pulls/{number}/reviews`). */
163export function useReview(owner: string, name: string, number: number) {
164 const { client } = useSignedIn();
165 const queries = useQueryClient();
166 return useMutation({
167 mutationFn: (review: { verdict: "approve" | "request_changes"; body: string }) =>
168 client.api<ApiComment>(`${repoPath(owner, name)}/pulls/${number}/reviews`, { method: "POST", body: JSON.stringify(review) }),
169 onSuccess: () => queries.invalidateQueries({ queryKey: ["code", "pull", owner, name, number] }),
170 });
171}

This file's history is long; its oldest lines are credited to the oldest commit read.