pr_01m47d24b0e6n91zwymwxg0vpx/crates/contracts/src/lib.rs

92 lines2,808 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
GitHub Actions on g1t, part two: running workflows7pub mod actions;
Agents as a team: lifecycle, merge queue, billing and a new shell8pub mod billing;
Rust repos service with shipping; pull requests kept in the model9pub mod events;
API and MCP server, Rust identity service, registration, site redesign10pub mod identity;
Integrations: your own model provider, alerts that open issues, tickets agents read11pub mod integrations;
API and MCP server, Rust identity service, registration, site redesign12mod ids;
13mod names;
14mod outcome;
Projects: what a workspace builds and runs, first on every page15pub mod projects;
Rust repos service with shipping; pull requests kept in the model16pub mod repos;
RFC 3339 timestamps in identity and repos17pub mod time;
Webhooks: every event, to your own addresses, signed and retried18pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps19pub mod work;
API and MCP server, Rust identity service, registration, site redesign20
21pub use ids::new_id;
22pub use names::{is_valid_namespace, is_valid_repo_name};
23pub use outcome::{Failure, FailureCode, Outcome};
24
25use serde::{Deserialize, Serialize};
26
Workspaces own repositories27/// What a member may do in a workspace.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "lowercase")]
30pub enum Role {
31 /// Everything a member can, plus managing members.
32 Owner,
Issues and pull requests replace intents and attempts33 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories34 Member,
35}
36
37/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign38#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories39pub struct Membership {
40 /// The workspace's name in URLs: `g1t.sh/<slug>`.
41 pub slug: String,
42 pub role: Role,
43}
44
Agents as a team: lifecycle, merge queue, billing and a new shell45/// What a set of credentials resolved to.
46#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
47#[serde(rename_all = "lowercase")]
48pub enum PrincipalKind {
49 /// A person's account.
50 #[default]
51 User,
52 /// A workspace, acting through one of its own access tokens. Its `id`
53 /// is the workspace's, its `username` the workspace's slug, and it is a
54 /// member of that workspace and no other.
55 Workspace,
56 /// A g1t agent at work in a sandbox, acting through a token that lives
57 /// as long as its run and can do only what that token's scope lists, in
58 /// one repository. Its `username` is `g1t-agent`.
59 Agent,
60}
61
Workspaces own repositories62#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign63pub struct User {
64 pub id: String,
65 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell66 #[serde(default)]
67 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning68 /// Whether the account's email address has been confirmed. Unverified
69 /// accounts can sign in but cannot create or change anything.
70 #[serde(default)]
71 pub verified: bool,
Workspaces own repositories72 /// The workspaces this user belongs to. Filled in when a user is
73 /// resolved from credentials, so any service can authorize from it.
74 #[serde(default)]
75 pub workspaces: Vec<Membership>,
76}
77
78impl User {
79 pub fn role_in(&self, slug: &str) -> Option<Role> {
80 self.workspaces
81 .iter()
82 .find(|membership| membership.slug == slug)
83 .map(|membership| membership.role)
84 }
85
86 pub fn is_member(&self, slug: &str) -> bool {
87 self.role_in(slug).is_some()
88 }
API and MCP server, Rust identity service, registration, site redesign89}
90
91/// Who is asking. Every read and write in every service takes one.
92pub type Viewer = Option<User>;