flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/crates/contracts/src/lib.rs

89 lines2,755 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
Agents as a team: lifecycle, merge queue, billing and a new shell7pub mod billing;
Rust repos service with shipping; pull requests kept in the model8pub mod events;
API and MCP server, Rust identity service, registration, site redesign9pub mod identity;
Integrations: your own model provider, alerts that open issues, tickets agents read10pub mod integrations;
API and MCP server, Rust identity service, registration, site redesign11mod ids;
12mod names;
13mod outcome;
Rust repos service with shipping; pull requests kept in the model14pub mod repos;
RFC 3339 timestamps in identity and repos15pub mod time;
Work service in Rust, with RFC 3339 timestamps16pub mod work;
API and MCP server, Rust identity service, registration, site redesign17
18pub use ids::new_id;
19pub use names::{is_valid_namespace, is_valid_repo_name};
20pub use outcome::{Failure, FailureCode, Outcome};
21
22use serde::{Deserialize, Serialize};
23
Workspaces own repositories24/// What a member may do in a workspace.
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(rename_all = "lowercase")]
27pub enum Role {
28 /// Everything a member can, plus managing members.
29 Owner,
Issues and pull requests replace intents and attempts30 /// Create repositories, push, manage issues and merge pull requests.
Workspaces own repositories31 Member,
32}
33
34/// One workspace a user belongs to.
API and MCP server, Rust identity service, registration, site redesign35#[derive(Clone, Debug, Serialize, Deserialize)]
Workspaces own repositories36pub 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 shell42/// What a set of credentials resolved to.
43#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
44#[serde(rename_all = "lowercase")]
45pub 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 repositories59#[derive(Clone, Debug, Default, Serialize, Deserialize)]
API and MCP server, Rust identity service, registration, site redesign60pub struct User {
61 pub id: String,
62 pub username: String,
Agents as a team: lifecycle, merge queue, billing and a new shell63 #[serde(default)]
64 pub kind: PrincipalKind,
Email verification, password reset, and Git for AI scale positioning65 /// 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 repositories69 /// 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
75impl 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 redesign86}
87
88/// Who is asking. Every read and write in every service takes one.
89pub type Viewer = Option<User>;