g1t/packages/contracts/src/work.ts

197 lines6,861 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 { RepoPath } from "./repos";
3import type { Result } from "./result";
4
Issues and pull requests replace intents and attempts5/**
6 * The filter on lists of issues and pull requests. An open pull request is
7 * a draft or one ready for review; a closed one was merged or closed
8 * without merging.
9 */
10export type State = "open" | "closed";
11
12/** Why an issue was closed. */
13export type IssueReason = "completed" | "not_planned";
Initial g1t: services, event bus, intents and attempts14
Issues and pull requests replace intents and attempts15/**
16 * Something that should change in a repository: a bug, a feature, a
17 * question. Opened by a person, an agent or an integration. Pull requests
18 * are made against it; the one that is merged resolves it.
19 *
20 * Issues and pull requests share one sequence of numbers per repository.
21 */
22export type Issue = {
Initial g1t: services, event bus, intents and attempts23 id: string;
24 repoId: string;
Issues and pull requests replace intents and attempts25 /** Shown as `#12`. */
Initial g1t: services, event bus, intents and attempts26 number: number;
27 title: string;
Issues and pull requests replace intents and attempts28 /** Markdown. Also what an agent is given to work from. */
29 body: string;
30 labels: string[];
31 /** Commands that must pass for a pull request to be accepted. */
Initial g1t: services, event bus, intents and attempts32 checks: string[];
Issues and pull requests replace intents and attempts33 state: State;
34 /** Set when closed. */
35 reason: IssueReason | null;
36 /** The number of the pull request whose merge closed this issue. */
37 resolvedBy: number | null;
Initial g1t: services, event bus, intents and attempts38 author: User;
Work service in Rust, with RFC 3339 timestamps39 /** RFC 3339. */
40 createdAt: string;
Issues and pull requests replace intents and attempts41 /** RFC 3339. */
42 updatedAt: string;
43 /** RFC 3339. */
44 closedAt: string | null;
45 /** Pull requests made against this issue, in any state. */
46 pullCount: number;
47 commentCount: number;
Initial g1t: services, event bus, intents and attempts48};
49
Issues and pull requests replace intents and attempts50/** `draft` is still being worked on; `open` is ready for review. */
51export type PullStatus = "draft" | "open" | "merged" | "closed";
Initial g1t: services, event bus, intents and attempts52
53/** Where the agent runs: on g1t's sandboxes, or in someone's own session. */
Issues and pull requests replace intents and attempts54export type Runtime = "hosted" | "external";
Initial g1t: services, event bus, intents and attempts55
Issues and pull requests replace intents and attempts56/** A proposed change, made in its own fork by an agent or a person. */
57export type Pull = {
Initial g1t: services, event bus, intents and attempts58 id: string;
59 repoId: string;
Issues and pull requests replace intents and attempts60 /** Shown as `#12`. */
Initial g1t: services, event bus, intents and attempts61 number: number;
Issues and pull requests replace intents and attempts62 /** The number of the issue this is for, if any. */
63 issue: number | null;
64 title: string;
65 /** Markdown: what changed and why. Set when marked ready. */
66 body: string | null;
Initial g1t: services, event bus, intents and attempts67 /** A label for the agent doing the work, e.g. `claude-code`. */
68 agent: string;
Issues and pull requests replace intents and attempts69 runtime: Runtime;
70 status: PullStatus;
Initial g1t: services, event bus, intents and attempts71 fork: RepoPath;
Diffs on attempts; hosted agent presented as the g1t agent72 /** The fork's repository id. */
73 forkRepoId: string;
Initial g1t: services, event bus, intents and attempts74 headCommit: string | null;
Diffs on attempts; hosted agent presented as the g1t agent75 /**
Issues and pull requests replace intents and attempts76 * For a merged pull request, what the branch pointed to before the merge.
77 * Comparing against it shows what the pull request changed.
78 */
79 mergeBase: string | null;
80 /** Username of whoever merged it. */
81 mergedBy: string | null;
82 /** RFC 3339. */
83 mergedAt: string | null;
84 /**
85 * Set on a pull request closed because another one for the same issue was
86 * merged: that one's number.
Diffs on attempts; hosted agent presented as the g1t agent87 */
Issues and pull requests replace intents and attempts88 supersededBy: number | null;
89 author: User;
Work service in Rust, with RFC 3339 timestamps90 /** RFC 3339. */
91 createdAt: string;
92 /** RFC 3339. */
93 updatedAt: string;
Initial g1t: services, event bus, intents and attempts94};
95
Issues and pull requests replace intents and attempts96export type Comment = {
97 id: string;
98 author: User;
99 /** Markdown. */
100 body: string;
101 /** RFC 3339. */
102 createdAt: string;
103};
104
Initial g1t: services, event bus, intents and attempts105export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note";
106
Issues and pull requests replace intents and attempts107/** One step of an agent's session: the "why" behind a pull request's commits. */
Initial g1t: services, event bus, intents and attempts108export type SessionEntry = {
109 seq: number;
110 kind: SessionEntryKind;
111 text: string;
112 /** For tool calls and results. */
113 tool: string | null;
114 /** The fork's head commit when this entry was recorded, if known. */
115 commit: string | null;
Work service in Rust, with RFC 3339 timestamps116 /** RFC 3339. */
117 at: string;
Initial g1t: services, event bus, intents and attempts118};
119
120export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> &
Work service in Rust, with RFC 3339 timestamps121 Partial<Pick<SessionEntry, "tool" | "commit">>;
Initial g1t: services, event bus, intents and attempts122
Issues and pull requests replace intents and attempts123export type IssueDetail = {
124 issue: Issue;
125 /** Every pull request made against it, oldest first. */
126 pulls: Pull[];
127 comments: Comment[];
128};
Initial g1t: services, event bus, intents and attempts129
Issues and pull requests replace intents and attempts130export type PullDetail = {
131 pull: Pull;
132 /** The issue it is for, if any. */
133 issue: Issue | null;
134 comments: Comment[];
135};
Initial g1t: services, event bus, intents and attempts136
Issues and pull requests replace intents and attempts137export type OpenIssueInput = {
138 title: string;
139 body: string;
140 labels?: string[];
141 checks?: string[];
142};
143
144export type UpdateIssueInput = { title?: string; body?: string; labels?: string[] };
145
146export type OpenPullInput = {
147 /** The number of the issue this is for. */
148 issue?: number;
149 /** Defaults to the issue's title; required without an issue. */
150 title?: string;
151 agent: string;
152 runtime: Runtime;
153};
Initial g1t: services, event bus, intents and attempts154
Issues and pull requests replace intents and attempts155/** Issues, pull requests, comments and sessions. */
Work service in Rust, with RFC 3339 timestamps156export interface WorkApi {
Issues and pull requests replace intents and attempts157 openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>;
158 /** Newest first. */
159 listIssues(
160 repo: RepoPath,
161 viewer: Viewer,
162 filter?: { state?: State; label?: string },
163 ): Promise<Result<Issue[]>>;
164 getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>;
165 /** The author or a member of the workspace may. */
166 updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>;
167 closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>;
168 reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>;
169 /** The default labels, then every other label in use on the repository. */
170 listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<string[]>>;
171 /** How many issues and pull requests are open. */
172 counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>;
Initial g1t: services, event bus, intents and attempts173
Issues and pull requests replace intents and attempts174 /** On an issue or a pull request. */
175 addComment(actor: User, repo: RepoPath, number: number, body: string): Promise<Result<Comment>>;
176
177 /** Forks the repo and returns the draft pull request to push to. */
178 openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>;
179 /** Newest first. */
180 listPulls(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Pull[]>>;
181 getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>;
182 /** Marks a draft ready for review and sets its description. */
183 readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>;
184 closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
Rust repos service with shipping; pull requests kept in the model185 /**
Issues and pull requests replace intents and attempts186 * Lands the pull request on the repository's default branch. Unless
187 * `keepIssueOpen`, that resolves the issue it was for: the issue closes
188 * naming this pull request, and the others still in progress for it close
189 * as superseded. Only members of the repository's workspace may merge.
Rust repos service with shipping; pull requests kept in the model190 */
Issues and pull requests replace intents and attempts191 mergePull(actor: User, repo: RepoPath, number: number, keepIssueOpen?: boolean): Promise<Result<Pull>>;
192 /** Drafts and open pull requests the viewer started, most recently active first. */
193 listActivePulls(viewer: Viewer): Promise<{ pull: Pull; issue: Issue | null }[]>;
Initial g1t: services, event bus, intents and attempts194
Issues and pull requests replace intents and attempts195 appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>;
196 readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>;
Initial g1t: services, event bus, intents and attempts197}