Skip to content

g1t/crates/contracts/src/lib.rs

206 lines7,486 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;
Fast pages, required checks on the branch, self-hosted runners, honest incidents29pub mod runners;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step30pub mod scopes;
Search across all of g1t, Explore, and a command palette31pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API32pub mod security;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar33pub mod teams;
34pub mod security_suite;
RFC 3339 timestamps in identity and repos35pub mod time;
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar36pub mod updates;
Webhooks: every event, to your own addresses, signed and retried37pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps38pub mod work;
API and MCP server, Rust identity service, registration, site redesign39
40pub use ids::new_id;
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent41pub use names::{claimable_namespace, is_reserved_name, is_valid_namespace, is_valid_repo_name};
API and MCP server, Rust identity service, registration, site redesign42pub use outcome::{Failure, FailureCode, Outcome};
43
44use serde::{Deserialize, Serialize};
45
Workspaces own repositories46/// What a member may do in a workspace.
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(rename_all = "lowercase")]
49pub enum Role {
50 /// Everything a member can, plus managing members.
51 Owner,
Issues and pull requests replace intents and attempts52 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories53 Member,
54}
55
56/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign57#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories58pub struct Membership {
59 /// The workspace's name in URLs: `g1t.sh/<slug>`.
60 pub slug: String,
61 pub role: Role,
Workspace names and icons, and a component kit for every control62 /// The workspace's display name, for showing it to people. Set when a
63 /// user is resolved from credentials; absent on principals made up by
64 /// a service.
65 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub name: Option<String>,
67 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
68 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
69 #[serde(default, skip_serializing_if = "Option::is_none")]
70 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look71 /// What a member gets on each of the workspace's repositories: the
72 /// workspace's base permission. Set when a user is resolved from
73 /// credentials; absent means the default, Write. Owners have Admin
74 /// whatever it says. See [`access`].
75 #[serde(default, skip_serializing_if = "Option::is_none")]
76 pub base_permission: Option<access::BasePermission>,
Merge branch 'worktree-agent-ad7c6d88d93adc817'77 /// Who may create the workspace's teams. Set when a user is resolved
78 /// from credentials; absent means the default, any member. See
79 /// [`teams::TeamCreation`].
80 #[serde(default, skip_serializing_if = "Option::is_none")]
81 pub team_creation: Option<teams::TeamCreation>,
Workspaces own repositories82}
83
Workspace names and icons, and a component kit for every control84impl Membership {
85 /// A plain member of `slug`, as services act inside one workspace.
86 pub fn member(slug: impl Into<String>) -> Self {
87 Membership {
88 slug: slug.into(),
89 role: Role::Member,
90 name: None,
91 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look92 base_permission: None,
Merge branch 'worktree-agent-ad7c6d88d93adc817'93 team_creation: None,
Workspace names and icons, and a component kit for every control94 }
95 }
96}
97
Agents as a team: lifecycle, merge queue, billing and a new shell98/// What a set of credentials resolved to.
99#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
100#[serde(rename_all = "lowercase")]
101pub enum PrincipalKind {
102 /// A person's account.
103 #[default]
104 User,
105 /// A workspace, acting through one of its own access tokens. Its `id`
106 /// is the workspace's, its `username` the workspace's slug, and it is a
107 /// member of that workspace and no other.
108 Workspace,
109 /// A g1t agent at work in a sandbox, acting through a token that lives
110 /// 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-agent111 /// one repository. Its `username` is `g1t`.
Agents as a team: lifecycle, merge queue, billing and a new shell112 Agent,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily113 /// g1t itself: the platform acting on its own, as when it opens a
114 /// pull request to upgrade a vulnerable dependency or merges from the
115 /// queue. Never resolved from credentials: only services make one,
116 /// with [`User::system`]. Its `username` is `g1t`, which nobody can
117 /// register.
118 System,
119}
120
121/// g1t's own identity, as [`PrincipalKind::System`] work is recorded.
122pub mod system {
123 /// Its id wherever an author or actor id is stored.
124 pub const ID: &str = "g1t";
125 /// Its name, shown as the author of what it does.
126 pub const USERNAME: &str = "g1t";
127 /// The address on the commits it makes, which no mailbox receives.
128 pub const EMAIL: &str = "g1t@users.noreply.g1t.sh";
129 /// Ids that earlier versions stored for g1t's own actions, such as a
130 /// merge its settings made. Read as g1t too.
131 pub const LEGACY_IDS: [&str; 3] = ["g1t_policy", "svc_runner", "g1t_runner"];
132
133 /// Whether `id` is g1t's own.
134 pub fn is_system_id(id: &str) -> bool {
135 id == ID || LEGACY_IDS.contains(&id)
136 }
Agents as a team: lifecycle, merge queue, billing and a new shell137}
138
Workspaces own repositories139#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign140pub struct User {
141 pub id: String,
142 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell143 #[serde(default)]
144 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning145 /// Whether the account's email address has been confirmed. Unverified
146 /// accounts can sign in but cannot create or change anything.
147 #[serde(default)]
148 pub verified: bool,
Workspaces own repositories149 /// The workspaces this user belongs to. Filled in when a user is
150 /// resolved from credentials, so any service can authorize from it.
151 #[serde(default)]
152 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control153 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
154 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
155 #[serde(default, skip_serializing_if = "Option::is_none")]
156 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API157 /// Set on an agent resolved from its token: who it acts for, with which
158 /// credential, and what it may do. See [`credentials`].
159 #[serde(default, skip_serializing_if = "Option::is_none")]
160 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look161 /// The repositories this user has been given a role on directly,
162 /// whether or not they belong to its workspace. Filled in with
163 /// `workspaces`; see [`access`].
164 #[serde(default, skip_serializing_if = "Vec::is_empty")]
165 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 step166 /// Set on a user resolved from an access token: its scopes and the
167 /// workspaces or repositories it is limited to. Absent on a signed-in
168 /// session and on an agent (whose `acting` scope applies instead).
169 /// See [`scopes`].
170 #[serde(default, skip_serializing_if = "Option::is_none")]
171 pub token: Option<Box<scopes::TokenAccess>>,
Workspaces own repositories172}
173
174impl User {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily175 /// g1t itself, acting in `workspace`: what the platform's own work,
176 /// such as security updates, is done and recorded as.
177 pub fn system(workspace: &str) -> User {
178 User {
179 id: system::ID.to_owned(),
180 username: system::USERNAME.to_owned(),
181 kind: PrincipalKind::System,
182 verified: true,
183 workspaces: vec![Membership::member(workspace.to_lowercase())],
184 ..User::default()
185 }
186 }
187
188 /// Whether this is g1t itself.
189 pub fn is_system(&self) -> bool {
190 self.kind == PrincipalKind::System
191 }
192
Workspaces own repositories193 pub fn role_in(&self, slug: &str) -> Option<Role> {
194 self.workspaces
195 .iter()
196 .find(|membership| membership.slug == slug)
197 .map(|membership| membership.role)
198 }
199
200 pub fn is_member(&self, slug: &str) -> bool {
201 self.role_in(slug).is_some()
202 }
API and MCP server, Rust identity service, registration, site redesign203}
204
205/// Who is asking. Every read and write in every service takes one.
206pub type Viewer = Option<User>;

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