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/packages/contracts/src/runner.ts

116 lines4,977 bytesCodeBlame
1import type { AgentRun } from "./agents";
2import type { Trial } from "./billing";
3import type { User, Viewer } from "./identity";
4import type { Result } from "./result";
5import type { RepoPath } from "./repos";
6import type { DelegateInput, Delegated, Plan, Pull } from "./work";
7
8export type RunHostedInput = {
9 /** Extra guidance given to the agent along with the issue. */
10 instructions?: string;
11};
12
13/**
14 * Sandboxes on g1t: agents that work on an issue, reviews, and the merge queue.
15 *
16 * Nobody who assigns a g1t agent picks a model. g1t routes each kind of
17 * work itself, and says in the session which model ran.
18 */
19/**
20 * How a workspace's agents reach a model. The workspace decides: its own
21 * provider (`own` names it), or g1t's hosted models paid from its credit.
22 */
23export type ModelAccess = {
24 /** The workspace's own model connection, by name, if it has one. */
25 own: string | null;
26 /** Whether g1t's hosted models are open to it, on its free allowance or otherwise. */
27 hosted: boolean;
28 /** Its free allowance, when that is how it reaches g1t's hosted models; null when it needs none. */
29 trial: Trial | null;
30};
31
32/**
33 * The files every g1t agent run in a repository reads as the repository's
34 * instructions, as they are on its default branch.
35 */
36export type RepoInstructions = {
37 branch: string;
38 /** Null when the repository has no commits yet. */
39 commit: string | null;
40 files: {
41 path: string;
42 /** `root` is read by every run, `directory` by runs that touch files under it, `review` by reviews. */
43 role: "root" | "directory" | "review";
44 text: string;
45 /** Longer than agents are given; they get the start of it. */
46 truncated: boolean;
47 lastChanged: { commit: string; message: string; author: string; at: string } | null;
48 }[];
49 /** How much of each file, and of all of them, an agent is given. */
50 limits: { fileChars: number; totalChars: number };
51};
52
53export interface RunnerApi {
54 /**
55 * The repository's instructions for agents (`AGENTS.md`, `CLAUDE.md`,
56 * `.g1t/review.md`), as they are on its default branch: what every g1t
57 * agent run there reads. Whoever can see the repository may ask.
58 */
59 instructions(viewer: Viewer, repo: RepoPath): Promise<Result<RepoInstructions>>;
60 /** How `workspace`'s agents would reach a model now. */
61 modelAccess(workspace: string): Promise<ModelAccess>;
62 /**
63 * Whether `viewer` may put g1t's agents to work: in `repo`'s workspace,
64 * or with none named, in any of theirs.
65 */
66 enabled(viewer: Viewer, repo?: RepoPath): Promise<boolean>;
67 /**
68 * Assigns the issue to a g1t agent: opens a draft pull request for it,
69 * made by an agent in a sandbox of its own. Returns as soon as the
70 * sandbox is starting; progress shows up in the pull request's session.
71 * Scale comes from assigning many issues, each to its own agent.
72 */
73 run(actor: User, repo: RepoPath, issue: number, input?: RunHostedInput): Promise<Result<Pull>>;
74 /**
75 * Puts an agent on something in one step: opens an issue and assigns it
76 * to g1t-agent. Refused, with nothing opened, unless `actor` may put
77 * agents to work in `repo` (Write). Once opened, the issue stays whatever
78 * becomes of the agent: `agent` says whether it started, waits for a
79 * free slot, or did not start, why and where to fix it.
80 */
81 delegate(actor: User, repo: RepoPath, input: DelegateInput): Promise<Result<Delegated>>;
82 /**
83 * Has an agent read the repository and turn an outcome into a plan: the
84 * issues that would get there and the order they have to land in. Returns
85 * the plan's id as soon as the sandbox is starting; the plan fills in when
86 * the agent has written it. Members of the repository's workspace only.
87 */
88 plan(actor: User, repo: RepoPath, brief: string): Promise<Result<{ planId: string }>>;
89 /**
90 * Opens a plan's issues. With `assign`, a g1t agent starts on each that
91 * depends on nothing, and on the others as what they depend on merges.
92 */
93 applyPlan(
94 actor: User,
95 repo: RepoPath,
96 planId: string,
97 options?: { assign?: boolean; keep?: number[] },
98 ): Promise<Result<Plan>>;
99 /**
100 * Brings a pull request up to date with the branch it would merge into,
101 * in a sandbox. A clean merge is pushed as it is; a conflict is resolved
102 * by a g1t agent. Whoever can push to the pull request's source may ask:
103 * its author, or for one from a branch, a workspace member.
104 */
105 update(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
106 /**
107 * Has a g1t agent review a pull request: line comments, a summary and a
108 * verdict, posted as `g1t-agent`.
109 */
110 review(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
111 /**
112 * Stops an agent run: marks it stopped, destroys its sandbox, and leaves
113 * the pull request it was on for a person. Members of the workspace only.
114 */
115 stopRun(actor: User, repo: RepoPath, runId: string): Promise<Result<AgentRun>>;
116}