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 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 7 | pub mod billing; |
| Rust repos service with shipping; pull requests kept in the model | 8 | pub mod events; |
| API and MCP server, Rust identity service, registration, site redesign | 9 | pub mod identity; |
| Integrations: your own model provider, alerts that open issues, tickets agents read | 10 | pub mod integrations; |
| API and MCP server, Rust identity service, registration, site redesign | 11 | mod ids; |
| 12 | mod names; | |
| 13 | mod outcome; | |
| Rust repos service with shipping; pull requests kept in the model | 14 | pub mod repos; |
| RFC 3339 timestamps in identity and repos | 15 | pub mod time; |
| Work service in Rust, with RFC 3339 timestamps | 16 | pub mod work; |
| API and MCP server, Rust identity service, registration, site redesign | 17 | |
| 18 | pub use ids::new_id; | |
| 19 | pub use names::{is_valid_namespace, is_valid_repo_name}; | |
| 20 | pub use outcome::{Failure, FailureCode, Outcome}; | |
| 21 | ||
| 22 | use serde::{Deserialize, Serialize}; | |
| 23 | ||
| Workspaces own repositories | 24 | /// What a member may do in a workspace. |
| 25 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 26 | #[serde(rename_all = "lowercase")] | |
| 27 | pub enum Role { | |
| 28 | /// Everything a member can, plus managing members. | |
| 29 | Owner, | |
| Issues and pull requests replace intents and attempts | 30 | /// Create repositories, push, manage issues and merge pull requests. |
| Workspaces own repositories | 31 | Member, |
| 32 | } | |
| 33 | ||
| 34 | /// One workspace a user belongs to. | |
| API and MCP server, Rust identity service, registration, site redesign | 35 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| Workspaces own repositories | 36 | pub struct Membership { |
| 37 | /// The workspace's name in URLs: `g1t.sh/<slug>`. | |
| 38 | pub slug: String, | |
| 39 | pub role: Role, | |
| 40 | } | |
| 41 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 42 | /// What a set of credentials resolved to. |
| 43 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | |
| 44 | #[serde(rename_all = "lowercase")] | |
| 45 | pub enum PrincipalKind { | |
| 46 | /// A person's account. | |
| 47 | #[default] | |
| 48 | User, | |
| 49 | /// A workspace, acting through one of its own access tokens. Its `id` | |
| 50 | /// is the workspace's, its `username` the workspace's slug, and it is a | |
| 51 | /// member of that workspace and no other. | |
| 52 | Workspace, | |
| 53 | /// A g1t agent at work in a sandbox, acting through a token that lives | |
| 54 | /// as long as its run and can do only what that token's scope lists, in | |
| 55 | /// one repository. Its `username` is `g1t-agent`. | |
| 56 | Agent, | |
| 57 | } | |
| 58 | ||
| Workspaces own repositories | 59 | #[derive(Clone, Debug, Default, Serialize, Deserialize)] |
| API and MCP server, Rust identity service, registration, site redesign | 60 | pub struct User { |
| 61 | pub id: String, | |
| 62 | pub username: String, | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 63 | #[serde(default)] |
| 64 | pub kind: PrincipalKind, | |
| Email verification, password reset, and Git for AI scale positioning | 65 | /// Whether the account's email address has been confirmed. Unverified |
| 66 | /// accounts can sign in but cannot create or change anything. | |
| 67 | #[serde(default)] | |
| 68 | pub verified: bool, | |
| Workspaces own repositories | 69 | /// The workspaces this user belongs to. Filled in when a user is |
| 70 | /// resolved from credentials, so any service can authorize from it. | |
| 71 | #[serde(default)] | |
| 72 | pub workspaces: Vec<Membership>, | |
| 73 | } | |
| 74 | ||
| 75 | impl User { | |
| 76 | pub fn role_in(&self, slug: &str) -> Option<Role> { | |
| 77 | self.workspaces | |
| 78 | .iter() | |
| 79 | .find(|membership| membership.slug == slug) | |
| 80 | .map(|membership| membership.role) | |
| 81 | } | |
| 82 | ||
| 83 | pub fn is_member(&self, slug: &str) -> bool { | |
| 84 | self.role_in(slug).is_some() | |
| 85 | } | |
| API and MCP server, Rust identity service, registration, site redesign | 86 | } |
| 87 | ||
| 88 | /// Who is asking. Every read and write in every service takes one. | |
| 89 | pub type Viewer = Option<User>; |