Skip to content

g1t/crates/contracts/src/lib.rs

210 lines7,564 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//! 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
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look7pub mod access;
8pub mod accounts;
GitHub Actions on g1t, part two: running workflows9pub mod actions;
Agents and memory, checks and conflicts, profiles, slug renames, custom domains10pub mod agents;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API11pub mod audit;
Merge branch 'worktree-agent-ac5b181a013e54348'12pub mod backups;
Agents as a team: lifecycle, merge queue, billing and a new shell13pub mod billing;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API14pub mod capture;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar15pub mod codeowners;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API16pub mod credentials;
Rust repos service with shipping; pull requests kept in the model17pub mod events;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look18pub mod github;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API19pub mod guardrails;
API and MCP server, Rust identity service, registration, site redesign20pub mod identity;
Inbox: the events service tells people what needs them as events arrive21pub mod inbox;
Integrations: your own model provider, alerts that open issues, tickets agents read22pub mod integrations;
API and MCP server, Rust identity service, registration, site redesign23mod ids;
24mod names;
25mod outcome;
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member26pub mod packages;
Projects: what a workspace builds and runs, first on every page27pub mod projects;
Rust repos service with shipping; pull requests kept in the model28pub mod repos;
Merge rulesets: branch and tag rules, agent-first, enforced on push and merge29pub mod rules;
Fast pages, required checks on the branch, self-hosted runners, honest incidents30pub mod runners;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step31pub mod scopes;
Search across all of g1t, Explore, and a command palette32pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API33pub mod security;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar34pub mod teams;
35pub mod security_suite;
RFC 3339 timestamps in identity and repos36pub mod time;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar37pub mod updates;
Webhooks: every event, to your own addresses, signed and retried38pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps39pub mod work;
API and MCP server, Rust identity service, registration, site redesign40
41pub use ids::new_id;
Merge branch 'worktree-agent-a8385d293d42c913a'42pub use names::{
43 aliasable_name, claimable_namespace, is_namespace_shaped, is_reserved_name, is_route_name, is_valid_namespace,
44 is_valid_repo_name,
45};
API and MCP server, Rust identity service, registration, site redesign46pub use outcome::{Failure, FailureCode, Outcome};
47
48use serde::{Deserialize, Serialize};
49
Workspaces own repositories50/// What a member may do in a workspace.
51#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
52#[serde(rename_all = "lowercase")]
53pub enum Role {
54 /// Everything a member can, plus managing members.
55 Owner,
Issues and pull requests replace intents and attempts56 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories57 Member,
58}
59
60/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign61#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories62pub struct Membership {
63 /// The workspace's name in URLs: `g1t.sh/<slug>`.
64 pub slug: String,
65 pub role: Role,
Workspace names and icons, and a component kit for every control66 /// The workspace's display name, for showing it to people. Set when a
67 /// user is resolved from credentials; absent on principals made up by
68 /// a service.
69 #[serde(default, skip_serializing_if = "Option::is_none")]
70 pub name: Option<String>,
71 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
72 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
73 #[serde(default, skip_serializing_if = "Option::is_none")]
74 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look75 /// What a member gets on each of the workspace's repositories: the
76 /// workspace's base permission. Set when a user is resolved from
77 /// credentials; absent means the default, Write. Owners have Admin
78 /// whatever it says. See [`access`].
79 #[serde(default, skip_serializing_if = "Option::is_none")]
80 pub base_permission: Option<access::BasePermission>,
Merge branch 'worktree-agent-ad7c6d88d93adc817'81 /// Who may create the workspace's teams. Set when a user is resolved
82 /// from credentials; absent means the default, any member. See
83 /// [`teams::TeamCreation`].
84 #[serde(default, skip_serializing_if = "Option::is_none")]
85 pub team_creation: Option<teams::TeamCreation>,
Workspaces own repositories86}
87
Workspace names and icons, and a component kit for every control88impl Membership {
89 /// A plain member of `slug`, as services act inside one workspace.
90 pub fn member(slug: impl Into<String>) -> Self {
91 Membership {
92 slug: slug.into(),
93 role: Role::Member,
94 name: None,
95 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look96 base_permission: None,
Merge branch 'worktree-agent-ad7c6d88d93adc817'97 team_creation: None,
Workspace names and icons, and a component kit for every control98 }
99 }
100}
101
Agents as a team: lifecycle, merge queue, billing and a new shell102/// What a set of credentials resolved to.
103#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
104#[serde(rename_all = "lowercase")]
105pub enum PrincipalKind {
106 /// A person's account.
107 #[default]
108 User,
109 /// A workspace, acting through one of its own access tokens. Its `id`
110 /// is the workspace's, its `username` the workspace's slug, and it is a
111 /// member of that workspace and no other.
112 Workspace,
113 /// A g1t agent at work in a sandbox, acting through a token that lives
114 /// 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-agent115 /// one repository. Its `username` is `g1t`.
Agents as a team: lifecycle, merge queue, billing and a new shell116 Agent,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily117 /// g1t itself: the platform acting on its own, as when it opens a
118 /// pull request to upgrade a vulnerable dependency or merges from the
119 /// queue. Never resolved from credentials: only services make one,
120 /// with [`User::system`]. Its `username` is `g1t`, which nobody can
121 /// register.
122 System,
123}
124
125/// g1t's own identity, as [`PrincipalKind::System`] work is recorded.
126pub mod system {
127 /// Its id wherever an author or actor id is stored.
128 pub const ID: &str = "g1t";
129 /// Its name, shown as the author of what it does.
130 pub const USERNAME: &str = "g1t";
131 /// The address on the commits it makes, which no mailbox receives.
132 pub const EMAIL: &str = "g1t@users.noreply.g1t.sh";
133 /// Ids that earlier versions stored for g1t's own actions, such as a
134 /// merge its settings made. Read as g1t too.
135 pub const LEGACY_IDS: [&str; 3] = ["g1t_policy", "svc_runner", "g1t_runner"];
136
137 /// Whether `id` is g1t's own.
138 pub fn is_system_id(id: &str) -> bool {
139 id == ID || LEGACY_IDS.contains(&id)
140 }
Agents as a team: lifecycle, merge queue, billing and a new shell141}
142
Workspaces own repositories143#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign144pub struct User {
145 pub id: String,
146 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell147 #[serde(default)]
148 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning149 /// Whether the account's email address has been confirmed. Unverified
150 /// accounts can sign in but cannot create or change anything.
151 #[serde(default)]
152 pub verified: bool,
Workspaces own repositories153 /// The workspaces this user belongs to. Filled in when a user is
154 /// resolved from credentials, so any service can authorize from it.
155 #[serde(default)]
156 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control157 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
158 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
159 #[serde(default, skip_serializing_if = "Option::is_none")]
160 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API161 /// Set on an agent resolved from its token: who it acts for, with which
162 /// credential, and what it may do. See [`credentials`].
163 #[serde(default, skip_serializing_if = "Option::is_none")]
164 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look165 /// The repositories this user has been given a role on directly,
166 /// whether or not they belong to its workspace. Filled in with
167 /// `workspaces`; see [`access`].
168 #[serde(default, skip_serializing_if = "Vec::is_empty")]
169 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 step170 /// Set on a user resolved from an access token: its scopes and the
171 /// workspaces or repositories it is limited to. Absent on a signed-in
172 /// session and on an agent (whose `acting` scope applies instead).
173 /// See [`scopes`].
174 #[serde(default, skip_serializing_if = "Option::is_none")]
175 pub token: Option<Box<scopes::TokenAccess>>,
Workspaces own repositories176}
177
178impl User {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily179 /// g1t itself, acting in `workspace`: what the platform's own work,
180 /// such as security updates, is done and recorded as.
181 pub fn system(workspace: &str) -> User {
182 User {
183 id: system::ID.to_owned(),
184 username: system::USERNAME.to_owned(),
185 kind: PrincipalKind::System,
186 verified: true,
187 workspaces: vec![Membership::member(workspace.to_lowercase())],
188 ..User::default()
189 }
190 }
191
192 /// Whether this is g1t itself.
193 pub fn is_system(&self) -> bool {
194 self.kind == PrincipalKind::System
195 }
196
Workspaces own repositories197 pub fn role_in(&self, slug: &str) -> Option<Role> {
198 self.workspaces
199 .iter()
200 .find(|membership| membership.slug == slug)
201 .map(|membership| membership.role)
202 }
203
204 pub fn is_member(&self, slug: &str) -> bool {
205 self.role_in(slug).is_some()
206 }
API and MCP server, Rust identity service, registration, site redesign207}
208
209/// Who is asking. Every read and write in every service takes one.
210pub type Viewer = Option<User>;

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