g1t/crates/contracts/src/lib.rs
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 redesign | 1 | //! 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 look | 7 | pub mod access; |
| 8 | pub mod accounts; | |
| GitHub Actions on g1t, part two: running workflows | 9 | pub mod actions; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 10 | pub mod agents; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 11 | pub mod audit; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 12 | pub mod billing; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 13 | pub mod capture; |
| 14 | pub mod credentials; | |
| Rust repos service with shipping; pull requests kept in the model | 15 | pub mod events; |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 16 | pub mod github; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 17 | pub mod guardrails; |
| API and MCP server, Rust identity service, registration, site redesign | 18 | pub mod identity; |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 19 | pub mod integrations; |
| API and MCP server, Rust identity service, registration, site redesign | 20 | mod ids; |
| 21 | mod names; | |
| 22 | mod outcome; | |
| Projects: what a workspace builds and runs, first on every page | 23 | pub mod projects; |
| Rust repos service with shipping; pull requests kept in the model | 24 | pub mod repos; |
| Search across all of g1t, Explore, and a command palette | 25 | pub mod search; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 26 | pub mod security; |
| RFC 3339 timestamps in identity and repos | 27 | pub mod time; |
| Webhooks: every event, to your own addresses, signed and retried | 28 | pub mod webhooks; |
| Work service in Rust, with RFC 3339 timestamps | 29 | pub mod work; |
| API and MCP server, Rust identity service, registration, site redesign | 30 | |
| 31 | pub use ids::new_id; | |
| 32 | pub use names::{is_valid_namespace, is_valid_repo_name}; | |
| 33 | pub use outcome::{Failure, FailureCode, Outcome}; | |
| 34 | ||
| 35 | use serde::{Deserialize, Serialize}; | |
| 36 | ||
| Workspaces own repositories | 37 | /// What a member may do in a workspace. |
| 38 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 39 | #[serde(rename_all = "lowercase")] | |
| 40 | pub enum Role { | |
| 41 | /// Everything a member can, plus managing members. | |
| 42 | Owner, | |
| Issues and pull requests replace intents and attempts | 43 | /// Create repositories, push, manage issues and merge pull requests. |
| Workspaces own repositories | 44 | Member, |
| 45 | } | |
| 46 | ||
| 47 | /// One workspace a user belongs to. | |
| API and MCP server, Rust identity service, registration, site redesign | 48 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| Workspaces own repositories | 49 | pub struct Membership { |
| 50 | /// The workspace's name in URLs: `g1t.sh/<slug>`. | |
| 51 | pub slug: String, | |
| 52 | pub role: Role, | |
| Workspace names and icons, and a component kit for every control | 53 | /// The workspace's display name, for showing it to people. Set when a |
| 54 | /// user is resolved from credentials; absent on principals made up by | |
| 55 | /// a service. | |
| 56 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 57 | pub name: Option<String>, | |
| 58 | /// The workspace's uploaded icon: the SHA-256 of its bytes, served at | |
| 59 | /// `/avatars/<avatar>`. Absent means the generated letter avatar. | |
| 60 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 61 | pub avatar: Option<String>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 62 | /// What a member gets on each of the workspace's repositories: the |
| 63 | /// workspace's base permission. Set when a user is resolved from | |
| 64 | /// credentials; absent means the default, Write. Owners have Admin | |
| 65 | /// whatever it says. See [`access`]. | |
| 66 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 67 | pub base_permission: Option<access::BasePermission>, | |
| Workspaces own repositories | 68 | } |
| 69 | ||
| Workspace names and icons, and a component kit for every control | 70 | impl Membership { |
| 71 | /// A plain member of `slug`, as services act inside one workspace. | |
| 72 | pub fn member(slug: impl Into<String>) -> Self { | |
| 73 | Membership { | |
| 74 | slug: slug.into(), | |
| 75 | role: Role::Member, | |
| 76 | name: None, | |
| 77 | avatar: None, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 78 | base_permission: None, |
| Workspace names and icons, and a component kit for every control | 79 | } |
| 80 | } | |
| 81 | } | |
| 82 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 83 | /// What a set of credentials resolved to. |
| 84 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | |
| 85 | #[serde(rename_all = "lowercase")] | |
| 86 | pub enum PrincipalKind { | |
| 87 | /// A person's account. | |
| 88 | #[default] | |
| 89 | User, | |
| 90 | /// A workspace, acting through one of its own access tokens. Its `id` | |
| 91 | /// is the workspace's, its `username` the workspace's slug, and it is a | |
| 92 | /// member of that workspace and no other. | |
| 93 | Workspace, | |
| 94 | /// A g1t agent at work in a sandbox, acting through a token that lives | |
| 95 | /// as long as its run and can do only what that token's scope lists, in | |
| 96 | /// one repository. Its `username` is `g1t-agent`. | |
| 97 | Agent, | |
| 98 | } | |
| 99 | ||
| Workspaces own repositories | 100 | #[derive(Clone, Debug, Default, Serialize, Deserialize)] |
| API and MCP server, Rust identity service, registration, site redesign | 101 | pub struct User { |
| 102 | pub id: String, | |
| 103 | pub username: String, | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 104 | #[serde(default)] |
| 105 | pub kind: PrincipalKind, | |
| Email verification, password reset, and Git for AI scale positioning | 106 | /// Whether the account's email address has been confirmed. Unverified |
| 107 | /// accounts can sign in but cannot create or change anything. | |
| 108 | #[serde(default)] | |
| 109 | pub verified: bool, | |
| Workspaces own repositories | 110 | /// The workspaces this user belongs to. Filled in when a user is |
| 111 | /// resolved from credentials, so any service can authorize from it. | |
| 112 | #[serde(default)] | |
| 113 | pub workspaces: Vec<Membership>, | |
| Workspace names and icons, and a component kit for every control | 114 | /// The person's uploaded avatar: the SHA-256 of its bytes, served at |
| 115 | /// `/avatars/<avatar>`. Absent means the generated letter avatar. | |
| 116 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 117 | pub avatar: Option<String>, | |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 118 | /// Set on an agent resolved from its token: who it acts for, with which |
| 119 | /// credential, and what it may do. See [`credentials`]. | |
| 120 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 121 | pub acting: Option<Box<credentials::Acting>>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 122 | /// The repositories this user has been given a role on directly, |
| 123 | /// whether or not they belong to its workspace. Filled in with | |
| 124 | /// `workspaces`; see [`access`]. | |
| 125 | #[serde(default, skip_serializing_if = "Vec::is_empty")] | |
| 126 | pub grants: Vec<access::RepoGrant>, | |
| Workspaces own repositories | 127 | } |
| 128 | ||
| 129 | impl User { | |
| 130 | pub fn role_in(&self, slug: &str) -> Option<Role> { | |
| 131 | self.workspaces | |
| 132 | .iter() | |
| 133 | .find(|membership| membership.slug == slug) | |
| 134 | .map(|membership| membership.role) | |
| 135 | } | |
| 136 | ||
| 137 | pub fn is_member(&self, slug: &str) -> bool { | |
| 138 | self.role_in(slug).is_some() | |
| 139 | } | |
| API and MCP server, Rust identity service, registration, site redesign | 140 | } |
| 141 | ||
| 142 | /// Who is asking. Every read and write in every service takes one. | |
| 143 | pub type Viewer = Option<User>; |