g1t/apps/web/app/routes/settings.tsx
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.
| API and MCP server, Rust identity service, registration, site redesign | 1 | import { identity } from "../lib/services.server"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 2 | import { Form, Link } from "react-router"; |
| Initial g1t: services, event bus, intents and attempts | 3 | |
| 4 | import type { Route } from "./+types/settings"; | |
| Social cards for every page: og.g1t.sh | 5 | import { page } from "../lib/meta"; |
| Workspace names and icons, and a component kit for every control | 6 | import { AvatarField } from "../components/avatar-field"; |
| OAuth 2.1 sign-in for MCP clients and other applications | 7 | import { Button, ErrorText, Field, Input, TimeAgo } from "../components/ui"; |
| Workspace names and icons, and a component kit for every control | 8 | import { readAvatarUpload } from "../lib/avatar-upload"; |
| Initial g1t: services, event bus, intents and attempts | 9 | import { assertSameOrigin, requireUser } from "../lib/session.server"; |
| 10 | ||
| Social cards for every page: og.g1t.sh | 11 | export function meta(args: Route.MetaArgs) { |
| 12 | return page(args, { title: "Settings · g1t" }); | |
| Initial g1t: services, event bus, intents and attempts | 13 | } |
| 14 | ||
| 15 | export async function loader({ request, context }: Route.LoaderArgs) { | |
| 16 | const user = requireUser(context, request); | |
| OAuth 2.1 sign-in for MCP clients and other applications | 17 | const [keys, tokens, applications] = await Promise.all([ |
| API and MCP server, Rust identity service, registration, site redesign | 18 | identity.listSshKeys(user), |
| 19 | identity.listAccessTokens(user), | |
| OAuth 2.1 sign-in for MCP clients and other applications | 20 | identity.listOAuthGrants(user), |
| Initial g1t: services, event bus, intents and attempts | 21 | ]); |
| OAuth 2.1 sign-in for MCP clients and other applications | 22 | return { user, keys, tokens, applications }; |
| Initial g1t: services, event bus, intents and attempts | 23 | } |
| 24 | ||
| 25 | export async function action({ request, context }: Route.ActionArgs) { | |
| 26 | assertSameOrigin(request); | |
| 27 | const user = requireUser(context, request); | |
| 28 | const form = await request.formData(); | |
| 29 | const id = String(form.get("id") ?? ""); | |
| 30 | ||
| 31 | switch (form.get("intent")) { | |
| Workspace names and icons, and a component kit for every control | 32 | // The picture: identity checks the image's bytes again. |
| 33 | case "avatar": { | |
| 34 | const upload = await readAvatarUpload(form); | |
| 35 | if ("error" in upload) return { avatarError: upload.error }; | |
| 36 | const result = await identity.setUserAvatar(user, upload.image); | |
| 37 | return result.ok ? null : { avatarError: result.error.message }; | |
| 38 | } | |
| 39 | case "remove-avatar": { | |
| 40 | const result = await identity.setUserAvatar(user, null); | |
| 41 | return result.ok ? null : { avatarError: result.error.message }; | |
| 42 | } | |
| Initial g1t: services, event bus, intents and attempts | 43 | case "add-key": { |
| API and MCP server, Rust identity service, registration, site redesign | 44 | const result = await identity.addSshKey( |
| Initial g1t: services, event bus, intents and attempts | 45 | user, |
| 46 | String(form.get("title") ?? ""), | |
| 47 | String(form.get("key") ?? ""), | |
| 48 | ); | |
| 49 | return result.ok ? null : { keyError: result.error.message }; | |
| 50 | } | |
| 51 | case "delete-key": | |
| API and MCP server, Rust identity service, registration, site redesign | 52 | await identity.removeSshKey(user, id); |
| Initial g1t: services, event bus, intents and attempts | 53 | return null; |
| 54 | case "add-token": { | |
| API and MCP server, Rust identity service, registration, site redesign | 55 | const created = await identity.createAccessToken( |
| Initial g1t: services, event bus, intents and attempts | 56 | user, |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 57 | String(form.get("label") ?? ""), |
| Initial g1t: services, event bus, intents and attempts | 58 | ); |
| 59 | return { newToken: created.token }; | |
| 60 | } | |
| 61 | case "delete-token": | |
| API and MCP server, Rust identity service, registration, site redesign | 62 | await identity.removeAccessToken(user, id); |
| Initial g1t: services, event bus, intents and attempts | 63 | return null; |
| OAuth 2.1 sign-in for MCP clients and other applications | 64 | case "sign-out-application": |
| 65 | await identity.revokeOAuthGrant(user, id); | |
| 66 | return null; | |
| Initial g1t: services, event bus, intents and attempts | 67 | } |
| 68 | return null; | |
| 69 | } | |
| 70 | ||
| OAuth 2.1 sign-in for MCP clients and other applications | 71 | function DeleteButton({ |
| 72 | intent, | |
| 73 | id, | |
| 74 | label = "Delete", | |
| 75 | }: { | |
| 76 | intent: string; | |
| 77 | id: string; | |
| 78 | label?: string; | |
| 79 | }) { | |
| Initial g1t: services, event bus, intents and attempts | 80 | return ( |
| 81 | <Form method="post" className="ml-auto"> | |
| 82 | <input type="hidden" name="intent" value={intent} /> | |
| 83 | <input type="hidden" name="id" value={id} /> | |
| 84 | <Button variant="quiet" type="submit"> | |
| OAuth 2.1 sign-in for MCP clients and other applications | 85 | {label} |
| Initial g1t: services, event bus, intents and attempts | 86 | </Button> |
| 87 | </Form> | |
| 88 | ); | |
| 89 | } | |
| 90 | ||
| 91 | export default function Settings({ | |
| 92 | loaderData, | |
| 93 | actionData, | |
| 94 | }: Route.ComponentProps) { | |
| OAuth 2.1 sign-in for MCP clients and other applications | 95 | const { user, keys, tokens, applications } = loaderData; |
| Initial g1t: services, event bus, intents and attempts | 96 | return ( |
| Account settings in the same shape as a workspace's | 97 | <main className="mx-auto max-w-5xl px-4 py-10 sm:px-8"> |
| 98 | <header className="mb-8 border-b border-line pb-6"> | |
| 99 | <h1 className="text-2xl font-semibold tracking-tight">Account</h1> | |
| 100 | <p className="mt-1.5 text-sm text-muted"> | |
| 101 | How <span className="font-mono text-fg">{user.username}</span> signs in from git, tools and agents. | |
| 102 | </p> | |
| 103 | </header> | |
| 104 | <div className="max-w-2xl space-y-12"> | |
| Workspace names and icons, and a component kit for every control | 105 | <section id="picture" className="scroll-mt-20"> |
| 106 | <h2 className="font-medium">Picture</h2> | |
| 107 | <div className="mt-4"> | |
| 108 | <AvatarField | |
| 109 | name={user.username} | |
| 110 | image={user.avatar} | |
| 111 | error={actionData && "avatarError" in actionData ? actionData.avatarError : undefined} | |
| 112 | about="Shown beside your username in the sidebar and on mission control. Without one, g1t draws your first letter." | |
| 113 | /> | |
| 114 | </div> | |
| 115 | </section> | |
| Account settings in the same shape as a workspace's | 116 | <section id="ssh-keys" className="scroll-mt-20"> |
| Initial g1t: services, event bus, intents and attempts | 117 | <h2 className="font-medium">SSH keys</h2> |
| 118 | <ul className="mt-4 divide-y divide-line rounded-md border border-line empty:hidden"> | |
| 119 | {keys.map((key) => ( | |
| 120 | <li key={key.id} className="flex items-center gap-4 px-4 py-3"> | |
| 121 | <div className="min-w-0"> | |
| 122 | <p className="text-sm">{key.title}</p> | |
| 123 | <p className="truncate font-mono text-xs text-muted"> | |
| 124 | {key.fingerprint} | |
| 125 | </p> | |
| 126 | </div> | |
| 127 | <DeleteButton intent="delete-key" id={key.id} /> | |
| 128 | </li> | |
| 129 | ))} | |
| 130 | </ul> | |
| 131 | <Form method="post" className="mt-4 space-y-3"> | |
| 132 | <input type="hidden" name="intent" value="add-key" /> | |
| 133 | <Field label="Title (optional)"> | |
| 134 | <Input name="title" maxLength={100} /> | |
| 135 | </Field> | |
| 136 | <Field label="Public key"> | |
| 137 | <Input name="key" placeholder="ssh-ed25519 AAAA…" required /> | |
| 138 | </Field> | |
| 139 | <ErrorText>{actionData?.keyError}</ErrorText> | |
| 140 | <Button type="submit">Add SSH key</Button> | |
| 141 | </Form> | |
| 142 | </section> | |
| 143 | ||
| Account settings in the same shape as a workspace's | 144 | <section id="tokens" className="scroll-mt-20"> |
| Initial g1t: services, event bus, intents and attempts | 145 | <h2 className="font-medium">Access tokens</h2> |
| 146 | <p className="mt-1 text-sm text-muted"> | |
| 147 | Use a token as the password when git asks for one over HTTPS, and to | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 148 | authenticate agents and the API. A token here acts as you. |
| Initial g1t: services, event bus, intents and attempts | 149 | </p> |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 150 | {(user.workspaces ?? []).length > 0 && ( |
| 151 | <p className="mt-1 text-sm text-muted"> | |
| 152 | For CI and integrations that work for a team, use a workspace's | |
| 153 | own tokens instead:{" "} | |
| 154 | {(user.workspaces ?? []).map((membership, i) => ( | |
| 155 | <span key={membership.slug}> | |
| 156 | {i > 0 && ", "} | |
| 157 | <Link | |
| 158 | to={`/${membership.slug}/-/tokens`} | |
| 159 | className="font-mono text-fg underline underline-offset-4" | |
| 160 | > | |
| 161 | {membership.slug} | |
| 162 | </Link> | |
| 163 | </span> | |
| 164 | ))} | |
| 165 | . | |
| 166 | </p> | |
| 167 | )} | |
| Initial g1t: services, event bus, intents and attempts | 168 | {actionData?.newToken && ( |
| 169 | <div className="mt-4 rounded-md border border-accent/40 bg-surface p-4"> | |
| 170 | <p className="text-sm">Copy it now. It will not be shown again.</p> | |
| 171 | <pre className="mt-2 overflow-x-auto font-mono text-sm text-accent"> | |
| 172 | {actionData.newToken} | |
| 173 | </pre> | |
| 174 | </div> | |
| 175 | )} | |
| 176 | <ul className="mt-4 divide-y divide-line rounded-md border border-line empty:hidden"> | |
| 177 | {tokens.map((token) => ( | |
| 178 | <li key={token.id} className="flex items-center gap-4 px-4 py-3"> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 179 | <div className="min-w-0"> |
| 180 | <p className="truncate text-sm">{token.name}</p> | |
| 181 | <p className="text-xs text-faint"> | |
| 182 | Created <TimeAgo at={token.createdAt} /> ·{" "} | |
| 183 | {token.lastUsedAt ? ( | |
| 184 | <> | |
| 185 | last used <TimeAgo at={token.lastUsedAt} /> | |
| 186 | </> | |
| 187 | ) : ( | |
| 188 | "never used" | |
| 189 | )} | |
| 190 | </p> | |
| 191 | </div> | |
| Initial g1t: services, event bus, intents and attempts | 192 | <DeleteButton intent="delete-token" id={token.id} /> |
| 193 | </li> | |
| 194 | ))} | |
| 195 | </ul> | |
| 196 | <Form method="post" className="mt-4 flex items-end gap-3"> | |
| 197 | <input type="hidden" name="intent" value="add-token" /> | |
| 198 | <div className="grow"> | |
| 199 | <Field label="Name"> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 200 | <Input name="label" maxLength={100} placeholder="laptop" /> |
| Initial g1t: services, event bus, intents and attempts | 201 | </Field> |
| 202 | </div> | |
| 203 | <Button type="submit">Create token</Button> | |
| 204 | </Form> | |
| 205 | </section> | |
| OAuth 2.1 sign-in for MCP clients and other applications | 206 | |
| Account settings in the same shape as a workspace's | 207 | <section id="applications" className="scroll-mt-20"> |
| OAuth 2.1 sign-in for MCP clients and other applications | 208 | <h2 className="font-medium">Connected applications</h2> |
| 209 | <p className="mt-1 text-sm text-muted"> | |
| 210 | Applications you signed in to through your browser, such as an agent | |
| 211 | connected to the g1t MCP server. Signing one out ends its access at | |
| 212 | once. | |
| 213 | </p> | |
| 214 | {applications.length === 0 ? ( | |
| 215 | <p className="mt-4 text-sm text-faint">None yet.</p> | |
| 216 | ) : ( | |
| 217 | <ul className="mt-4 divide-y divide-line rounded-md border border-line"> | |
| 218 | {applications.map((application) => ( | |
| 219 | <li key={application.id} className="flex items-center gap-4 px-4 py-3"> | |
| 220 | <div> | |
| 221 | <p className="text-sm">{application.clientName}</p> | |
| 222 | <p className="text-xs text-faint"> | |
| 223 | Connected <TimeAgo at={application.createdAt} /> · last used{" "} | |
| 224 | <TimeAgo at={application.lastUsedAt} /> | |
| 225 | </p> | |
| 226 | </div> | |
| 227 | <DeleteButton | |
| 228 | intent="sign-out-application" | |
| 229 | id={application.id} | |
| 230 | label="Sign out" | |
| 231 | /> | |
| 232 | </li> | |
| 233 | ))} | |
| 234 | </ul> | |
| 235 | )} | |
| 236 | </section> | |
| Account settings in the same shape as a workspace's | 237 | </div> |
| Initial g1t: services, event bus, intents and attempts | 238 | </main> |
| 239 | ); | |
| 240 | } |