Skip to content
280 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;
9pub mod accounts;
GitHub Actions on g1t, part two: running workflows10pub mod actions;
Agents and memory, checks and conflicts, profiles, slug renames, custom domains11pub mod agents;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API12pub mod audit;
Merge branch 'worktree-agent-ac5b181a013e54348'13pub mod backups;
Agents as a team: lifecycle, merge queue, billing and a new shell14pub mod billing;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API15pub mod capture;
Merge checks: statuses and check runs on every commit16pub mod checks;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar17pub mod codeowners;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API18pub mod credentials;
Merge branch 'worktree-agent-a5a5de74d8863d554' into worktree-agent-a16631325aecf58ca19pub mod deploy_keys;
Rust repos service with shipping; pull requests kept in the model20pub mod events;
Workflow files need workflow_files:write from a token; fine-grained permission table21pub mod fine_grained;
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;
API and MCP server, Rust identity service, registration, site redesign28mod ids;
29mod names;
30mod outcome;
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member31pub mod packages;
Projects: what a workspace builds and runs, first on every page32pub mod projects;
Rust repos service with shipping; pull requests kept in the model33pub mod repos;
Merge rulesets: branch and tag rules, agent-first, enforced on push and merge34pub mod rules;
Fast pages, required checks on the branch, self-hosted runners, honest incidents35pub mod runners;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step36pub mod scopes;
Search across all of g1t, Explore, and a command palette37pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API38pub mod security;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar39pub mod teams;
40pub mod security_suite;
RFC 3339 timestamps in identity and repos41pub mod time;
Fine-grained personal tokens, workspace token rules and approvals in identity42pub mod tokens;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar43pub mod updates;
Webhooks: every event, to your own addresses, signed and retried44pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps45pub mod work;
API and MCP server, Rust identity service, registration, site redesign46
47pub use ids::new_id;
Merge branch 'worktree-agent-a8385d293d42c913a'48pub use names::{
49 aliasable_name, claimable_namespace, is_namespace_shaped, is_reserved_name, is_route_name, is_valid_namespace,
50 is_valid_repo_name,
51};
API and MCP server, Rust identity service, registration, site redesign52pub use outcome::{Failure, FailureCode, Outcome};
53
54use serde::{Deserialize, Serialize};
55
Merge main (membership, two-factor, GitHub repo roles) into tokens56/// What a member may do in a workspace. A member may also hold
57/// [`members::OrgRole`]s, which add to it.
Workspaces own repositories58#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
59#[serde(rename_all = "lowercase")]
60pub enum Role {
Merge main (membership, two-factor, GitHub repo roles) into tokens61 /// Everything: Admin on every repository, the workspace's members,
62 /// settings, billing and security.
Workspaces own repositories63 Owner,
Merge main (membership, two-factor, GitHub repo roles) into tokens64 /// The workspace's base permission on each repository, and what its
65 /// member privileges allow (see [`members::MemberPrivileges`]).
Workspaces own repositories66 Member,
67}
68
Merge main (membership, two-factor, GitHub repo roles) into tokens69pub use members::{MemberPrivileges, OrgRole};
70
Workspaces own repositories71/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign72#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories73pub struct Membership {
74 /// The workspace's name in URLs: `g1t.sh/<slug>`.
75 pub slug: String,
76 pub role: Role,
Workspace names and icons, and a component kit for every control77 /// The workspace's display name, for showing it to people. Set when a
78 /// user is resolved from credentials; absent on principals made up by
79 /// a service.
80 #[serde(default, skip_serializing_if = "Option::is_none")]
81 pub name: Option<String>,
82 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
83 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
84 #[serde(default, skip_serializing_if = "Option::is_none")]
85 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look86 /// What a member gets on each of the workspace's repositories: the
87 /// workspace's base permission. Set when a user is resolved from
88 /// credentials; absent means the default, Write. Owners have Admin
89 /// whatever it says. See [`access`].
90 #[serde(default, skip_serializing_if = "Option::is_none")]
91 pub base_permission: Option<access::BasePermission>,
Merge branch 'worktree-agent-ad7c6d88d93adc817'92 /// Who may create the workspace's teams. Set when a user is resolved
93 /// from credentials; absent means the default, any member. See
94 /// [`teams::TeamCreation`].
95 #[serde(default, skip_serializing_if = "Option::is_none")]
96 pub team_creation: Option<teams::TeamCreation>,
Merge main (membership, two-factor, GitHub repo roles) into tokens97 /// The roles the member holds besides `role`: billing manager,
98 /// security manager. Set when a user is resolved from credentials.
99 #[serde(default, skip_serializing_if = "Vec::is_empty")]
100 pub org_roles: Vec<OrgRole>,
101 /// What the workspace lets members (and repository admins) do. Set
102 /// when a user is resolved from credentials; absent means the
103 /// defaults. See [`members::MemberPrivileges`].
104 #[serde(default, skip_serializing_if = "Option::is_none")]
105 pub privileges: Option<MemberPrivileges>,
Workspaces own repositories106}
107
Workspace names and icons, and a component kit for every control108impl Membership {
109 /// A plain member of `slug`, as services act inside one workspace.
110 pub fn member(slug: impl Into<String>) -> Self {
111 Membership {
112 slug: slug.into(),
113 role: Role::Member,
114 name: None,
115 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look116 base_permission: None,
Merge branch 'worktree-agent-ad7c6d88d93adc817'117 team_creation: None,
Merge main (membership, two-factor, GitHub repo roles) into tokens118 org_roles: Vec::new(),
119 privileges: None,
Workspace names and icons, and a component kit for every control120 }
121 }
Merge main (membership, two-factor, GitHub repo roles) into tokens122
123 /// Whether the member holds `role` besides owner or member.
124 pub fn has(&self, role: OrgRole) -> bool {
125 self.org_roles.contains(&role)
126 }
Workspace names and icons, and a component kit for every control127}
128
Agents as a team: lifecycle, merge queue, billing and a new shell129/// What a set of credentials resolved to.
130#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
131#[serde(rename_all = "lowercase")]
132pub enum PrincipalKind {
133 /// A person's account.
134 #[default]
135 User,
136 /// A workspace, acting through one of its own access tokens. Its `id`
137 /// is the workspace's, its `username` the workspace's slug, and it is a
138 /// member of that workspace and no other.
139 Workspace,
140 /// A g1t agent at work in a sandbox, acting through a token that lives
141 /// 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-agent142 /// one repository. Its `username` is `g1t`.
Agents as a team: lifecycle, merge queue, billing and a new shell143 Agent,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily144 /// g1t itself: the platform acting on its own, as when it opens a
145 /// pull request to upgrade a vulnerable dependency or merges from the
146 /// queue. Never resolved from credentials: only services make one,
147 /// with [`User::system`]. Its `username` is `g1t`, which nobody can
148 /// register.
149 System,
150}
151
152/// g1t's own identity, as [`PrincipalKind::System`] work is recorded.
153pub mod system {
154 /// Its id wherever an author or actor id is stored.
155 pub const ID: &str = "g1t";
156 /// Its name, shown as the author of what it does.
157 pub const USERNAME: &str = "g1t";
158 /// The address on the commits it makes, which no mailbox receives.
159 pub const EMAIL: &str = "g1t@users.noreply.g1t.sh";
160 /// Ids that earlier versions stored for g1t's own actions, such as a
161 /// merge its settings made. Read as g1t too.
162 pub const LEGACY_IDS: [&str; 3] = ["g1t_policy", "svc_runner", "g1t_runner"];
163
164 /// Whether `id` is g1t's own.
165 pub fn is_system_id(id: &str) -> bool {
166 id == ID || LEGACY_IDS.contains(&id)
167 }
Agents as a team: lifecycle, merge queue, billing and a new shell168}
169
Workspaces own repositories170#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign171pub struct User {
172 pub id: String,
173 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell174 #[serde(default)]
175 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning176 /// Whether the account's email address has been confirmed. Unverified
177 /// accounts can sign in but cannot create or change anything.
178 #[serde(default)]
179 pub verified: bool,
Workspaces own repositories180 /// The workspaces this user belongs to. Filled in when a user is
181 /// resolved from credentials, so any service can authorize from it.
182 #[serde(default)]
183 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control184 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
185 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
186 #[serde(default, skip_serializing_if = "Option::is_none")]
187 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API188 /// Set on an agent resolved from its token: who it acts for, with which
189 /// credential, and what it may do. See [`credentials`].
190 #[serde(default, skip_serializing_if = "Option::is_none")]
191 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look192 /// The repositories this user has been given a role on directly,
193 /// whether or not they belong to its workspace. Filled in with
194 /// `workspaces`; see [`access`].
195 #[serde(default, skip_serializing_if = "Vec::is_empty")]
196 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 step197 /// Set on a user resolved from an access token: its scopes and the
198 /// workspaces or repositories it is limited to. Absent on a signed-in
199 /// session and on an agent (whose `acting` scope applies instead).
200 /// See [`scopes`].
201 #[serde(default, skip_serializing_if = "Option::is_none")]
202 pub token: Option<Box<scopes::TokenAccess>>,
Merge main (membership, two-factor, GitHub repo roles) into tokens203 /// The workspaces this person belongs to but cannot use until they
204 /// meet its policy, such as turning on two-factor authentication.
205 /// They are left out of `workspaces` and `grants` meanwhile. Set when
206 /// a person is resolved from a session.
207 #[serde(default, skip_serializing_if = "Vec::is_empty")]
208 pub held: Vec<members::PolicyHold>,
Workspaces own repositories209}
210
211impl User {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily212 /// g1t itself, acting in `workspace`: what the platform's own work,
213 /// such as security updates, is done and recorded as.
214 pub fn system(workspace: &str) -> User {
215 User {
216 id: system::ID.to_owned(),
217 username: system::USERNAME.to_owned(),
218 kind: PrincipalKind::System,
219 verified: true,
220 workspaces: vec![Membership::member(workspace.to_lowercase())],
221 ..User::default()
222 }
223 }
224
225 /// Whether this is g1t itself.
226 pub fn is_system(&self) -> bool {
227 self.kind == PrincipalKind::System
228 }
229
Merge email confirmation gate: a code and a link, nothing until confirmed (identity 0036)230 /// Whether this is a person whose account has not confirmed its email
231 /// address. Such an account can only confirm it (or change it, or sign
232 /// out): the site, the API, MCP and git refuse it everything else
233 /// ([`accounts::confirm_email_first`]).
234 pub fn awaits_confirmation(&self) -> bool {
235 self.kind == PrincipalKind::User && !self.verified
236 }
237
Workspaces own repositories238 pub fn role_in(&self, slug: &str) -> Option<Role> {
239 self.workspaces
240 .iter()
241 .find(|membership| membership.slug == slug)
242 .map(|membership| membership.role)
243 }
244
245 pub fn is_member(&self, slug: &str) -> bool {
246 self.role_in(slug).is_some()
247 }
Merge main (membership, two-factor, GitHub repo roles) into tokens248
249 /// The membership in `slug`, if any.
250 pub fn membership(&self, slug: &str) -> Option<&Membership> {
251 self.workspaces.iter().find(|membership| membership.slug.eq_ignore_ascii_case(slug))
252 }
253
254 /// Whether this is a person who owns `slug`, or holds `role` in it.
255 pub fn owns_or_has(&self, slug: &str, role: OrgRole) -> bool {
256 self.membership(slug)
257 .is_some_and(|membership| membership.role == Role::Owner || membership.has(role))
258 }
259
260 /// Whether the user may manage `slug`'s billing: an owner or a billing
261 /// manager.
262 pub fn manages_billing(&self, slug: &str) -> bool {
263 self.owns_or_has(slug, OrgRole::BillingManager)
264 }
265
266 /// Whether the user may see and manage security across `slug`: an
267 /// owner or a security manager.
268 pub fn manages_security(&self, slug: &str) -> bool {
269 self.owns_or_has(slug, OrgRole::SecurityManager)
270 }
271
272 /// The workspace's member privileges as this user sees them: the
273 /// defaults when the membership does not say.
274 pub fn privileges_in(&self, slug: &str) -> MemberPrivileges {
275 self.membership(slug).and_then(|membership| membership.privileges).unwrap_or_default()
276 }
API and MCP server, Rust identity service, registration, site redesign277}
278
279/// Who is asking. Every read and write in every service takes one.
280pub type Viewer = Option<User>;

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