pr_01m47d15m3e54sn21z27rpy5n9/packages/contracts/src/runner.ts

80 lines3,336 bytesCodeBlame
1import type { Trial } from "./billing";
2import type { User, Viewer } from "./identity";
3import type { Result } from "./result";
4import type { RepoPath } from "./repos";
5import type { Plan, Pull } from "./work";
6
7export type RunHostedInput = {
8 /** Extra guidance given to the agent along with the issue. */
9 instructions?: string;
10};
11
12/**
13 * Sandboxes on g1t: agents that work on an issue, and acceptance checks.
14 *
15 * Nobody who assigns a g1t agent picks a model. g1t routes each kind of
16 * work itself, and says in the session which model ran.
17 */
18/**
19 * How a workspace's agents reach a model. The workspace decides: its own
20 * provider (`own` names it), or g1t's hosted models paid from its credit.
21 */
22export type ModelAccess = {
23 /** The workspace's own model connection, by name, if it has one. */
24 own: string | null;
25 /** Whether g1t's hosted models are open to it, on its free allowance or otherwise. */
26 hosted: boolean;
27 /** Its free allowance, when that is how it reaches g1t's hosted models; null when it needs none. */
28 trial: Trial | null;
29};
30
31export interface RunnerApi {
32 /** How `workspace`'s agents would reach a model now. */
33 modelAccess(workspace: string): Promise<ModelAccess>;
34 /**
35 * Whether `viewer` may put g1t's agents to work: in `repo`'s workspace,
36 * or with none named, in any of theirs.
37 */
38 enabled(viewer: Viewer, repo?: RepoPath): Promise<boolean>;
39 /**
40 * Assigns the issue to a g1t agent: opens a draft pull request for it,
41 * made by an agent in a sandbox of its own. Returns as soon as the
42 * sandbox is starting; progress shows up in the pull request's session.
43 * Scale comes from assigning many issues, each to its own agent.
44 */
45 run(actor: User, repo: RepoPath, issue: number, input?: RunHostedInput): Promise<Result<Pull>>;
46 /**
47 * Has an agent read the repository and turn an outcome into a plan: the
48 * issues that would get there and the order they have to land in. Returns
49 * the plan's id as soon as the sandbox is starting; the plan fills in when
50 * the agent has written it. Members of the repository's workspace only.
51 */
52 plan(actor: User, repo: RepoPath, brief: string): Promise<Result<{ planId: string }>>;
53 /**
54 * Opens a plan's issues. With `assign`, a g1t agent starts on each that
55 * depends on nothing, and on the others as what they depend on merges.
56 */
57 applyPlan(
58 actor: User,
59 repo: RepoPath,
60 planId: string,
61 options?: { assign?: boolean; keep?: number[] },
62 ): Promise<Result<Plan>>;
63 /**
64 * Runs the acceptance checks of a pull request again. Whoever opened it,
65 * or a member of the repository's workspace, may ask.
66 */
67 recheck(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
68 /**
69 * Brings a pull request up to date with the branch it would merge into,
70 * in a sandbox. A clean merge is pushed as it is; a conflict is resolved
71 * by a g1t agent. Whoever can push to the pull request's source may ask:
72 * its author, or for one from a branch, a workspace member.
73 */
74 update(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
75 /**
76 * Has a g1t agent review a pull request: line comments, a summary and a
77 * verdict, posted as `g1t-agent`.
78 */
79 review(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
80}