flagon-io/g1t

public

Git for AI scale: a forge for thousands of agents working on the same code at once.

g1t/crates/contracts/src/lib.rs

143 lines4,959 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;
Search across all of g1t, Explore, and a command palette25pub mod search;
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API26pub mod security;
RFC 3339 timestamps in identity and repos27pub mod time;
Webhooks: every event, to your own addresses, signed and retried28pub mod webhooks;
Work service in Rust, with RFC 3339 timestamps29pub mod work;
API and MCP server, Rust identity service, registration, site redesign30
31pub use ids::new_id;
32pub use names::{is_valid_namespace, is_valid_repo_name};
33pub use outcome::{Failure, FailureCode, Outcome};
34
35use serde::{Deserialize, Serialize};
36
Workspaces own repositories37/// What a member may do in a workspace.
38#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "lowercase")]
40pub enum Role {
41 /// Everything a member can, plus managing members.
42 Owner,
Issues and pull requests replace intents and attempts43 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories44 Member,
45}
46
47/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign48#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories49pub 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 control53 /// 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 look62 /// 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 repositories68}
69
Workspace names and icons, and a component kit for every control70impl 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 look78 base_permission: None,
Workspace names and icons, and a component kit for every control79 }
80 }
81}
82
Agents as a team: lifecycle, merge queue, billing and a new shell83/// What a set of credentials resolved to.
84#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
85#[serde(rename_all = "lowercase")]
86pub 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 repositories100#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign101pub struct User {
102 pub id: String,
103 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell104 #[serde(default)]
105 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning106 /// 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 repositories110 /// 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 control114 /// 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 API118 /// 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 look122 /// 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 repositories127}
128
129impl 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 redesign140}
141
142/// Who is asking. Every read and write in every service takes one.
143pub type Viewer = Option<User>;