Skip to content

g1t/crates/contracts/src/identity.rs

1,458 lines49,770 bytesCodeBlame

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 redesign1//! The identity service: accounts, credentials and sessions.
2//!
3//! Each `*Args` struct is the argument of the method of the same name,
4//! served at `POST /rpc/<method>`.
5
6use serde::{Deserialize, Serialize};
7
8use crate::User;
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct SshKey {
13 pub id: String,
14 pub title: String,
15 pub fingerprint: String,
RFC 3339 timestamps in identity and repos16 /// RFC 3339.
17 pub created_at: String,
API and MCP server, Rust identity service, registration, site redesign18}
19
20#[derive(Clone, Debug, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct AccessToken {
23 pub id: String,
24 pub name: String,
RFC 3339 timestamps in identity and repos25 /// RFC 3339.
26 pub created_at: String,
Agents as a team: lifecycle, merge queue, billing and a new shell27 /// RFC 3339, to within a few minutes. Null until it is first used.
28 pub last_used_at: Option<String>,
29 /// For a workspace's token, the username of the member who made it.
30 /// Null once that account is gone, and on personal tokens.
31 pub created_by: Option<String>,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step32 /// Its scopes, as `resource:level`. Null: full access.
33 #[serde(default)]
34 pub scopes: Option<Vec<String>>,
35 /// Made before tokens had scopes: full access until someone narrows it.
36 #[serde(default)]
37 pub legacy: bool,
38 /// RFC 3339. Null: it does not expire.
39 #[serde(default)]
40 pub expires_at: Option<String>,
API and MCP server, Rust identity service, registration, site redesign41}
42
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look43/// `sign_in`: verifies a username, or any confirmed email address of the
44/// account, and its password, for website sign-in. Wrong passwords are
45/// counted against the account and `client`, and past a limit nothing is
46/// checked for a while (see identity's `throttle.rs`).
API and MCP server, Rust identity service, registration, site redesign47/// Returns `Outcome<SignedIn>`.
48#[derive(Debug, Serialize, Deserialize)]
49pub struct SignInArgs {
50 pub username: String,
51 pub password: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look52 /// Who is asking, such as the visitor's IP address, for rate limits.
53 #[serde(default)]
54 pub client: Option<String>,
API and MCP server, Rust identity service, registration, site redesign55}
56
57#[derive(Debug, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct SignedIn {
60 pub user: User,
61 pub session_token: String,
62}
63
64/// `sign_out` and `user_for_session`.
65#[derive(Debug, Serialize, Deserialize)]
66#[serde(rename_all = "camelCase")]
67pub struct SessionArgs {
68 pub session_token: String,
69}
70
71/// `user_for_git_credentials`: the account password or an access token.
72#[derive(Debug, Serialize, Deserialize)]
73pub struct GitCredentialsArgs {
74 pub username: String,
75 pub secret: String,
76}
77
78/// `user_for_access_token`.
79#[derive(Debug, Serialize, Deserialize)]
80pub struct TokenArgs {
81 pub token: String,
82}
83
84/// `user_for_ssh_key`.
85#[derive(Debug, Serialize, Deserialize)]
86pub struct FingerprintArgs {
87 pub fingerprint: String,
88}
89
90/// `user_by_username`.
91#[derive(Debug, Serialize, Deserialize)]
92pub struct UsernameArgs {
93 pub username: String,
94}
95
What happened across an outcome, as a feed beside its graph96/// `usernames`: the names behind account and workspace ids, as events and
97/// other records store them. Returns a map from id to name; ids it does
98/// not know are left out.
99#[derive(Debug, Serialize, Deserialize)]
100pub struct UsernamesArgs {
101 pub ids: Vec<String>,
102}
103
API and MCP server, Rust identity service, registration, site redesign104/// `list_ssh_keys` and `list_access_tokens`.
105#[derive(Debug, Serialize, Deserialize)]
106pub struct UserArgs {
107 pub user: User,
108}
109
110/// `add_ssh_key`: `public_key` is one line in OpenSSH format.
111/// Returns `Outcome<SshKey>`.
112#[derive(Debug, Serialize, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct AddSshKeyArgs {
115 pub user: User,
116 pub title: String,
117 pub public_key: String,
118}
119
120/// `remove_ssh_key` and `remove_access_token`.
121#[derive(Debug, Serialize, Deserialize)]
122pub struct RemoveArgs {
123 pub user: User,
124 pub id: String,
125}
126
Agents as a team: lifecycle, merge queue, billing and a new shell127/// `create_access_token`: a token that acts as `user`. For a workspace
128/// acting through a token of its own, the new token belongs to that
129/// workspace too.
API and MCP server, Rust identity service, registration, site redesign130#[derive(Debug, Serialize, Deserialize)]
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)131#[serde(rename_all = "camelCase")]
API and MCP server, Rust identity service, registration, site redesign132pub struct CreateAccessTokenArgs {
133 pub user: User,
134 pub name: String,
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)135 /// When set, the token stops working after this many seconds and is
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step136 /// left out of the user's token list, unless `listed`. Used for hosted
137 /// attempts.
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)138 #[serde(default)]
139 pub ttl_seconds: Option<u64>,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step140 /// Its scopes, as `resource:level`; unknown names are left out. Null:
141 /// full access.
142 #[serde(default)]
143 pub scopes: Option<Vec<String>>,
144 /// Listed with the person's tokens although it expires: one they made
145 /// themselves, with an expiry.
146 #[serde(default)]
147 pub listed: bool,
148}
149
150/// `update_access_token`: changes what one of a person's tokens may do.
151/// The token itself is unchanged. Returns `Outcome<AccessToken>`.
152#[derive(Debug, Serialize, Deserialize)]
153pub struct UpdateAccessTokenArgs {
154 pub user: User,
155 pub id: String,
156 /// Null: full access.
157 #[serde(default)]
158 pub scopes: Option<Vec<String>>,
API and MCP server, Rust identity service, registration, site redesign159}
160
161/// The plaintext token is returned once and never stored.
162#[derive(Debug, Serialize, Deserialize)]
163pub struct CreatedAccessToken {
164 pub token: String,
165 pub info: AccessToken,
166}
167
168/// `register`: creates an account and signs it in.
169/// Returns `Outcome<SignedIn>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look170///
171/// While registration is invite-only (`REGISTRATION_MODE=invite`), every
172/// new account needs `invite_code`: an unused, unexpired invite, and, when
173/// the invite names an email, that address. See [`CreateInviteArgs`].
API and MCP server, Rust identity service, registration, site redesign174#[derive(Debug, Serialize, Deserialize)]
175pub struct RegisterArgs {
176 pub username: String,
177 pub email: String,
178 pub password: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look179 /// An invite code such as `g1t-k7m2-q9xd-4hpw-…`. Ignored while
180 /// registration is open.
181 #[serde(default)]
182 pub invite_code: Option<String>,
183 /// Who is asking, such as the visitor's IP address, for rate limits.
184 #[serde(default)]
185 pub client: Option<String>,
API and MCP server, Rust identity service, registration, site redesign186}
Email verification, password reset, and Git for AI scale positioning187
188/// `verify_email`: the token from the emailed link. Returns `Outcome<User>`.
189#[derive(Debug, Serialize, Deserialize)]
190pub struct EmailTokenArgs {
191 pub token: String,
192}
193
194/// `request_password_reset`. Always succeeds, so it cannot be used to find
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look195/// out which addresses have accounts. Any confirmed address of an account
196/// works: the link goes to the address given, and the primary (and the
197/// backup) are told a reset was asked for. A few requests an hour per
198/// address and per `client`; past that, nothing is sent.
Email verification, password reset, and Git for AI scale positioning199#[derive(Debug, Serialize, Deserialize)]
200pub struct EmailArgs {
201 pub email: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look202 /// Who is asking, such as the visitor's IP address, for rate limits.
203 #[serde(default)]
204 pub client: Option<String>,
Email verification, password reset, and Git for AI scale positioning205}
206
207/// `reset_password`: sets a new password and ends every session.
208/// Returns `Outcome<User>`.
209#[derive(Debug, Serialize, Deserialize)]
210pub struct ResetPasswordArgs {
211 pub token: String,
212 pub password: String,
213}
Device sign-in replaces registering and minting tokens over the API214
215/// `device_start`: begins a device sign-in. Returns `DeviceStart`.
216#[derive(Debug, Serialize, Deserialize)]
217#[serde(rename_all = "camelCase")]
218pub struct DeviceStartArgs {
219 /// What is asking, shown to the person approving, e.g. "Claude Code".
220 pub client_name: String,
221}
222
223#[derive(Debug, Serialize, Deserialize)]
224#[serde(rename_all = "camelCase")]
225pub struct DeviceStart {
226 /// Secret held by the tool and exchanged for a token once approved.
227 pub device_code: String,
228 /// Short code shown to the person, e.g. `WDJB-MJHT`.
229 pub user_code: String,
230 /// Seconds until both codes stop working.
231 pub expires_in: u32,
232 /// Seconds the tool should wait between polls.
233 pub interval: u32,
234}
235
236/// `device_lookup`: what a user code is asking for, or null if it is not
237/// valid. Returns `Option<DeviceRequest>`.
238#[derive(Debug, Serialize, Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub struct DeviceLookupArgs {
241 pub user_code: String,
242}
243
244#[derive(Debug, Serialize, Deserialize)]
245#[serde(rename_all = "camelCase")]
246pub struct DeviceRequest {
247 pub user_code: String,
248 pub client_name: String,
249}
250
251/// `device_resolve`: the signed-in person approves or denies a request.
252/// Returns `Outcome<bool>`.
253#[derive(Debug, Serialize, Deserialize)]
254#[serde(rename_all = "camelCase")]
255pub struct DeviceResolveArgs {
256 pub user_code: String,
257 pub user: User,
258 pub approve: bool,
259}
260
261/// `device_claim`: the tool asks whether its request was approved.
262#[derive(Debug, Serialize, Deserialize)]
263#[serde(rename_all = "camelCase")]
264pub struct DeviceClaimArgs {
265 pub device_code: String,
266}
267
268/// The answer to a `device_claim`.
269#[derive(Debug, Serialize, Deserialize)]
270#[serde(tag = "status", rename_all = "snake_case")]
271pub enum DeviceClaim {
272 /// Nobody has approved or denied it yet; ask again after the interval.
273 Pending,
274 Denied,
275 /// The code was never issued, has expired, or was already used.
276 Expired,
277 /// The access token, returned once.
278 Approved {
279 token: String,
280 user: User,
281 },
282}
Workspaces own repositories283
284/// A workspace: the owner of repositories, and the first segment of their
285/// URLs. A person's own space and a team's are the same thing.
286#[derive(Clone, Debug, Serialize, Deserialize)]
287#[serde(rename_all = "camelCase")]
288pub struct Workspace {
289 pub id: String,
290 pub slug: String,
291 pub name: String,
Agents as a team: lifecycle, merge queue, billing and a new shell292 /// One line saying what the workspace is for.
293 pub description: Option<String>,
Workspaces own repositories294 /// RFC 3339.
295 pub created_at: String,
296 pub member_count: u32,
Workspace names and icons, and a component kit for every control297 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
298 /// `/avatars/<avatar>`. Null means the generated letter avatar.
299 #[serde(default)]
300 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look301 /// What every member gets on each of its repositories; owners have
302 /// Admin. See [`crate::access`].
303 #[serde(default)]
304 pub base_permission: crate::access::BasePermission,
Merge branch 'worktree-agent-ad7c6d88d93adc817'305 /// Who may create its teams. See [`crate::teams::TeamCreation`].
306 #[serde(default)]
307 pub team_creation: crate::teams::TeamCreation,
Workspaces own repositories308}
309
310#[derive(Clone, Debug, Serialize, Deserialize)]
311pub struct Member {
312 pub username: String,
313 pub role: crate::Role,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look314 /// Their display name, when they set one.
315 #[serde(default)]
316 pub name: Option<String>,
317 /// Their uploaded avatar: the SHA-256 of its bytes, served at
318 /// `/avatars/<avatar>`. None means the generated letter avatar.
319 #[serde(default)]
320 pub avatar: Option<String>,
Workspaces own repositories321}
322
Merge branch 'worktree-agent-a2013627e5ea4ab13'323/// Where a workspace keeps its repositories' git data: anywhere g1t
324/// stores it (the default), or in the EU only. It applies to repositories
325/// made after it is set; the repos service reads it when it places a new
326/// one (`storage_options` says whether the EU can be chosen).
327#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
328#[serde(rename_all = "lowercase")]
329pub enum DataResidency {
330 #[default]
331 Anywhere,
332 Eu,
333}
334
335impl DataResidency {
336 pub fn as_str(self) -> &'static str {
337 match self {
338 DataResidency::Anywhere => "anywhere",
339 DataResidency::Eu => "eu",
340 }
341 }
342
343 pub fn parse(text: &str) -> Option<Self> {
344 match text.trim().to_ascii_lowercase().as_str() {
345 "anywhere" => Some(DataResidency::Anywhere),
346 "eu" => Some(DataResidency::Eu),
347 _ => None,
348 }
349 }
350}
351
352/// `workspace_residency` takes [`SlugArgs`] and returns
353/// `Option<DataResidency>` (null when there is no such workspace).
354/// `set_workspace_residency`: owners only. Returns `Outcome<DataResidency>`.
355#[derive(Debug, Serialize, Deserialize)]
356pub struct SetResidencyArgs {
357 pub actor: User,
358 pub slug: String,
359 pub residency: DataResidency,
360}
361
Workspaces own repositories362/// `create_workspace`. Returns `Outcome<Workspace>`.
363#[derive(Debug, Serialize, Deserialize)]
364pub struct CreateWorkspaceArgs {
365 pub user: User,
366 pub slug: String,
367 #[serde(default)]
368 pub name: String,
369}
370
371/// `get_workspace`: public details, or null. Returns `Option<Workspace>`.
372#[derive(Debug, Serialize, Deserialize)]
373pub struct SlugArgs {
374 pub slug: String,
375}
376
377/// `list_members`: members only. Returns `Outcome<Vec<Member>>`.
378#[derive(Debug, Serialize, Deserialize)]
379pub struct ListMembersArgs {
380 pub slug: String,
381 pub viewer: crate::Viewer,
382}
383
384/// `add_member` and `remove_member`: owners only.
385/// Each returns `Outcome<bool>`.
386#[derive(Debug, Serialize, Deserialize)]
387pub struct MemberArgs {
388 pub actor: User,
389 pub slug: String,
390 pub username: String,
391}
OAuth 2.1 sign-in for MCP clients and other applications392
Agents as a team: lifecycle, merge queue, billing and a new shell393/// `update_workspace`: owners only. An empty name falls back to the slug;
394/// an empty description clears it. Returns `Outcome<Workspace>`.
395#[derive(Debug, Serialize, Deserialize)]
396pub struct UpdateWorkspaceArgs {
397 pub actor: User,
398 pub slug: String,
399 pub name: String,
400 pub description: String,
401}
402
Agents and memory, checks and conflicts, profiles, slug renames, custom domains403/// `rename_workspace`: owners only. Changes the workspace's slug, the first
404/// segment of its URLs, to `new_slug`; the display name is untouched. The
405/// old slug redirects to the new one, and is held for this workspace, for
406/// [`SLUG_HOLD_DAYS`]. Publishes `workspace.renamed`. Returns
407/// `Outcome<Workspace>`.
408///
409/// `check_workspace_rename` takes the same arguments and answers whether
410/// the rename would be allowed, changing nothing. Returns `Outcome<bool>`.
411#[derive(Debug, Serialize, Deserialize)]
412#[serde(rename_all = "camelCase")]
413pub struct RenameWorkspaceArgs {
414 pub actor: User,
415 pub slug: String,
416 pub new_slug: String,
417}
418
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look419/// `delete_workspace`: owners only, and only a person. `confirm` must be
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member420/// the workspace's slug, typed out. Refused for a protected workspace
421/// ([`protected_names`]), whoever asks, and while billing cannot settle it
422/// (`close_workspace`). Everything in it goes with it at once: nobody can
423/// reach it, its tokens stop working, its pages are not found, and its
424/// repositories, projects and apps are deleted with it. It is kept for
425/// [`WORKSPACE_RESTORE_DAYS`] so g1t's staff can restore it, then purged:
426/// its memberships, access tokens and old-slug redirects go, and billing's
427/// ledger and the audit log keep its history. The slug is never given to
428/// another workspace; the person whose username it is may make a workspace
429/// of that name again once it is purged. Publishes `workspace.deleting`,
430/// and `workspace.deleted` at the purge. Returns `Outcome<bool>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look431///
432/// `check_workspace_deletion` takes the same arguments (with `confirm`
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member433/// ignored) and says what would go and whether anything stands in the way,
434/// changing nothing. Returns `Outcome<WorkspaceDeletion>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look435#[derive(Debug, Serialize, Deserialize)]
436pub struct DeleteWorkspaceArgs {
437 pub actor: User,
438 pub slug: String,
439 #[serde(default)]
440 pub confirm: String,
441 /// Where the request came in, for the audit log; g1t.sh when absent.
442 #[serde(default)]
443 pub surface: Option<crate::audit::Surface>,
444}
445
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member446/// What deleting a workspace takes with it, and what stands in the way.
447/// Nothing does when `billing` is null and it is not `protected`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look448#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
449pub struct WorkspaceDeletion {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member450 /// Its live repositories, which are deleted with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look451 pub repositories: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member452 /// Its projects, hidden with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look453 pub projects: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member454 #[serde(default)]
455 pub members: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look456 /// Why billing cannot close the workspace yet, in words for its owner.
457 pub billing: Option<String>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member458 /// It can never be deleted, by anyone ([`protected_names`]).
459 #[serde(default)]
460 pub protected: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look461}
462
463impl WorkspaceDeletion {
464 pub fn blocked(&self) -> bool {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member465 self.protected || self.billing.is_some()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look466 }
467
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member468 /// Why the workspace cannot be deleted, as one sentence, or `None`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look469 pub fn reason(&self, slug: &str) -> Option<String> {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member470 if self.protected {
471 return Some(protected_refusal(slug));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look472 }
473 self.billing.clone()
474 }
475}
476
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member477/// How long a deleted workspace is kept, for staff to restore, before it is
478/// purged.
479pub const WORKSPACE_RESTORE_DAYS: u64 = 30;
480
481/// Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
482/// says: Flagon's, which runs g1t.
483pub const ALWAYS_PROTECTED: &[&str] = &["flagon-io"];
484
485/// The protected workspaces: `configured` (comma-separated slugs or
486/// workspace ids, as identity's `PROTECTED_WORKSPACES` holds them), and
487/// [`ALWAYS_PROTECTED`] whatever it says, so an empty or missing variable
488/// still protects them. Lowercased, without duplicates.
489pub fn protected_names(configured: Option<&str>) -> Vec<String> {
490 let mut names: Vec<String> = Vec::new();
491 let given = configured.unwrap_or_default().split(',');
492 for name in ALWAYS_PROTECTED.iter().copied().chain(given) {
493 let name = name.trim().to_lowercase();
494 if !name.is_empty() && !names.contains(&name) {
495 names.push(name);
496 }
497 }
498 names
499}
500
501/// Why a protected workspace is not deleted, purged or acted on.
502pub fn protected_refusal(slug: &str) -> String {
503 format!("{slug} is protected and can never be deleted.")
504}
505
506/// `admin_deleted_workspaces` takes no arguments (`{}`) and returns
507/// `Vec<DeletedWorkspace>`, newest first. Staff only.
508///
509/// A workspace an owner deleted, kept until `purge_after` for staff to
510/// restore.
511#[derive(Clone, Debug, Serialize, Deserialize)]
512#[serde(rename_all = "camelCase")]
513pub struct DeletedWorkspace {
514 pub workspace_id: String,
515 pub slug: String,
516 pub name: String,
517 /// RFC 3339.
518 pub deleted_at: String,
519 /// The username of the owner who deleted it.
520 pub deleted_by: String,
521 /// RFC 3339: when it is purged unless restored first.
522 pub purge_after: String,
523 /// What went with it, counted when it was deleted.
524 pub went: WorkspaceDeletion,
525 /// Whether staff can still restore it.
526 pub restorable: bool,
527}
528
529/// `admin_restore_workspace` and `admin_purge_workspace`: staff restore a
530/// deleted workspace within [`WORKSPACE_RESTORE_DAYS`], or purge it now.
531/// `staff` is who, for the audit logs. Purging needs `confirm`, the slug
532/// typed out, and is refused for a protected workspace. Restoring publishes
533/// `workspace.restored`; purging, `workspace.deleted`. Both return
534/// `Outcome<bool>`.
535#[derive(Debug, Serialize, Deserialize)]
536#[serde(rename_all = "camelCase")]
537pub struct AdminDeletedWorkspaceArgs {
538 pub workspace_id: String,
539 pub staff: String,
540 #[serde(default)]
541 pub confirm: String,
542}
543
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look544/// `transfer_repo_scopes`: a repository moved from `from` to `to`; the
545/// tokens of agents at work on it are kept pointing at it. For repos'
546/// `transfer`. Returns `bool`.
547#[derive(Debug, Serialize, Deserialize)]
548pub struct TransferRepoScopesArgs {
549 pub from: crate::repos::RepoPath,
550 pub to: crate::repos::RepoPath,
551}
552
Agents and memory, checks and conflicts, profiles, slug renames, custom domains553/// How long a workspace's old slug keeps redirecting to it, and stays
554/// reserved for it, after a rename.
555pub const SLUG_HOLD_DAYS: u64 = 90;
556
557/// How long a workspace must wait between renames.
558pub const RENAME_COOLDOWN_HOURS: u64 = 24;
559
560// `resolve_slug` takes `SlugArgs` and returns `Option<String>`: the
561// workspace's current slug when `slug` is one it was renamed from within
562// the last `SLUG_HOLD_DAYS`, and null otherwise (including for a slug that
563// is in use).
564
Workspace names and icons, and a component kit for every control565/// `set_workspace_avatar`: owners only. `image` is the file's bytes in
566/// base64: PNG, JPEG, WebP or GIF, at most `MAX_AVATAR_BYTES`. Null removes
567/// the icon. Returns `Outcome<Workspace>`.
568#[derive(Debug, Serialize, Deserialize)]
569pub struct SetWorkspaceAvatarArgs {
570 pub actor: User,
571 pub slug: String,
572 pub image: Option<String>,
573}
574
575/// `set_user_avatar`: a person's own avatar, as `SetWorkspaceAvatarArgs`.
576/// Returns `Outcome<Option<String>>`: the new avatar, or null once removed.
577#[derive(Debug, Serialize, Deserialize)]
578pub struct SetUserAvatarArgs {
579 pub user: User,
580 pub image: Option<String>,
581}
582
583/// The largest avatar that can be uploaded, in bytes.
584pub const MAX_AVATAR_BYTES: usize = 1024 * 1024;
585
Agents as a team: lifecycle, merge queue, billing and a new shell586/// `list_workspace_tokens`: members only. Returns
587/// `Outcome<Vec<AccessToken>>`.
588#[derive(Debug, Serialize, Deserialize)]
589pub struct WorkspaceTokensArgs {
590 pub slug: String,
591 pub viewer: crate::Viewer,
592}
593
594/// `create_workspace_token`: owners only. The token belongs to the
595/// workspace, acts as it, and keeps working when the member who made it
596/// leaves. Returns `Outcome<CreatedAccessToken>`.
597#[derive(Debug, Serialize, Deserialize)]
598pub struct CreateWorkspaceTokenArgs {
599 pub actor: User,
600 pub slug: String,
601 pub name: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step602 /// Its scopes; null for full access.
603 #[serde(default)]
604 pub scopes: Option<Vec<String>>,
605 /// When set, the token stops working after this many seconds. It is
606 /// listed with the workspace's tokens either way. Null: no expiry.
607 #[serde(default)]
608 pub ttl_seconds: Option<u64>,
Agents as a team: lifecycle, merge queue, billing and a new shell609}
610
611/// `remove_workspace_token`: owners only. Returns `Outcome<bool>`.
612#[derive(Debug, Serialize, Deserialize)]
613pub struct RemoveWorkspaceTokenArgs {
614 pub actor: User,
615 pub slug: String,
616 pub id: String,
617}
618
OAuth 2.1 sign-in for MCP clients and other applications619/// `oauth_authorize`: the signed-in person approved an application. The
620/// caller has checked the client and that it may be redirected to
621/// `redirect_uri`. Returns `OAuthCode`.
622#[derive(Debug, Serialize, Deserialize)]
623#[serde(rename_all = "camelCase")]
624pub struct OAuthAuthorizeArgs {
625 pub user: User,
626 pub client_id: String,
627 /// Shown wherever the application's access is listed.
628 pub client_name: String,
629 pub redirect_uri: String,
630 /// PKCE challenge, method S256.
631 pub code_challenge: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step632 /// What the person granted, as `resource:level`. Null: full access.
633 #[serde(default)]
634 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications635}
636
637#[derive(Debug, Serialize, Deserialize)]
638pub struct OAuthCode {
639 pub code: String,
640}
641
642/// `oauth_exchange`: redeems an authorization code.
643/// Returns `Outcome<OAuthTokens>`.
644#[derive(Debug, Serialize, Deserialize)]
645#[serde(rename_all = "camelCase")]
646pub struct OAuthExchangeArgs {
647 pub code: String,
648 pub code_verifier: String,
649 pub client_id: String,
650 pub redirect_uri: String,
651}
652
653/// `oauth_refresh`: trades a refresh token for new tokens.
654/// Returns `Outcome<OAuthTokens>`.
655#[derive(Debug, Serialize, Deserialize)]
656#[serde(rename_all = "camelCase")]
657pub struct OAuthRefreshArgs {
658 pub refresh_token: String,
659 pub client_id: String,
660}
661
662#[derive(Debug, Serialize, Deserialize)]
663#[serde(rename_all = "camelCase")]
664pub struct OAuthTokens {
665 pub access_token: String,
666 /// Works once; using it returns the next one.
667 pub refresh_token: String,
668 /// Seconds until the access token stops working.
669 pub expires_in: u64,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step670 /// The scopes granted, space-separated, or `*` for full access.
671 #[serde(default)]
672 pub scope: Option<String>,
OAuth 2.1 sign-in for MCP clients and other applications673}
674
675/// An application a person has signed in to. Listed by `list_oauth_grants`
676/// and ended by `revoke_oauth_grant`.
677#[derive(Debug, Serialize, Deserialize)]
678#[serde(rename_all = "camelCase")]
679pub struct OAuthGrant {
680 pub id: String,
681 pub client_name: String,
682 /// RFC 3339.
683 pub created_at: String,
684 /// RFC 3339.
685 pub last_used_at: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step686 /// What the person granted. Null: full access.
687 #[serde(default)]
688 pub scopes: Option<Vec<String>>,
689 /// Signed in before applications were given scopes: full access until
690 /// someone narrows it.
691 #[serde(default)]
692 pub legacy: bool,
693}
694
695/// `update_oauth_grant`: changes what an application the person signed in
696/// to may do, at once and when it refreshes. Returns `Outcome<OAuthGrant>`.
697#[derive(Debug, Serialize, Deserialize)]
698pub struct UpdateOAuthGrantArgs {
699 pub user: User,
700 pub id: String,
701 #[serde(default)]
702 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications703}
Agents as a team: lifecycle, merge queue, billing and a new shell704
705
706/// What an agent's token may do: these operations, in this repository.
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API707#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Agents as a team: lifecycle, merge queue, billing and a new shell708pub struct AgentScope {
709 pub repo: crate::repos::RepoPath,
710 /// API and MCP operation names, such as `create_issue`.
711 pub operations: Vec<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API712 /// Set on a run credential: the run it belongs to, and what it may do
713 /// with git. See [`crate::credentials`].
714 #[serde(default, skip_serializing_if = "Option::is_none")]
715 pub run: Option<crate::credentials::RunBinding>,
Agents as a team: lifecycle, merge queue, billing and a new shell716}
717
718/// `create_agent_token`: a token for a g1t agent working on someone's
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent719/// behalf. It acts as `g1t`, a member of the repository's workspace,
Agents as a team: lifecycle, merge queue, billing and a new shell720/// and only for the operations in `scope`. Returns `CreatedAccessToken`.
721#[derive(Debug, Serialize, Deserialize)]
722#[serde(rename_all = "camelCase")]
723pub struct CreateAgentTokenArgs {
724 /// The person the agent works for; the token is recorded as theirs.
725 pub on_behalf_of: User,
726 pub scope: AgentScope,
727 pub ttl_seconds: u64,
728}
729
730// `agent_scope` takes `TokenArgs` and returns `Option<AgentScope>`: what an
731// agent's token may do, or null for any other token.
732
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent733/// The id g1t's agent acts under. Only ever stored, never shown: it keeps
734/// the agent's work apart from g1t's own ([`crate::system::ID`]) where
735/// that matters, such as whether its approval counts.
Agents as a team: lifecycle, merge queue, billing and a new shell736pub const AGENT_ID: &str = "usr_g1t_agent";
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent737/// The name g1t's agent is shown by: g1t's own, [`crate::system::USERNAME`].
738/// Everything it does, people see g1t do.
739pub const AGENT_NAME: &str = crate::system::USERNAME;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace740
741// --- Staff ---------------------------------------------------------------
742//
743// Staff-only methods, for sudo.g1t.sh. They take no viewer and check no
744// membership: only sudo calls them, over its service binding, after it has
745// verified a Cloudflare Access sign-in and its staff list. Nothing a
746// customer can reach should ever forward to them.
747
748/// `notify_owners`: emails a short notice, with one link, to each owner of
749/// a workspace with a confirmed address. Called by other services (billing
750/// warns owners near their usage limit), never on a person's behalf.
751/// Returns how many were sent.
752#[derive(Clone, Debug, Serialize, Deserialize)]
753pub struct NotifyOwnersArgs {
754 pub workspace: String,
755 pub subject: String,
756 /// One or two sentences: what happened and what it means.
757 pub intro: String,
758 /// The button's words, such as `Open billing`.
759 pub action: String,
760 /// Where the button goes; must be on g1t.sh.
761 pub link: String,
762 /// Small print: why they got it.
763 pub footer: String,
764}
765
766/// `admin_workspaces`: every workspace, newest first, at most
767/// [`ADMIN_WORKSPACES_LIMIT`], optionally only those whose slug, name or
768/// an owner's username or email contains `query`. Returns
769/// `Vec<AdminWorkspace>`. Staff only.
770#[derive(Debug, Default, Serialize, Deserialize)]
771pub struct AdminWorkspacesArgs {
772 #[serde(default)]
773 pub query: Option<String>,
774}
775
776/// The most workspaces one `admin_workspaces` call returns.
777pub const ADMIN_WORKSPACES_LIMIT: usize = 500;
778
779/// An owner of a workspace, as staff see them.
780#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
781pub struct AdminOwner {
782 pub username: String,
783 pub email: Option<String>,
784}
785
786/// A workspace as staff see it: who owns it and how many belong to it.
787#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
788#[serde(rename_all = "camelCase")]
789pub struct AdminWorkspace {
790 pub slug: String,
791 pub name: String,
792 /// RFC 3339.
793 pub created_at: String,
794 pub owners: Vec<AdminOwner>,
795 pub member_count: u32,
796}
797
798/// `admin_workspace`: one workspace with every member, or null. Takes
799/// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only.
800#[derive(Clone, Debug, Serialize, Deserialize)]
801#[serde(rename_all = "camelCase")]
802pub struct AdminWorkspaceDetail {
803 pub slug: String,
804 pub name: String,
805 pub description: Option<String>,
806 /// RFC 3339.
807 pub created_at: String,
808 /// Owners first, then by username.
809 pub members: Vec<AdminMember>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member810 /// It can never be deleted ([`protected_names`]).
811 #[serde(default)]
812 pub protected: bool,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace813}
814
815/// A member of a workspace, as staff see them.
816#[derive(Clone, Debug, Serialize, Deserialize)]
817pub struct AdminMember {
818 pub username: String,
819 pub email: Option<String>,
820 pub role: crate::Role,
821 /// When they joined the workspace. RFC 3339.
822 pub joined: String,
823}
Agents and memory, checks and conflicts, profiles, slug renames, custom domains824
825// --- Profiles ------------------------------------------------------------
826//
827// A person's public page at `g1t.sh/u/<username>`. Everything in a
828// `Profile` is shown to anyone, signed in or not; an email address never is.
829
830/// The most characters each profile field takes.
831pub const MAX_PROFILE_NAME: usize = 80;
832pub const MAX_PROFILE_BIO: usize = 160;
833pub const MAX_PROFILE_LOCATION: usize = 80;
834pub const MAX_PROFILE_WEBSITE: usize = 200;
835pub const MAX_PROFILE_PRONOUNS: usize = 40;
836
837/// What anyone may see about a person.
838#[derive(Clone, Debug, Default, Serialize, Deserialize)]
839#[serde(rename_all = "camelCase")]
840pub struct Profile {
841 pub username: String,
842 /// The name they go by, if they gave one.
843 pub name: Option<String>,
844 /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters.
845 pub bio: Option<String>,
846 pub location: Option<String>,
847 /// An `https://` address.
848 pub website: Option<String>,
849 pub pronouns: Option<String>,
850 /// The uploaded avatar's hash, served at `/avatars/<avatar>`.
851 pub avatar: Option<String>,
852 /// When the account was made. RFC 3339.
853 pub created_at: String,
854}
855
856// `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for
857// an account that does not exist.
858
859/// `update_profile`: a person changes their own profile. Every field is
860/// replaced; an empty one is cleared. Returns `Outcome<Profile>`.
861#[derive(Debug, Default, Serialize, Deserialize)]
862#[serde(rename_all = "camelCase")]
863pub struct UpdateProfileArgs {
864 pub actor: User,
865 #[serde(default)]
866 pub name: String,
867 #[serde(default)]
868 pub bio: String,
869 #[serde(default)]
870 pub location: String,
871 #[serde(default)]
872 pub website: String,
873 #[serde(default)]
874 pub pronouns: String,
875}
876
877/// `profile_workspaces`: the workspaces shown on a person's profile, as
878/// `viewer` may see them. A membership is shown only when it is no secret
879/// from the viewer: a workspace the viewer belongs to as well, or one of
880/// `public`, the workspaces the caller found the person has made a public
881/// project in (whose page shows that already). Returns
882/// `Vec<ProfileWorkspace>`; empty for an account that does not exist.
883#[derive(Debug, Serialize, Deserialize)]
884pub struct ProfileWorkspacesArgs {
885 pub username: String,
886 pub viewer: crate::Viewer,
887 #[serde(default)]
888 pub public: Vec<String>,
889}
890
891/// A workspace on a person's profile.
892#[derive(Clone, Debug, Serialize, Deserialize)]
893pub struct ProfileWorkspace {
894 pub slug: String,
895 pub name: String,
896 pub avatar: Option<String>,
897}
Search across all of g1t, Explore, and a command palette898
899/// `directory`: every account or every workspace, as their public pages
900/// show them, a page at a time in name order. For services that index
901/// them, such as search; nothing private is in it. Returns
902/// `DirectoryPage`.
903#[derive(Debug, Default, Serialize, Deserialize)]
904pub struct DirectoryArgs {
905 /// `user` or `workspace`.
906 pub kind: String,
907 /// Names after this one.
908 #[serde(default)]
909 pub after: Option<String>,
910 pub limit: u32,
911}
912
913/// One account or workspace in the directory.
914#[derive(Clone, Debug, Serialize, Deserialize)]
915#[serde(rename_all = "camelCase")]
916pub struct DirectoryEntry {
917 /// The account's or workspace's id.
918 pub id: String,
919 /// A username or a workspace's slug.
920 pub slug: String,
921 /// A person's display name or a workspace's name.
922 pub name: Option<String>,
923 /// A person's bio or a workspace's description.
924 pub bio: Option<String>,
925 pub avatar: Option<String>,
926 /// RFC 3339.
927 pub created_at: String,
928}
929
930#[derive(Clone, Debug, Default, Serialize, Deserialize)]
931pub struct DirectoryPage {
932 pub entries: Vec<DirectoryEntry>,
933 /// Where the next page starts; null on the last.
934 pub next: Option<String>,
935}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look936
937// --- Invites ---------------------------------------------------------------
938//
939// While registration is invite-only, every new account (with a password or
940// through GitHub) needs an invite code. Each person may have
941// `INVITES_PER_USER` invites out at a time; staff grant more to a person or
942// to a workspace, whose owners share them. Inviting an email with no
943// account into a workspace makes an invite bound to that address, which
944// registers and joins in one step. See services/identity/src/invites.rs.
945
946/// Whether anyone may make an account, or only someone with an invite. Set
947/// by identity's `REGISTRATION_MODE` var; anything but `open`, including
948/// leaving it unset, is `invite`, so a missing setting never opens sign-up.
949#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
950#[serde(rename_all = "snake_case")]
951pub enum RegistrationMode {
952 #[default]
953 Invite,
954 Open,
955}
956
957impl RegistrationMode {
958 pub fn parse(text: Option<&str>) -> RegistrationMode {
959 match text.map(|text| text.trim().to_ascii_lowercase()).as_deref() {
960 Some("open") => RegistrationMode::Open,
961 _ => RegistrationMode::Invite,
962 }
963 }
964}
965
966/// How many invites a person may have out at once, unless identity's
967/// `INVITES_PER_USER` var says otherwise.
968pub const INVITES_PER_USER: u32 = 5;
969
970/// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says
971/// otherwise.
972pub const INVITE_TTL_DAYS: u64 = 30;
973
974/// Where an invite stands. Only a pending invite can be used or revoked.
975/// An expired or revoked invite that was never used gives its inviter the
976/// invite back.
977#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
978#[serde(rename_all = "snake_case")]
979pub enum InviteStatus {
980 Pending,
981 Redeemed,
982 Expired,
983 Revoked,
984}
985
986/// What using an invite does.
987#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
988#[serde(rename_all = "snake_case")]
989pub enum InviteKind {
990 /// Makes a new account, and joins `workspace` when one is set.
991 Account,
992 /// An existing account joins `workspace`. Never makes an account.
993 Workspace,
994}
995
996/// Whose allowance an invite uses.
997#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
998#[serde(rename_all = "snake_case")]
999pub enum InviteCharge {
1000 /// Its inviter's own.
1001 User,
1002 /// The workspace's, granted by staff and shared by its owners.
1003 Workspace,
1004 /// Nobody's: staff minted it, or it invites an existing account.
1005 None,
1006}
1007
1008/// One invite, as the person who made it sees it.
1009#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1010#[serde(rename_all = "camelCase")]
1011pub struct Invite {
1012 pub id: String,
1013 /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite
1014 /// is made, and afterwards to whoever made it while it is pending.
1015 /// Null otherwise.
1016 pub code: Option<String>,
1017 /// The code's first group, such as `g1t-k7m2`, to recognise it by.
1018 pub hint: String,
1019 /// Only an account with this address can use it. Null: anyone with
1020 /// the code.
1021 pub email: Option<String>,
1022 pub kind: InviteKind,
1023 /// The workspace it joins, by slug.
1024 pub workspace: Option<String>,
1025 pub status: InviteStatus,
1026 pub charged_to: InviteCharge,
1027 /// Who made it, by username. Null when g1t staff did.
1028 pub invited_by: Option<String>,
1029 /// The account that used it, by username.
1030 pub redeemed_by: Option<String>,
1031 /// RFC 3339.
1032 pub created_at: String,
1033 /// RFC 3339.
1034 pub expires_at: String,
1035 /// RFC 3339.
1036 pub redeemed_at: Option<String>,
1037 /// RFC 3339.
1038 pub revoked_at: Option<String>,
1039 /// The staff member who minted it. Only in staff views.
1040 #[serde(default, skip_serializing_if = "Option::is_none")]
1041 pub staff: Option<String>,
1042}
1043
1044/// How many invites someone may have out, and how many they have.
1045#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1046pub struct Allowance {
1047 /// Null: no limit.
1048 pub limit: Option<u32>,
1049 /// Pending and used invites; revoked and expired ones are not counted.
1050 pub used: u32,
1051 /// Null: no limit.
1052 pub remaining: Option<u32>,
1053}
1054
1055impl Allowance {
1056 pub fn new(limit: Option<u32>, used: u32) -> Allowance {
1057 Allowance {
1058 limit,
1059 used,
1060 remaining: limit.map(|limit| limit.saturating_sub(used)),
1061 }
1062 }
1063
1064 pub fn exhausted(&self) -> bool {
1065 self.remaining == Some(0)
1066 }
1067}
1068
1069/// A workspace's shared invites, for one of its owners.
1070#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1071pub struct WorkspaceAllowance {
1072 pub slug: String,
1073 pub allowance: Allowance,
1074}
1075
1076/// `list_invites` (takes `UserArgs`): a person's invites, newest first,
1077/// and what they have left. Returns `InvitesOverview`.
1078#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1079pub struct InvitesOverview {
1080 pub mode: RegistrationMode,
1081 pub allowance: Allowance,
1082 /// Workspaces the person owns that staff granted invites to.
1083 pub workspaces: Vec<WorkspaceAllowance>,
1084 pub invites: Vec<Invite>,
1085}
1086
1087/// `create_invite`: a person makes an invite, optionally for one email
1088/// address. People only; never an agent or a workspace's token, and not
1089/// before their email is confirmed. Uses one of the person's invites, or,
1090/// with `workspace`, one of the invites staff granted that workspace (its
1091/// owners only). Emails the address when one is given. Returns
1092/// `Outcome<Invite>`, with the code.
1093///
1094/// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending
1095/// invite; a workspace's owners may revoke one made for the workspace.
1096/// The invite comes back to whoever it was charged to. Returns
1097/// `Outcome<Invite>`.
1098#[derive(Debug, Serialize, Deserialize)]
1099pub struct CreateInviteArgs {
1100 pub user: User,
1101 #[serde(default)]
1102 pub email: Option<String>,
1103 /// Use this workspace's granted invites, by slug.
1104 #[serde(default)]
1105 pub workspace: Option<String>,
1106 /// Where the request came in, for the audit log; g1t.sh when absent.
1107 #[serde(default)]
1108 pub surface: Option<crate::audit::Surface>,
1109}
1110
1111/// `check_invite`: what an invite code is for, before using it. Returns
1112/// `Outcome<InvitePreview>`; a code that is unknown, used, revoked or
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1113/// expired gets the same answer, so codes cannot be probed. With
1114/// `any_status`, a real code that can no longer be used is described
1115/// instead (its `status` says why), so the page can say whom to ask for a
1116/// new one; an unknown code still gets the one answer.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1117#[derive(Debug, Serialize, Deserialize)]
1118pub struct InviteCodeArgs {
1119 pub code: String,
1120 /// Who is asking, such as the visitor's IP address, for rate limits.
1121 #[serde(default)]
1122 pub client: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1123 /// Who is looking, if signed in: sets `InvitePreview::for_viewer`.
1124 #[serde(default)]
1125 pub viewer: Option<User>,
1126 #[serde(default)]
1127 pub any_status: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1128}
1129
1130/// Someone shown on an invite.
1131#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1132pub struct InviteFrom {
1133 pub username: String,
1134 pub name: Option<String>,
1135 pub avatar: Option<String>,
1136}
1137
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1138/// A repository an invite code was sent with: using the code accepts the
1139/// invitation to collaborate on it.
1140#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1141pub struct InviteRepository {
1142 /// `workspace/repo`.
1143 pub name: String,
1144 /// The role it gives, such as `write`.
1145 pub role: String,
1146}
1147
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1148/// What a valid invite code is for.
1149#[derive(Clone, Debug, Serialize, Deserialize)]
1150#[serde(rename_all = "camelCase")]
1151pub struct InvitePreview {
1152 pub kind: InviteKind,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1153 /// Pending, unless `any_status` asked about a code that is spent.
1154 pub status: InviteStatus,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1155 /// Null when g1t staff sent it.
1156 pub invited_by: Option<InviteFrom>,
1157 pub workspace: Option<ProfileWorkspace>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1158 /// The repository it accepts an invitation to, if it was sent with one.
1159 pub repository: Option<InviteRepository>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1160 /// The address it is for, partly hidden, such as `a•••@example.com`.
1161 pub email: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1162 /// The address in full, while it is pending: whoever holds the code
1163 /// was sent it there. Fills in and locks the sign-up form.
1164 pub address: Option<String>,
1165 /// Whether the address it is for has a g1t account already, so the
1166 /// page asks them to sign in rather than sign up.
1167 pub has_account: bool,
1168 /// With a viewer: whether the invite is theirs (it is for one of their
1169 /// confirmed addresses, or they used it). Null without a viewer or,
1170 /// for a pending invite, when it is for anyone with the code.
1171 pub for_viewer: Option<bool>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1172 /// RFC 3339.
1173 pub expires_at: String,
1174}
1175
1176/// `accept_invite`: a signed-in person uses a workspace invite made for
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1177/// their confirmed address, and joins the workspace, or an invite sent with
1178/// a repository invitation, and accepts it. Returns `Outcome<String>`: the
1179/// workspace's slug, or `workspace/repo`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1180#[derive(Debug, Serialize, Deserialize)]
1181pub struct AcceptInviteArgs {
1182 pub user: User,
1183 pub code: String,
1184}
1185
1186/// `invite_member`: an owner invites an email address into a workspace.
1187/// It always makes an invite bound to that address and emails it, so the
1188/// answer never says whether the address has an account. Without one, the
1189/// invite registers and joins in one step, and uses one of the workspace's
1190/// granted invites or else one of the owner's own. With one, it costs
1191/// nothing. Returns `Outcome<Invite>`, with the code.
1192#[derive(Debug, Serialize, Deserialize)]
1193pub struct InviteMemberArgs {
1194 pub actor: User,
1195 pub slug: String,
1196 pub email: String,
1197 /// Where the request came in, for the audit log; g1t.sh when absent.
1198 #[serde(default)]
1199 pub surface: Option<crate::audit::Surface>,
1200}
1201
1202/// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites,
1203/// newest first. Owners only. Returns `Outcome<Vec<Invite>>`.
1204///
1205/// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`.
1206#[derive(Debug, Serialize, Deserialize)]
1207pub struct WorkspaceInviteArgs {
1208 pub actor: User,
1209 pub slug: String,
1210 pub id: String,
1211}
1212
1213/// `request_access`: someone without an invite asks for one. Kept on the
1214/// waitlist, one entry per address. Answers the same way whether or not
1215/// the address is already on it. Returns `Outcome<bool>`.
1216#[derive(Debug, Default, Serialize, Deserialize)]
1217pub struct RequestAccessArgs {
1218 pub email: String,
1219 /// What they will build, if they said.
1220 #[serde(default)]
1221 pub about: String,
1222 /// Who is asking, such as the visitor's IP address, for rate limits.
1223 #[serde(default)]
1224 pub client: Option<String>,
1225}
1226
1227/// The most characters `RequestAccessArgs::about` keeps.
1228pub const MAX_WAITLIST_ABOUT: usize = 1000;
1229
1230// `registration` takes `{}` and returns `RegistrationMode`.
1231
1232// --- Invites, staff only ---
1233
1234#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1235#[serde(rename_all = "snake_case")]
1236pub enum WaitlistStatus {
1237 Waiting,
1238 Invited,
1239 Dismissed,
1240}
1241
1242impl WaitlistStatus {
1243 pub fn as_str(self) -> &'static str {
1244 match self {
1245 WaitlistStatus::Waiting => "waiting",
1246 WaitlistStatus::Invited => "invited",
1247 WaitlistStatus::Dismissed => "dismissed",
1248 }
1249 }
1250}
1251
1252/// Someone who asked for access.
1253#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1254#[serde(rename_all = "camelCase")]
1255pub struct WaitlistEntry {
1256 pub id: String,
1257 pub email: String,
1258 pub about: Option<String>,
1259 pub status: WaitlistStatus,
1260 pub invite_id: Option<String>,
1261 pub decided_by: Option<String>,
1262 /// RFC 3339.
1263 pub decided_at: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1264 /// What staff wrote when approving; it went in the invite email.
1265 #[serde(default)]
1266 pub note: Option<String>,
1267 /// The account made with the invite, once it was used.
1268 #[serde(default)]
1269 pub joined_as: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1270 /// When they first asked. RFC 3339.
1271 pub created_at: String,
1272 /// When they last asked. RFC 3339.
1273 pub updated_at: String,
1274}
1275
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1276/// `admin_waitlist`: the waitlist, newest first, at most
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1277/// [`ADMIN_INVITES_LIMIT`]. Returns `Vec<WaitlistEntry>`.
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1278///
1279/// `admin_waitlist_pending` takes `{}` and returns the number of requests
1280/// still waiting, for sudo's navigation.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1281#[derive(Debug, Default, Serialize, Deserialize)]
1282pub struct AdminWaitlistArgs {
1283 /// Part of an email address or of what they said.
1284 #[serde(default)]
1285 pub query: Option<String>,
1286 /// Null: every status.
1287 #[serde(default)]
1288 pub status: Option<WaitlistStatus>,
1289}
1290
1291/// The most rows one staff listing of invites or the waitlist returns.
1292pub const ADMIN_INVITES_LIMIT: usize = 500;
1293
1294/// `admin_decide_waitlist`: approving mints an invite bound to the
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1295/// address, charged to nobody, and emails it, with `note` if given;
1296/// dismissing only marks the entry. Returns `Outcome<WaitlistEntry>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1297#[derive(Debug, Serialize, Deserialize)]
1298pub struct AdminDecideWaitlistArgs {
1299 pub id: String,
1300 pub approve: bool,
1301 /// The staff member, by email.
1302 pub staff: String,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1303 /// A line for the invite email, up to [`MAX_WAITLIST_NOTE`] characters.
1304 #[serde(default)]
1305 pub note: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1306}
1307
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1308/// The most characters an approval's note keeps.
1309pub const MAX_WAITLIST_NOTE: usize = 500;
1310
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1311/// `admin_invites`: every invite, newest first, at most
1312/// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with
1313/// `query`, or whose email, inviter or redeemer contains it. Returns
1314/// `Vec<Invite>`.
1315#[derive(Debug, Default, Serialize, Deserialize)]
1316pub struct AdminInvitesArgs {
1317 #[serde(default)]
1318 pub query: Option<String>,
1319}
1320
1321/// `admin_revoke_invite`: revokes any pending invite. Returns
1322/// `Outcome<Invite>`.
1323#[derive(Debug, Serialize, Deserialize)]
1324pub struct AdminRevokeInviteArgs {
1325 pub id: String,
1326 pub staff: String,
1327}
1328
1329/// `admin_mint_invite`: staff make an invite that uses nobody's
1330/// allowance, optionally bound to (and emailed to) an address. Returns
1331/// `Outcome<Invite>`, with the code.
1332#[derive(Debug, Serialize, Deserialize)]
1333pub struct AdminMintInviteArgs {
1334 #[serde(default)]
1335 pub email: Option<String>,
1336 pub staff: String,
1337}
1338
1339/// Who staff grant invites to.
1340#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1341#[serde(rename_all = "snake_case")]
1342pub enum GrantTarget {
1343 User,
1344 Workspace,
1345}
1346
1347impl GrantTarget {
1348 pub fn as_str(self) -> &'static str {
1349 match self {
1350 GrantTarget::User => "user",
1351 GrantTarget::Workspace => "workspace",
1352 }
1353 }
1354}
1355
1356/// `admin_grant_invites`: gives a person (by username) or a workspace (by
1357/// slug) `amount` more invites; a negative amount takes some back. Returns
1358/// `Outcome<Allowance>`: theirs afterwards.
1359#[derive(Debug, Serialize, Deserialize)]
1360pub struct AdminGrantInvitesArgs {
1361 pub target: GrantTarget,
1362 pub name: String,
1363 pub amount: i32,
1364 #[serde(default)]
1365 pub note: String,
1366 pub staff: String,
1367}
1368
1369/// The most invites one grant gives or takes back.
1370pub const MAX_INVITE_GRANT: i32 = 1000;
1371
1372/// Invites staff granted.
1373#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1374#[serde(rename_all = "camelCase")]
1375pub struct InviteGrant {
1376 pub amount: i32,
1377 pub note: Option<String>,
1378 pub granted_by: String,
1379 /// RFC 3339.
1380 pub created_at: String,
1381}
1382
1383/// Someone a person invited, and whom they invited in turn.
1384#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1385#[serde(rename_all = "camelCase")]
1386pub struct InviteTreeNode {
1387 pub username: String,
1388 /// When they used the invite. RFC 3339.
1389 pub joined_at: String,
1390 pub invited: Vec<InviteTreeNode>,
1391}
1392
1393/// `admin_invite_tree` (takes `UsernameArgs`): where a person came from
1394/// and whom they brought, for tracing abuse. Returns `Option<InviteTree>`.
1395///
1396/// `admin_workspace_invites` (takes `SlugArgs`): a workspace's granted
1397/// invites, grants and invites. Returns `Option<InviteTree>` with
1398/// `username` the slug and no `invited_by`.
1399#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1400#[serde(rename_all = "camelCase")]
1401pub struct InviteTree {
1402 pub username: String,
1403 /// Who invited them, then who invited that person, and so on. Empty
1404 /// for an account made without an invite.
1405 pub invited_by: Vec<String>,
1406 /// The staff member who minted their invite, when staff did.
1407 pub staff: Option<String>,
1408 pub allowance: Allowance,
1409 pub grants: Vec<InviteGrant>,
1410 /// Their invites, newest first.
1411 pub invites: Vec<Invite>,
1412 /// Whom they invited, three levels down.
1413 pub invited: Vec<InviteTreeNode>,
1414}
1415
1416#[cfg(test)]
1417mod deletion_tests {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1418 use super::{WorkspaceDeletion, protected_names};
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1419
1420 #[test]
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1421 fn only_billing_or_protection_stands_in_the_way() {
1422 let clear = WorkspaceDeletion {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1423 repositories: 2,
1424 projects: 1,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1425 members: 3,
1426 ..WorkspaceDeletion::default()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1427 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1428 assert!(!clear.blocked());
1429 assert_eq!(clear.reason("acme"), None);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1430 let owing = WorkspaceDeletion {
1431 billing: Some("Pay first.".into()),
1432 ..WorkspaceDeletion::default()
1433 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1434 assert!(owing.blocked());
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1435 assert_eq!(owing.reason("acme").as_deref(), Some("Pay first."));
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1436 let protected = WorkspaceDeletion {
1437 billing: Some("Pay first.".into()),
1438 protected: true,
1439 ..WorkspaceDeletion::default()
1440 };
1441 assert!(protected.blocked());
1442 assert_eq!(
1443 protected.reason("flagon-io").as_deref(),
1444 Some("flagon-io is protected and can never be deleted.")
1445 );
1446 }
1447
1448 #[test]
1449 fn flagon_is_protected_whatever_the_variable_says() {
1450 assert_eq!(protected_names(None), ["flagon-io"]);
1451 assert_eq!(protected_names(Some("")), ["flagon-io"]);
1452 assert_eq!(protected_names(Some(" , ")), ["flagon-io"]);
1453 assert_eq!(
1454 protected_names(Some("Flagon-IO, acme ,wsp_1")),
1455 ["flagon-io", "acme", "wsp_1"]
1456 );
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1457 }
1458}

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