Skip to content
288 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

API and MCP server, Rust identity service, registration, site redesign1//! Types and service interfaces shared by every g1t service.
2//!
3//! Each service has a module here holding the data it exchanges and the
4//! arguments of each of its methods. Services and their callers depend on
5//! this crate, never on each other's code.
6
Merge branch 'main' into worktree-agent-a69aeabc4b0deeb977pub mod about;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look8pub mod access;
Merge account deletion: soft delete for 30 days, staff restore and purge, ghost for what remains (identity 0037)9pub mod account_deletion;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look10pub mod accounts;
GitHub Actions on g1t, part two: running workflows11pub mod actions;
Agents and memory, checks and conflicts, profiles, slug renames, custom domains12pub mod agents;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API13pub mod audit;
Merge branch 'worktree-agent-ac5b181a013e54348'14pub mod backups;
Agents as a team: lifecycle, merge queue, billing and a new shell15pub mod billing;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API16pub mod capture;
Merge checks: statuses and check runs on every commit17pub mod checks;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar18pub mod codeowners;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API19pub mod credentials;
Merge branch 'worktree-agent-a5a5de74d8863d554' into worktree-agent-a16631325aecf58ca20pub mod deploy_keys;
Rust repos service with shipping; pull requests kept in the model21pub mod events;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look22pub mod github;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API23pub mod guardrails;
API and MCP server, Rust identity service, registration, site redesign24pub mod identity;
Inbox: the events service tells people what needs them as events arrive25pub mod inbox;
Integrations: your own model provider, alerts that open issues, tickets agents read26pub mod integrations;
Merge main (membership, two-factor, GitHub repo roles) into tokens27pub mod members;
Mirroring core: one leader per repository, standby mirrors, takeover and hand-back28pub mod mirrors;
API and MCP server, Rust identity service, registration, site redesign29mod ids;
30mod names;
31mod outcome;
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member32pub mod packages;
Projects: what a workspace builds and runs, first on every page33pub mod projects;
Rust repos service with shipping; pull requests kept in the model34pub mod repos;
Merge rulesets: branch and tag rules, agent-first, enforced on push and merge35pub mod rules;
Fast pages, required checks on the branch, self-hosted runners, honest incidents36pub mod runners;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step37pub mod scopes;
Search across all of g1t, Explore, and a command palette38pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API39pub mod security;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar40pub mod teams;
41pub mod security_suite;
Merge main into mirroring: remotes migration becomes integrations 000742pub mod subscribers;
RFC 3339 timestamps in identity and repos43pub mod time;
Fine-grained personal tokens, workspace token rules and approvals in identity44pub mod tokens;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar45pub mod updates;
Webhooks: every event, to your own addresses, signed and retried46pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps47pub mod work;
API and MCP server, Rust identity service, registration, site redesign48
49pub use ids::new_id;
Merge branch 'worktree-agent-a8385d293d42c913a'50pub use names::{
Merge branch 'fast-push' into mirroring51 Username, aliasable_name, claimable_namespace, claimable_username, is_namespace_shaped, is_reserved_name, is_route_name,
52 is_valid_namespace, is_valid_repo_name,
Merge branch 'worktree-agent-a8385d293d42c913a'53};
API and MCP server, Rust identity service, registration, site redesign54pub use outcome::{Failure, FailureCode, Outcome};
55
56use serde::{Deserialize, Serialize};
57
Merge main (membership, two-factor, GitHub repo roles) into tokens58/// What a member may do in a workspace. A member may also hold
59/// [`members::OrgRole`]s, which add to it.
Workspaces own repositories60#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
61#[serde(rename_all = "lowercase")]
62pub enum Role {
Merge main (membership, two-factor, GitHub repo roles) into tokens63 /// Everything: Admin on every repository, the workspace's members,
64 /// settings, billing and security.
Workspaces own repositories65 Owner,
Merge main (membership, two-factor, GitHub repo roles) into tokens66 /// The workspace's base permission on each repository, and what its
67 /// member privileges allow (see [`members::MemberPrivileges`]).
Workspaces own repositories68 Member,
69}
70
Merge main (membership, two-factor, GitHub repo roles) into tokens71pub use members::{MemberPrivileges, OrgRole};
72
Workspaces own repositories73/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign74#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories75pub struct Membership {
76 /// The workspace's name in URLs: `g1t.sh/<slug>`.
77 pub slug: String,
78 pub role: Role,
Workspace names and icons, and a component kit for every control79 /// The workspace's display name, for showing it to people. Set when a
80 /// user is resolved from credentials; absent on principals made up by
81 /// a service.
82 #[serde(default, skip_serializing_if = "Option::is_none")]
83 pub name: Option<String>,
84 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
85 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
86 #[serde(default, skip_serializing_if = "Option::is_none")]
87 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look88 /// What a member gets on each of the workspace's repositories: the
89 /// workspace's base permission. Set when a user is resolved from
90 /// credentials; absent means the default, Write. Owners have Admin
91 /// whatever it says. See [`access`].
92 #[serde(default, skip_serializing_if = "Option::is_none")]
93 pub base_permission: Option<access::BasePermission>,
Merge branch 'worktree-agent-ad7c6d88d93adc817'94 /// Who may create the workspace's teams. Set when a user is resolved
95 /// from credentials; absent means the default, any member. See
96 /// [`teams::TeamCreation`].
97 #[serde(default, skip_serializing_if = "Option::is_none")]
98 pub team_creation: Option<teams::TeamCreation>,
Merge main (membership, two-factor, GitHub repo roles) into tokens99 /// The roles the member holds besides `role`: billing manager,
100 /// security manager. Set when a user is resolved from credentials.
101 #[serde(default, skip_serializing_if = "Vec::is_empty")]
102 pub org_roles: Vec<OrgRole>,
103 /// What the workspace lets members (and repository admins) do. Set
104 /// when a user is resolved from credentials; absent means the
105 /// defaults. See [`members::MemberPrivileges`].
106 #[serde(default, skip_serializing_if = "Option::is_none")]
107 pub privileges: Option<MemberPrivileges>,
Workspaces own repositories108}
109
Workspace names and icons, and a component kit for every control110impl Membership {
111 /// A plain member of `slug`, as services act inside one workspace.
112 pub fn member(slug: impl Into<String>) -> Self {
113 Membership {
114 slug: slug.into(),
115 role: Role::Member,
116 name: None,
117 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look118 base_permission: None,
Merge branch 'worktree-agent-ad7c6d88d93adc817'119 team_creation: None,
Merge main (membership, two-factor, GitHub repo roles) into tokens120 org_roles: Vec::new(),
121 privileges: None,
Workspace names and icons, and a component kit for every control122 }
123 }
Merge main (membership, two-factor, GitHub repo roles) into tokens124
125 /// Whether the member holds `role` besides owner or member.
126 pub fn has(&self, role: OrgRole) -> bool {
127 self.org_roles.contains(&role)
128 }
Workspace names and icons, and a component kit for every control129}
130
Agents as a team: lifecycle, merge queue, billing and a new shell131/// What a set of credentials resolved to.
132#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
133#[serde(rename_all = "lowercase")]
134pub enum PrincipalKind {
135 /// A person's account.
136 #[default]
137 User,
138 /// A workspace, acting through one of its own access tokens. Its `id`
139 /// is the workspace's, its `username` the workspace's slug, and it is a
140 /// member of that workspace and no other.
141 Workspace,
142 /// A g1t agent at work in a sandbox, acting through a token that lives
143 /// as long as its run and can do only what that token's scope lists, in
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent144 /// one repository. Its `username` is `g1t`.
Agents as a team: lifecycle, merge queue, billing and a new shell145 Agent,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily146 /// g1t itself: the platform acting on its own, as when it opens a
147 /// pull request to upgrade a vulnerable dependency or merges from the
148 /// queue. Never resolved from credentials: only services make one,
149 /// with [`User::system`]. Its `username` is `g1t`, which nobody can
150 /// register.
151 System,
152}
153
154/// g1t's own identity, as [`PrincipalKind::System`] work is recorded.
155pub mod system {
156 /// Its id wherever an author or actor id is stored.
157 pub const ID: &str = "g1t";
158 /// Its name, shown as the author of what it does.
159 pub const USERNAME: &str = "g1t";
160 /// The address on the commits it makes, which no mailbox receives.
161 pub const EMAIL: &str = "g1t@users.noreply.g1t.sh";
162 /// Ids that earlier versions stored for g1t's own actions, such as a
163 /// merge its settings made. Read as g1t too.
164 pub const LEGACY_IDS: [&str; 3] = ["g1t_policy", "svc_runner", "g1t_runner"];
165
166 /// Whether `id` is g1t's own.
167 pub fn is_system_id(id: &str) -> bool {
168 id == ID || LEGACY_IDS.contains(&id)
169 }
Agents as a team: lifecycle, merge queue, billing and a new shell170}
171
Workspaces own repositories172#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign173pub struct User {
174 pub id: String,
Merge branch 'fast-push' into mirroring175 /// Lowercased: what the person is found, linked and mentioned by.
API and MCP server, Rust identity service, registration, site redesign176 pub username: String,
Merge branch 'fast-push' into mirroring177 /// The username as its owner wrote it (`Ana`), when that differs from
178 /// `username`: what pages show. Set on the signed-in person and on
179 /// people looked up by name; absent elsewhere, where `username` is shown.
180 #[serde(default, skip_serializing_if = "Option::is_none")]
181 pub display_username: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell182 #[serde(default)]
183 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning184 /// Whether the account's email address has been confirmed. Unverified
185 /// accounts can sign in but cannot create or change anything.
186 #[serde(default)]
187 pub verified: bool,
Workspaces own repositories188 /// The workspaces this user belongs to. Filled in when a user is
189 /// resolved from credentials, so any service can authorize from it.
190 #[serde(default)]
191 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control192 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
193 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
194 #[serde(default, skip_serializing_if = "Option::is_none")]
195 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API196 /// Set on an agent resolved from its token: who it acts for, with which
197 /// credential, and what it may do. See [`credentials`].
198 #[serde(default, skip_serializing_if = "Option::is_none")]
199 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look200 /// The repositories this user has been given a role on directly,
201 /// whether or not they belong to its workspace. Filled in with
202 /// `workspaces`; see [`access`].
203 #[serde(default, skip_serializing_if = "Vec::is_empty")]
204 pub grants: Vec<access::RepoGrant>,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step205 /// Set on a user resolved from an access token: its scopes and the
206 /// workspaces or repositories it is limited to. Absent on a signed-in
207 /// session and on an agent (whose `acting` scope applies instead).
208 /// See [`scopes`].
209 #[serde(default, skip_serializing_if = "Option::is_none")]
210 pub token: Option<Box<scopes::TokenAccess>>,
Merge main (membership, two-factor, GitHub repo roles) into tokens211 /// The workspaces this person belongs to but cannot use until they
212 /// meet its policy, such as turning on two-factor authentication.
213 /// They are left out of `workspaces` and `grants` meanwhile. Set when
214 /// a person is resolved from a session.
215 #[serde(default, skip_serializing_if = "Vec::is_empty")]
216 pub held: Vec<members::PolicyHold>,
Workspaces own repositories217}
218
219impl User {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily220 /// g1t itself, acting in `workspace`: what the platform's own work,
221 /// such as security updates, is done and recorded as.
222 pub fn system(workspace: &str) -> User {
223 User {
224 id: system::ID.to_owned(),
225 username: system::USERNAME.to_owned(),
226 kind: PrincipalKind::System,
227 verified: true,
228 workspaces: vec![Membership::member(workspace.to_lowercase())],
229 ..User::default()
230 }
231 }
232
233 /// Whether this is g1t itself.
234 pub fn is_system(&self) -> bool {
235 self.kind == PrincipalKind::System
236 }
237
Merge email confirmation gate: a code and a link, nothing until confirmed (identity 0036)238 /// Whether this is a person whose account has not confirmed its email
239 /// address. Such an account can only confirm it (or change it, or sign
240 /// out): the site, the API, MCP and git refuse it everything else
241 /// ([`accounts::confirm_email_first`]).
242 pub fn awaits_confirmation(&self) -> bool {
243 self.kind == PrincipalKind::User && !self.verified
244 }
245
Workspaces own repositories246 pub fn role_in(&self, slug: &str) -> Option<Role> {
247 self.workspaces
248 .iter()
249 .find(|membership| membership.slug == slug)
250 .map(|membership| membership.role)
251 }
252
253 pub fn is_member(&self, slug: &str) -> bool {
254 self.role_in(slug).is_some()
255 }
Merge main (membership, two-factor, GitHub repo roles) into tokens256
257 /// The membership in `slug`, if any.
258 pub fn membership(&self, slug: &str) -> Option<&Membership> {
259 self.workspaces.iter().find(|membership| membership.slug.eq_ignore_ascii_case(slug))
260 }
261
262 /// Whether this is a person who owns `slug`, or holds `role` in it.
263 pub fn owns_or_has(&self, slug: &str, role: OrgRole) -> bool {
264 self.membership(slug)
265 .is_some_and(|membership| membership.role == Role::Owner || membership.has(role))
266 }
267
268 /// Whether the user may manage `slug`'s billing: an owner or a billing
269 /// manager.
270 pub fn manages_billing(&self, slug: &str) -> bool {
271 self.owns_or_has(slug, OrgRole::BillingManager)
272 }
273
274 /// Whether the user may see and manage security across `slug`: an
275 /// owner or a security manager.
276 pub fn manages_security(&self, slug: &str) -> bool {
277 self.owns_or_has(slug, OrgRole::SecurityManager)
278 }
279
280 /// The workspace's member privileges as this user sees them: the
281 /// defaults when the membership does not say.
282 pub fn privileges_in(&self, slug: &str) -> MemberPrivileges {
283 self.membership(slug).and_then(|membership| membership.privileges).unwrap_or_default()
284 }
API and MCP server, Rust identity service, registration, site redesign285}
286
287/// Who is asking. Every read and write in every service takes one.
288pub type Viewer = Option<User>;

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