g1t/packages/contracts/src/identity.ts
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.
| Agents as a team: lifecycle, merge queue, billing and a new shell | 1 | import type { RepoPath } from "./repos"; |
| Initial g1t: services, event bus, intents and attempts | 2 | import type { Result } from "./result"; |
| 3 | ||
| Email verification, password reset, and Git for AI scale positioning | 4 | export type User = { |
| 5 | id: string; | |
| 6 | username: string; | |
| 7 | /** | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 8 | * `workspace` when a workspace is acting through one of its own access |
| 9 | * tokens: `id` is then the workspace's and `username` its slug. Absent | |
| 10 | * means `user`. | |
| 11 | */ | |
| 12 | kind?: "user" | "workspace" | "agent"; | |
| 13 | /** | |
| Email verification, password reset, and Git for AI scale positioning | 14 | * Whether the account's email address is confirmed. Only set on users |
| 15 | * resolved from credentials; unverified accounts cannot change anything. | |
| 16 | */ | |
| 17 | verified?: boolean; | |
| Workspaces own repositories | 18 | /** |
| 19 | * The workspaces this user belongs to. Set on users resolved from | |
| 20 | * credentials, so any service can authorize from it. | |
| 21 | */ | |
| 22 | workspaces?: Membership[]; | |
| Email verification, password reset, and Git for AI scale positioning | 23 | }; |
| Initial g1t: services, event bus, intents and attempts | 24 | |
| Workspaces own repositories | 25 | /** What a member may do: an owner also manages the workspace's members. */ |
| 26 | export type Role = "owner" | "member"; | |
| 27 | ||
| 28 | export type Membership = { slug: string; role: Role }; | |
| 29 | ||
| 30 | /** | |
| 31 | * A workspace: the owner of repositories, and the first segment of their | |
| 32 | * URLs. A person's own space and a team's are the same thing. | |
| 33 | */ | |
| 34 | export type Workspace = { | |
| 35 | id: string; | |
| 36 | slug: string; | |
| 37 | name: string; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 38 | /** One line saying what the workspace is for. */ |
| 39 | description: string | null; | |
| Workspaces own repositories | 40 | /** RFC 3339. */ |
| 41 | createdAt: string; | |
| 42 | memberCount: number; | |
| 43 | }; | |
| 44 | ||
| 45 | export type Member = { username: string; role: Role }; | |
| 46 | ||
| Billing on Stripe's pages, month-end charges, warnings; sudo by workspace | 47 | /** An owner of a workspace, as staff see them. */ |
| 48 | export type AdminOwner = { username: string; email: string | null }; | |
| 49 | ||
| 50 | /** A workspace as staff see it. Mirrors `AdminWorkspace` in `crates/contracts/src/identity.rs`. */ | |
| 51 | export type AdminWorkspace = { | |
| 52 | slug: string; | |
| 53 | name: string; | |
| 54 | /** RFC 3339. */ | |
| 55 | createdAt: string; | |
| 56 | owners: AdminOwner[]; | |
| 57 | memberCount: number; | |
| 58 | }; | |
| 59 | ||
| 60 | /** A member of a workspace, as staff see them. */ | |
| 61 | export type AdminMember = { username: string; email: string | null; role: Role; /** RFC 3339. */ joined: string }; | |
| 62 | ||
| 63 | export type AdminWorkspaceDetail = { | |
| 64 | slug: string; | |
| 65 | name: string; | |
| 66 | description: string | null; | |
| 67 | /** RFC 3339. */ | |
| 68 | createdAt: string; | |
| 69 | /** Owners first, then by username. */ | |
| 70 | members: AdminMember[]; | |
| 71 | }; | |
| 72 | ||
| 73 | /** The most workspaces one `workspaces` call returns. */ | |
| 74 | export const ADMIN_WORKSPACES_LIMIT = 500; | |
| 75 | ||
| 76 | /** | |
| 77 | * Staff-only identity, for sudo.g1t.sh. It takes no viewer and checks no | |
| 78 | * membership: only sudo calls it, over its service binding, once Cloudflare | |
| 79 | * Access and its staff list have let someone in. Never call it on behalf of | |
| 80 | * a customer. | |
| 81 | */ | |
| 82 | export interface IdentityAdminApi { | |
| 83 | /** Every workspace, newest first, at most 500; `query` matches slug, name, or an owner's username or email. */ | |
| 84 | workspaces(query?: string): Promise<AdminWorkspace[]>; | |
| 85 | /** One workspace with all its members, or null. */ | |
| 86 | workspace(slug: string): Promise<AdminWorkspaceDetail | null>; | |
| 87 | } | |
| 88 | ||
| Initial g1t: services, event bus, intents and attempts | 89 | /** Who is asking. Every read and write in every service takes one. */ |
| 90 | export type Viewer = User | null; | |
| 91 | ||
| 92 | export type SshKey = { | |
| 93 | id: string; | |
| 94 | title: string; | |
| 95 | fingerprint: string; | |
| RFC 3339 timestamps in identity and repos | 96 | /** RFC 3339. */ |
| 97 | createdAt: string; | |
| Initial g1t: services, event bus, intents and attempts | 98 | }; |
| 99 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 100 | export type AccessToken = { |
| 101 | id: string; | |
| 102 | name: string; | |
| 103 | /** RFC 3339. */ | |
| 104 | createdAt: string; | |
| 105 | /** RFC 3339, to within a few minutes. Null until it is first used. */ | |
| 106 | lastUsedAt: string | null; | |
| 107 | /** | |
| 108 | * For a workspace's token, the username of the member who made it. Null | |
| 109 | * once that account is gone, and on personal tokens. | |
| 110 | */ | |
| 111 | createdBy: string | null; | |
| 112 | }; | |
| Initial g1t: services, event bus, intents and attempts | 113 | |
| Device sign-in replaces registering and minting tokens over the API | 114 | export type DeviceStart = { |
| 115 | /** Secret held by the tool and exchanged for a token once approved. */ | |
| 116 | deviceCode: string; | |
| 117 | /** Short code shown to the person, e.g. `WDJB-MJHT`. */ | |
| 118 | userCode: string; | |
| 119 | /** Seconds until both codes stop working. */ | |
| 120 | expiresIn: number; | |
| 121 | /** Seconds the tool should wait between polls. */ | |
| 122 | interval: number; | |
| 123 | }; | |
| 124 | ||
| 125 | export type DeviceRequest = { userCode: string; clientName: string }; | |
| 126 | ||
| 127 | export type DeviceClaim = | |
| 128 | | { status: "pending" | "denied" | "expired" } | |
| 129 | | { status: "approved"; token: string; user: User }; | |
| 130 | ||
| OAuth 2.1 sign-in for MCP clients and other applications | 131 | /** What the site passes on once a person has approved an application. */ |
| 132 | export type OAuthApproval = { | |
| 133 | clientId: string; | |
| 134 | /** Shown wherever the application's access is listed. */ | |
| 135 | clientName: string; | |
| 136 | redirectUri: string; | |
| 137 | /** PKCE challenge, method S256. */ | |
| 138 | codeChallenge: string; | |
| 139 | }; | |
| 140 | ||
| 141 | export type OAuthTokens = { | |
| 142 | accessToken: string; | |
| 143 | /** Works once; using it returns the next one. */ | |
| 144 | refreshToken: string; | |
| 145 | /** Seconds until the access token stops working. */ | |
| 146 | expiresIn: number; | |
| 147 | }; | |
| 148 | ||
| 149 | /** An application a person has signed in to. */ | |
| 150 | export type OAuthGrant = { | |
| 151 | id: string; | |
| 152 | clientName: string; | |
| 153 | /** RFC 3339. */ | |
| 154 | createdAt: string; | |
| 155 | /** RFC 3339. */ | |
| 156 | lastUsedAt: string; | |
| 157 | }; | |
| 158 | ||
| Initial g1t: services, event bus, intents and attempts | 159 | /** Accounts, credentials and sessions. */ |
| 160 | export interface IdentityApi { | |
| API and MCP server, Rust identity service, registration, site redesign | 161 | /** Creates an account and signs it in. */ |
| 162 | register(username: string, email: string, password: string): Promise<Result<{ user: User; sessionToken: string }>>; | |
| Initial g1t: services, event bus, intents and attempts | 163 | /** Verifies a username and password for website sign-in. */ |
| 164 | signIn(username: string, password: string): Promise<Result<{ user: User; sessionToken: string }>>; | |
| 165 | signOut(sessionToken: string): Promise<void>; | |
| Email verification, password reset, and Git for AI scale positioning | 166 | |
| 167 | /** Sends the confirmation email again. */ | |
| 168 | resendVerification(user: User): Promise<Result<boolean>>; | |
| 169 | /** Confirms the address the emailed token was sent to. */ | |
| 170 | verifyEmail(token: string): Promise<Result<User>>; | |
| 171 | /** Emails a reset link if the address has an account. Always resolves. */ | |
| 172 | requestPasswordReset(email: string): Promise<boolean>; | |
| 173 | /** Sets a new password from an emailed token and ends every session. */ | |
| 174 | resetPassword(token: string, password: string): Promise<Result<User>>; | |
| 175 | ||
| Device sign-in replaces registering and minting tokens over the API | 176 | /** |
| 177 | * Device sign-in (RFC 8628). A tool starts a request, a person approves | |
| 178 | * its short code in a browser, and the tool claims an access token. | |
| 179 | */ | |
| 180 | deviceStart(clientName: string): Promise<DeviceStart>; | |
| 181 | /** What a user code is asking for, or null if it is not valid. */ | |
| 182 | deviceLookup(userCode: string): Promise<DeviceRequest | null>; | |
| 183 | deviceResolve(userCode: string, user: User, approve: boolean): Promise<Result<boolean>>; | |
| 184 | deviceClaim(deviceCode: string): Promise<DeviceClaim>; | |
| 185 | ||
| OAuth 2.1 sign-in for MCP clients and other applications | 186 | /** |
| 187 | * OAuth 2.1 for applications that sign a person in through the browser. | |
| 188 | * The caller has checked the client and its redirect address; this | |
| 189 | * returns the one-time code the application exchanges for tokens. | |
| 190 | */ | |
| 191 | oauthAuthorize(user: User, approval: OAuthApproval): Promise<{ code: string }>; | |
| 192 | /** Redeems a code. It works once, for that client, with the PKCE verifier. */ | |
| 193 | oauthExchange(code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<Result<OAuthTokens>>; | |
| 194 | /** Trades a refresh token for new tokens; the old ones stop working. */ | |
| 195 | oauthRefresh(refreshToken: string, clientId: string): Promise<Result<OAuthTokens>>; | |
| 196 | /** Applications the user has signed in to, most recently used first. */ | |
| 197 | listOAuthGrants(user: User): Promise<OAuthGrant[]>; | |
| 198 | /** Signs an application out. */ | |
| 199 | revokeOAuthGrant(user: User, id: string): Promise<void>; | |
| 200 | ||
| Workspaces own repositories | 201 | createWorkspace(user: User, slug: string, name: string): Promise<Result<Workspace>>; |
| 202 | /** Public details of a workspace, or null. */ | |
| 203 | getWorkspace(slug: string): Promise<Workspace | null>; | |
| 204 | /** Members only. */ | |
| 205 | listMembers(slug: string, viewer: Viewer): Promise<Result<Member[]>>; | |
| 206 | /** Owners only. */ | |
| 207 | addMember(actor: User, slug: string, username: string): Promise<Result<boolean>>; | |
| 208 | /** Owners only. */ | |
| 209 | removeMember(actor: User, slug: string, username: string): Promise<Result<boolean>>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 210 | /** Owners only. An empty name falls back to the slug. */ |
| 211 | updateWorkspace(actor: User, slug: string, details: { name: string; description: string }): Promise<Result<Workspace>>; | |
| Workspaces own repositories | 212 | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 213 | /** |
| 214 | * A workspace's own access tokens. They belong to the workspace, act as | |
| 215 | * it, and keep working when the member who made one leaves. Members only. | |
| 216 | */ | |
| 217 | listWorkspaceTokens(slug: string, viewer: Viewer): Promise<Result<AccessToken[]>>; | |
| 218 | /** Owners only. The plaintext token is returned once and never stored. */ | |
| 219 | createWorkspaceToken(actor: User, slug: string, name: string): Promise<Result<{ token: string; info: AccessToken }>>; | |
| 220 | /** Owners only. */ | |
| 221 | removeWorkspaceToken(actor: User, slug: string, id: string): Promise<Result<boolean>>; | |
| 222 | ||
| Initial g1t: services, event bus, intents and attempts | 223 | userForSession(sessionToken: string): Promise<Viewer>; |
| 224 | ||
| 225 | /** Verifies git credentials: the account password or an access token. */ | |
| 226 | userForGitCredentials(username: string, secret: string): Promise<Viewer>; | |
| API and MCP server, Rust identity service, registration, site redesign | 227 | /** Resolves a `g1t_…` access token, as sent to the API and MCP server. */ |
| 228 | userForAccessToken(token: string): Promise<Viewer>; | |
| Initial g1t: services, event bus, intents and attempts | 229 | userForSshKey(fingerprint: string): Promise<Viewer>; |
| 230 | userByUsername(username: string): Promise<Viewer>; | |
| What happened across an outcome, as a feed beside its graph | 231 | /** The names behind account and workspace ids; unknown ids are left out. */ |
| 232 | usernames(ids: string[]): Promise<Record<string, string>>; | |
| Initial g1t: services, event bus, intents and attempts | 233 | |
| 234 | listSshKeys(user: User): Promise<SshKey[]>; | |
| 235 | /** Takes one line in OpenSSH public key format. */ | |
| 236 | addSshKey(user: User, title: string, publicKey: string): Promise<Result<SshKey>>; | |
| 237 | removeSshKey(user: User, id: string): Promise<void>; | |
| 238 | ||
| 239 | listAccessTokens(user: User): Promise<AccessToken[]>; | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 240 | /** |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 241 | * The plaintext token is returned once and never stored. With |
| 242 | * `ttlSeconds` the token expires and is left out of token lists; that | |
| 243 | * form is used for hosted agents. A token made for a workspace acting | |
| 244 | * through a token of its own belongs to that workspace too. | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 245 | */ |
| 246 | createAccessToken(user: User, name: string, ttlSeconds?: number): Promise<{ token: string; info: AccessToken }>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 247 | /** |
| 248 | * A token for a g1t agent working for `onBehalfOf`: it acts as | |
| 249 | * `g1t-agent`, in `scope.repo` only, and only for `scope.operations`. | |
| 250 | */ | |
| 251 | createAgentToken( | |
| 252 | onBehalfOf: User, | |
| 253 | scope: AgentScope, | |
| 254 | ttlSeconds: number, | |
| 255 | ): Promise<{ token: string; info: AccessToken }>; | |
| Initial g1t: services, event bus, intents and attempts | 256 | removeAccessToken(user: User, id: string): Promise<void>; |
| 257 | } | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 258 | |
| 259 | ||
| 260 | /** What an agent's token may do: these operations, in this repository. */ | |
| 261 | export type AgentScope = { repo: RepoPath; operations: string[] }; |