flagon-io/g1t

public

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

g1t/packages/contracts/src/repos.ts

199 lines6,478 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.

Initial g1t: services, event bus, intents and attempts1import type { User, Viewer } from "./identity";
2import type { Result } from "./result";
3
4export type Repo = {
5 id: string;
Workspaces own repositories6 /** The slug of the workspace that owns it: the first URL segment. */
Initial g1t: services, event bus, intents and attempts7 namespace: string;
8 name: string;
9 description: string | null;
10 isPrivate: boolean;
11 ownerId: string;
12 defaultBranch: string;
Issues and pull requests replace intents and attempts13 /** Set when this repo is a pull request's working copy of another repo. */
Initial g1t: services, event bus, intents and attempts14 forkOf: string | null;
Agents as a team: lifecycle, merge queue, billing and a new shell15 /**
16 * Whether the default branch is protected: it changes only by merging a
17 * pull request, and pushes to it are refused.
18 */
19 protected: boolean;
RFC 3339 timestamps in identity and repos20 /** RFC 3339. */
21 createdAt: string;
Initial g1t: services, event bus, intents and attempts22};
23
24export type RepoPath = { namespace: string; name: string };
25
26export type Commit = {
27 hash: string;
28 treeHash: string;
29 message: string;
30 author: { name: string; email: string };
31 parents: string[];
RFC 3339 timestamps in identity and repos32 /** RFC 3339. */
33 authoredAt: string;
Initial g1t: services, event bus, intents and attempts34};
35
36export type TreeEntry = {
37 name: string;
38 hash: string;
39 kind: "tree" | "blob" | "symlink" | "gitlink" | "exec";
40};
41
42export type TreeView = {
43 repo: Repo;
44 ref: string;
45 path: string;
46 /** Null when the repo has no commits yet. */
47 head: Commit | null;
48 entries: TreeEntry[];
49 readme: { name: string; text: string | null } | null;
50};
51
52export type BlobView = {
53 repo: Repo;
54 ref: string;
55 path: string;
56 size: number;
57 /** Null when the file is binary or too large to show. */
58 text: string | null;
59};
60
61/** A git remote and a short-lived credential for it. */
62export type GitAccess = { remote: string; token: string };
63
64export type GitService = "git-upload-pack" | "git-receive-pack";
65
66export type CreateRepoInput = {
Workspaces own repositories67 /** The workspace to create it in; the creator must be a member. */
68 namespace: string;
Initial g1t: services, event bus, intents and attempts69 name: string;
70 description?: string | null;
71 isPrivate?: boolean;
Agents as a team: lifecycle, merge queue, billing and a new shell72 /**
73 * The https address of a public git repository to copy the default branch
74 * of, such as `https://github.com/owner/repo`.
75 */
76 importUrl?: string;
Initial g1t: services, event bus, intents and attempts77};
78
79/** Repositories: metadata, contents and git access. */
80export interface ReposApi {
81 get(path: RepoPath, viewer: Viewer): Promise<Result<Repo>>;
82 getById(id: string, viewer: Viewer): Promise<Result<Repo>>;
Agents and memory, checks and conflicts, profiles, slug renames, custom domains83 /**
84 * The workspaces in which this account made a public repository, and so
85 * a public project anyone can see. By account id.
86 */
87 publicNamespaces(ownerId: string): Promise<string[]>;
Initial g1t: services, event bus, intents and attempts88 /** Repos the viewer may see, newest first, optionally matching `query`. */
Workspaces own repositories89 list(
90 viewer: Viewer,
91 options?: {
92 query?: string;
93 /** Only repos in this workspace. */
94 namespace?: string;
95 /** Only repos in workspaces the viewer belongs to. */
96 memberOnly?: boolean;
97 },
98 ): Promise<Repo[]>;
Initial g1t: services, event bus, intents and attempts99 create(owner: User, input: CreateRepoInput): Promise<Result<Repo>>;
Agents as a team: lifecycle, merge queue, billing and a new shell100 /**
101 * Changes whichever details are given. Members of the repository's
102 * workspace only. An empty description clears it.
103 */
104 update(
105 actor: User,
106 path: RepoPath,
107 changes: { description?: string; isPrivate?: boolean; protected?: boolean },
108 ): Promise<Result<Repo>>;
Initial g1t: services, event bus, intents and attempts109
110 tree(path: RepoPath, viewer: Viewer, ref: string | null, treePath: string): Promise<Result<TreeView>>;
111 blob(path: RepoPath, viewer: Viewer, ref: string, filePath: string): Promise<Result<BlobView>>;
112 log(path: RepoPath, viewer: Viewer, ref: string | null, limit: number): Promise<Result<Commit[]>>;
Agents as a team: lifecycle, merge queue, billing and a new shell113 /**
114 * Who last changed each line of a file as of `ref` (the default branch if
115 * null). Not found when the file is missing or is not text.
116 */
117 blame(path: RepoPath, viewer: Viewer, ref: string | null, filePath: string): Promise<Result<Blame>>;
Initial g1t: services, event bus, intents and attempts118
119 /**
Issues and pull requests replace intents and attempts120 * A copy-on-write copy of `source`, hidden from listings, for one pull request
Initial g1t: services, event bus, intents and attempts121 * to work in.
122 */
Issues and pull requests replace intents and attempts123 forkForPull(sourceId: string, pullId: string, actor: User): Promise<Result<Repo>>;
Initial g1t: services, event bus, intents and attempts124
125 /**
126 * Authorizes a git operation and returns where to send it. Pushing to a
127 * repo that does not exist creates it in the pusher's own namespace.
128 */
129 gitAccess(path: RepoPath, viewer: Viewer, service: GitService): Promise<Result<GitAccess>>;
Rust repos service with shipping; pull requests kept in the model130
Pull requests from branches131 /** The repository's branches, default branch first. */
132 branches(path: RepoPath, viewer: Viewer): Promise<Result<Branch[]>>;
133
Rust repos service with shipping; pull requests kept in the model134 /**
Pull requests from branches135 * Moves a repository's default branch to the head of a pull request's
136 * source: a fork (`sourceId` is the fork) or one of the repository's own
137 * branches (`sourceId` is the repository, and `branch` is required).
138 * Refused with "conflict" when the source is behind, since that would
Rust repos service with shipping; pull requests kept in the model139 * discard commits.
140 */
Pull requests from branches141 land(sourceId: string, actor: User, branch?: string | null): Promise<Result<{ commit: string; previous: string | null }>>;
Diffs on attempts; hosted agent presented as the g1t agent142
143 /**
Pull requests from branches144 * What `head` changes relative to `base`. `head` is a branch or a commit
145 * and defaults to the default branch. With no `base`, a fork is compared
146 * with the last commit it shares with the repository it came from, and a
147 * branch with the point where it left the default branch.
Diffs on attempts; hosted agent presented as the g1t agent148 */
Pull requests from branches149 compare(repoId: string, viewer: Viewer, base?: string | null, head?: string | null): Promise<Result<Comparison>>;
Initial g1t: services, event bus, intents and attempts150}
Diffs on attempts; hosted agent presented as the g1t agent151
Agents as a team: lifecycle, merge queue, billing and a new shell152/** Lines `start` to `end` (inclusive, from 1) last changed by `commit`. */
153export type BlameRange = { start: number; end: number; commit: string };
154
155/** Who last changed each line of a file. */
156export type Blame = {
157 /** The commit the file was read at. */
158 head: string;
159 /** Every line, in order, in runs that share a commit. */
160 ranges: BlameRange[];
161 /** The commits the ranges name, each once. */
162 commits: Commit[];
163 /** True when the history was too long to read in full. */
164 partial: boolean;
165};
166
Pull requests from branches167/** A branch and the commit it points to. */
168export type Branch = { name: string; hash: string };
169
Diffs on attempts; hosted agent presented as the g1t agent170export type DiffLine = {
171 kind: "context" | "add" | "delete";
172 /** Line number in the old file; null for added lines. */
173 old: number | null;
174 /** Line number in the new file; null for deleted lines. */
175 new: number | null;
176 text: string;
177};
178
179/** A run of changed lines with their surrounding context. */
180export type Hunk = { lines: DiffLine[] };
181
182export type FileDiff = {
183 path: string;
184 status: "added" | "modified" | "deleted";
185 additions: number;
186 deletions: number;
187 /** True when the file is binary or too large, so no lines are shown. */
188 binary: boolean;
189 hunks: Hunk[];
190};
191
192/** What changed between two commits. */
193export type Comparison = {
194 base: string | null;
195 head: string;
196 files: FileDiff[];
197 /** True when the change was too large to return in full. */
198 truncated: boolean;
199};