Skip to content

g1t/crates/contracts/src/lib.rs

150 lines5,330 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;
Agents as a team: lifecycle, merge queue, billing and a new shell12pub mod billing;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API13pub mod capture;
14pub mod credentials;
Rust repos service with shipping; pull requests kept in the model15pub mod events;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look16pub mod github;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API17pub mod guardrails;
API and MCP server, Rust identity service, registration, site redesign18pub mod identity;
Integrations: your own model provider, alerts that open issues, tickets agents read19pub mod integrations;
API and MCP server, Rust identity service, registration, site redesign20mod ids;
21mod names;
22mod outcome;
Projects: what a workspace builds and runs, first on every page23pub mod projects;
Rust repos service with shipping; pull requests kept in the model24pub mod repos;
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step25pub mod scopes;
Search across all of g1t, Explore, and a command palette26pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API27pub mod security;
RFC 3339 timestamps in identity and repos28pub mod time;
Webhooks: every event, to your own addresses, signed and retried29pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps30pub mod work;
API and MCP server, Rust identity service, registration, site redesign31
32pub use ids::new_id;
33pub use names::{is_valid_namespace, is_valid_repo_name};
34pub use outcome::{Failure, FailureCode, Outcome};
35
36use serde::{Deserialize, Serialize};
37
Workspaces own repositories38/// What a member may do in a workspace.
39#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(rename_all = "lowercase")]
41pub enum Role {
42 /// Everything a member can, plus managing members.
43 Owner,
Issues and pull requests replace intents and attempts44 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories45 Member,
46}
47
48/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign49#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories50pub struct Membership {
51 /// The workspace's name in URLs: `g1t.sh/<slug>`.
52 pub slug: String,
53 pub role: Role,
Workspace names and icons, and a component kit for every control54 /// The workspace's display name, for showing it to people. Set when a
55 /// user is resolved from credentials; absent on principals made up by
56 /// a service.
57 #[serde(default, skip_serializing_if = "Option::is_none")]
58 pub name: Option<String>,
59 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
60 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
61 #[serde(default, skip_serializing_if = "Option::is_none")]
62 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look63 /// What a member gets on each of the workspace's repositories: the
64 /// workspace's base permission. Set when a user is resolved from
65 /// credentials; absent means the default, Write. Owners have Admin
66 /// whatever it says. See [`access`].
67 #[serde(default, skip_serializing_if = "Option::is_none")]
68 pub base_permission: Option<access::BasePermission>,
Workspaces own repositories69}
70
Workspace names and icons, and a component kit for every control71impl Membership {
72 /// A plain member of `slug`, as services act inside one workspace.
73 pub fn member(slug: impl Into<String>) -> Self {
74 Membership {
75 slug: slug.into(),
76 role: Role::Member,
77 name: None,
78 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look79 base_permission: None,
Workspace names and icons, and a component kit for every control80 }
81 }
82}
83
Agents as a team: lifecycle, merge queue, billing and a new shell84/// What a set of credentials resolved to.
85#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
86#[serde(rename_all = "lowercase")]
87pub enum PrincipalKind {
88 /// A person's account.
89 #[default]
90 User,
91 /// A workspace, acting through one of its own access tokens. Its `id`
92 /// is the workspace's, its `username` the workspace's slug, and it is a
93 /// member of that workspace and no other.
94 Workspace,
95 /// A g1t agent at work in a sandbox, acting through a token that lives
96 /// as long as its run and can do only what that token's scope lists, in
97 /// one repository. Its `username` is `g1t-agent`.
98 Agent,
99}
100
Workspaces own repositories101#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign102pub struct User {
103 pub id: String,
104 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell105 #[serde(default)]
106 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning107 /// Whether the account's email address has been confirmed. Unverified
108 /// accounts can sign in but cannot create or change anything.
109 #[serde(default)]
110 pub verified: bool,
Workspaces own repositories111 /// The workspaces this user belongs to. Filled in when a user is
112 /// resolved from credentials, so any service can authorize from it.
113 #[serde(default)]
114 pub workspaces: Vec<Membership>,
Workspace names and icons, and a component kit for every control115 /// The person's uploaded avatar: the SHA-256 of its bytes, served at
116 /// `/avatars/<avatar>`. Absent means the generated letter avatar.
117 #[serde(default, skip_serializing_if = "Option::is_none")]
118 pub avatar: Option<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API119 /// Set on an agent resolved from its token: who it acts for, with which
120 /// credential, and what it may do. See [`credentials`].
121 #[serde(default, skip_serializing_if = "Option::is_none")]
122 pub acting: Option<Box<credentials::Acting>>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look123 /// The repositories this user has been given a role on directly,
124 /// whether or not they belong to its workspace. Filled in with
125 /// `workspaces`; see [`access`].
126 #[serde(default, skip_serializing_if = "Vec::is_empty")]
127 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 step128 /// Set on a user resolved from an access token: its scopes and the
129 /// workspaces or repositories it is limited to. Absent on a signed-in
130 /// session and on an agent (whose `acting` scope applies instead).
131 /// See [`scopes`].
132 #[serde(default, skip_serializing_if = "Option::is_none")]
133 pub token: Option<Box<scopes::TokenAccess>>,
Workspaces own repositories134}
135
136impl User {
137 pub fn role_in(&self, slug: &str) -> Option<Role> {
138 self.workspaces
139 .iter()
140 .find(|membership| membership.slug == slug)
141 .map(|membership| membership.role)
142 }
143
144 pub fn is_member(&self, slug: &str) -> bool {
145 self.role_in(slug).is_some()
146 }
API and MCP server, Rust identity service, registration, site redesign147}
148
149/// Who is asking. Every read and write in every service takes one.
150pub type Viewer = Option<User>;