pr_01m47d15m3e54sn21z27rpy5n9/crates/contracts/src/lib.rs

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