Skip to content

g1t/crates/contracts/src/lib.rs

196 lines7,087 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;
15pub mod credentials;
Rust repos service with shipping; pull requests kept in the model16pub mod events;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look17pub mod github;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API18pub mod guardrails;
API and MCP server, Rust identity service, registration, site redesign19pub mod identity;
Inbox: the events service tells people what needs them as events arrive20pub mod inbox;
Integrations: your own model provider, alerts that open issues, tickets agents read21pub mod integrations;
API and MCP server, Rust identity service, registration, site redesign22mod ids;
23mod names;
24mod outcome;
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member25pub mod packages;
Projects: what a workspace builds and runs, first on every page26pub mod projects;
Rust repos service with shipping; pull requests kept in the model27pub mod repos;
Fast pages, required checks on the branch, self-hosted runners, honest incidents28pub mod runners;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step29pub mod scopes;
Search across all of g1t, Explore, and a command palette30pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API31pub mod security;
RFC 3339 timestamps in identity and repos32pub mod time;
Webhooks: every event, to your own addresses, signed and retried33pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps34pub mod work;
API and MCP server, Rust identity service, registration, site redesign35
36pub 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-agent37pub use names::{claimable_namespace, is_reserved_name, is_valid_namespace, is_valid_repo_name};
API and MCP server, Rust identity service, registration, site redesign38pub use outcome::{Failure, FailureCode, Outcome};
39
40use serde::{Deserialize, Serialize};
41
Workspaces own repositories42/// What a member may do in a workspace.
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
44#[serde(rename_all = "lowercase")]
45pub enum Role {
46 /// Everything a member can, plus managing members.
47 Owner,
Issues and pull requests replace intents and attempts48 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories49 Member,
50}
51
52/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign53#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories54pub struct Membership {
55 /// The workspace's name in URLs: `g1t.sh/<slug>`.
56 pub slug: String,
57 pub role: Role,
Workspace names and icons, and a component kit for every control58 /// The workspace's display name, for showing it to people. Set when a
59 /// user is resolved from credentials; absent on principals made up by
60 /// a service.
61 #[serde(default, skip_serializing_if = "Option::is_none")]
62 pub name: Option<String>,
63 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
64 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
65 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look67 /// What a member gets on each of the workspace's repositories: the
68 /// workspace's base permission. Set when a user is resolved from
69 /// credentials; absent means the default, Write. Owners have Admin
70 /// whatever it says. See [`access`].
71 #[serde(default, skip_serializing_if = "Option::is_none")]
72 pub base_permission: Option<access::BasePermission>,
Workspaces own repositories73}
74
Workspace names and icons, and a component kit for every control75impl Membership {
76 /// A plain member of `slug`, as services act inside one workspace.
77 pub fn member(slug: impl Into<String>) -> Self {
78 Membership {
79 slug: slug.into(),
80 role: Role::Member,
81 name: None,
82 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look83 base_permission: None,
Workspace names and icons, and a component kit for every control84 }
85 }
86}
87
Agents as a team: lifecycle, merge queue, billing and a new shell88/// What a set of credentials resolved to.
89#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
90#[serde(rename_all = "lowercase")]
91pub enum PrincipalKind {
92 /// A person's account.
93 #[default]
94 User,
95 /// A workspace, acting through one of its own access tokens. Its `id`
96 /// is the workspace's, its `username` the workspace's slug, and it is a
97 /// member of that workspace and no other.
98 Workspace,
99 /// A g1t agent at work in a sandbox, acting through a token that lives
100 /// 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-agent101 /// one repository. Its `username` is `g1t`.
Agents as a team: lifecycle, merge queue, billing and a new shell102 Agent,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily103 /// g1t itself: the platform acting on its own, as when it opens a
104 /// pull request to upgrade a vulnerable dependency or merges from the
105 /// queue. Never resolved from credentials: only services make one,
106 /// with [`User::system`]. Its `username` is `g1t`, which nobody can
107 /// register.
108 System,
109}
110
111/// g1t's own identity, as [`PrincipalKind::System`] work is recorded.
112pub mod system {
113 /// Its id wherever an author or actor id is stored.
114 pub const ID: &str = "g1t";
115 /// Its name, shown as the author of what it does.
116 pub const USERNAME: &str = "g1t";
117 /// The address on the commits it makes, which no mailbox receives.
118 pub const EMAIL: &str = "g1t@users.noreply.g1t.sh";
119 /// Ids that earlier versions stored for g1t's own actions, such as a
120 /// merge its settings made. Read as g1t too.
121 pub const LEGACY_IDS: [&str; 3] = ["g1t_policy", "svc_runner", "g1t_runner"];
122
123 /// Whether `id` is g1t's own.
124 pub fn is_system_id(id: &str) -> bool {
125 id == ID || LEGACY_IDS.contains(&id)
126 }
Agents as a team: lifecycle, merge queue, billing and a new shell127}
128
Workspaces own repositories129#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign130pub struct User {
131 pub id: String,
132 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell133 #[serde(default)]
134 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning135 /// Whether the account's email address has been confirmed. Unverified
136 /// accounts can sign in but cannot create or change anything.
137 #[serde(default)]
138 pub verified: bool,
Workspaces own repositories139 /// The workspaces this user belongs to. Filled in when a user is
140 /// resolved from credentials, so any service can authorize from it.
141 #[serde(default)]
142 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control143 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
144 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
145 #[serde(default, skip_serializing_if = "Option::is_none")]
146 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API147 /// Set on an agent resolved from its token: who it acts for, with which
148 /// credential, and what it may do. See [`credentials`].
149 #[serde(default, skip_serializing_if = "Option::is_none")]
150 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look151 /// The repositories this user has been given a role on directly,
152 /// whether or not they belong to its workspace. Filled in with
153 /// `workspaces`; see [`access`].
154 #[serde(default, skip_serializing_if = "Vec::is_empty")]
155 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 step156 /// Set on a user resolved from an access token: its scopes and the
157 /// workspaces or repositories it is limited to. Absent on a signed-in
158 /// session and on an agent (whose `acting` scope applies instead).
159 /// See [`scopes`].
160 #[serde(default, skip_serializing_if = "Option::is_none")]
161 pub token: Option<Box<scopes::TokenAccess>>,
Workspaces own repositories162}
163
164impl User {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily165 /// g1t itself, acting in `workspace`: what the platform's own work,
166 /// such as security updates, is done and recorded as.
167 pub fn system(workspace: &str) -> User {
168 User {
169 id: system::ID.to_owned(),
170 username: system::USERNAME.to_owned(),
171 kind: PrincipalKind::System,
172 verified: true,
173 workspaces: vec![Membership::member(workspace.to_lowercase())],
174 ..User::default()
175 }
176 }
177
178 /// Whether this is g1t itself.
179 pub fn is_system(&self) -> bool {
180 self.kind == PrincipalKind::System
181 }
182
Workspaces own repositories183 pub fn role_in(&self, slug: &str) -> Option<Role> {
184 self.workspaces
185 .iter()
186 .find(|membership| membership.slug == slug)
187 .map(|membership| membership.role)
188 }
189
190 pub fn is_member(&self, slug: &str) -> bool {
191 self.role_in(slug).is_some()
192 }
API and MCP server, Rust identity service, registration, site redesign193}
194
195/// Who is asking. Every read and write in every service takes one.
196pub type Viewer = Option<User>;

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