g1t/packages/contracts/src/work.ts
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 attempts | 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { RepoPath } from "./repos"; | |
| 3 | import type { Result } from "./result"; | |
| 4 | ||
| Issues and pull requests replace intents and attempts | 5 | /** |
| 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 | */ | |
| 10 | export type State = "open" | "closed"; | |
| 11 | ||
| 12 | /** Why an issue was closed. */ | |
| 13 | export type IssueReason = "completed" | "not_planned"; | |
| Initial g1t: services, event bus, intents and attempts | 14 | |
| Issues and pull requests replace intents and attempts | 15 | /** |
| 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 | */ | |
| 22 | export type Issue = { | |
| Initial g1t: services, event bus, intents and attempts | 23 | id: string; |
| 24 | repoId: string; | |
| Issues and pull requests replace intents and attempts | 25 | /** Shown as `#12`. */ |
| Initial g1t: services, event bus, intents and attempts | 26 | number: number; |
| 27 | title: string; | |
| Issues and pull requests replace intents and attempts | 28 | /** 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 attempts | 32 | checks: string[]; |
| Issues and pull requests replace intents and attempts | 33 | 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 attempts | 38 | author: User; |
| Work service in Rust, with RFC 3339 timestamps | 39 | /** RFC 3339. */ |
| 40 | createdAt: string; | |
| Issues and pull requests replace intents and attempts | 41 | /** 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; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 48 | /** Usernames of the people it is assigned to. */ |
| 49 | assignees: string[]; | |
| 50 | /** The numbers of the issues that have to be merged before this one is worked on. */ | |
| 51 | blockedBy: number[]; | |
| 52 | /** | |
| 53 | * Whether a g1t agent takes it as soon as it can: at once, or when what it | |
| 54 | * is blocked by has merged. | |
| 55 | */ | |
| 56 | queued: boolean; | |
| 57 | /** | |
| 58 | * The agent working on it now: the one behind its newest pull request | |
| 59 | * that is still in progress in a fork, such as `g1t-agent`. | |
| 60 | */ | |
| 61 | agent: string | null; | |
| Initial g1t: services, event bus, intents and attempts | 62 | }; |
| 63 | ||
| Issues and pull requests replace intents and attempts | 64 | /** `draft` is still being worked on; `open` is ready for review. */ |
| 65 | export type PullStatus = "draft" | "open" | "merged" | "closed"; | |
| Initial g1t: services, event bus, intents and attempts | 66 | |
| 67 | /** Where the agent runs: on g1t's sandboxes, or in someone's own session. */ | |
| Issues and pull requests replace intents and attempts | 68 | export type Runtime = "hosted" | "external"; |
| Initial g1t: services, event bus, intents and attempts | 69 | |
| Pull requests from branches | 70 | /** |
| 71 | * A proposed change. It is made either in a fork created for it, which is | |
| 72 | * how agents work, or on a branch pushed to the repository itself. | |
| 73 | */ | |
| Issues and pull requests replace intents and attempts | 74 | export type Pull = { |
| Initial g1t: services, event bus, intents and attempts | 75 | id: string; |
| 76 | repoId: string; | |
| Issues and pull requests replace intents and attempts | 77 | /** Shown as `#12`. */ |
| Initial g1t: services, event bus, intents and attempts | 78 | number: number; |
| Issues and pull requests replace intents and attempts | 79 | /** The number of the issue this is for, if any. */ |
| 80 | issue: number | null; | |
| 81 | title: string; | |
| 82 | /** Markdown: what changed and why. Set when marked ready. */ | |
| 83 | body: string | null; | |
| Initial g1t: services, event bus, intents and attempts | 84 | /** A label for the agent doing the work, e.g. `claude-code`. */ |
| 85 | agent: string; | |
| Issues and pull requests replace intents and attempts | 86 | runtime: Runtime; |
| 87 | status: PullStatus; | |
| Pull requests from branches | 88 | /** The fork holding the change, unless it is on a branch. */ |
| 89 | fork: RepoPath | null; | |
| Diffs on attempts; hosted agent presented as the g1t agent | 90 | /** The fork's repository id. */ |
| Pull requests from branches | 91 | forkRepoId: string | null; |
| 92 | /** The branch of the repository holding the change, unless it is in a fork. */ | |
| 93 | branch: string | null; | |
| Initial g1t: services, event bus, intents and attempts | 94 | headCommit: string | null; |
| Diffs on attempts; hosted agent presented as the g1t agent | 95 | /** |
| Issues and pull requests replace intents and attempts | 96 | * For a merged pull request, what the branch pointed to before the merge. |
| 97 | * Comparing against it shows what the pull request changed. | |
| 98 | */ | |
| 99 | mergeBase: string | null; | |
| 100 | /** Username of whoever merged it. */ | |
| 101 | mergedBy: string | null; | |
| 102 | /** RFC 3339. */ | |
| 103 | mergedAt: string | null; | |
| 104 | /** | |
| 105 | * Set on a pull request closed because another one for the same issue was | |
| 106 | * merged: that one's number. | |
| Diffs on attempts; hosted agent presented as the g1t agent | 107 | */ |
| Issues and pull requests replace intents and attempts | 108 | supersededBy: number | null; |
| Acceptance checks in sandboxes, line comments and review verdicts | 109 | /** |
| 110 | * Where the latest run of the issue's acceptance checks stands, if there | |
| 111 | * has been one against the current head. | |
| 112 | */ | |
| 113 | checkStatus: CheckStatus | null; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 114 | /** The files it changes, as of its latest push. */ |
| 115 | files: ChangedFile[]; | |
| 116 | /** Usernames of the people it is assigned to. */ | |
| 117 | assignees: string[]; | |
| 118 | /** | |
| 119 | * Those whose review was asked for: usernames, and `g1t-agent` when a g1t | |
| 120 | * agent was asked. | |
| 121 | */ | |
| 122 | reviewers: string[]; | |
| Issues and pull requests replace intents and attempts | 123 | author: User; |
| Work service in Rust, with RFC 3339 timestamps | 124 | /** RFC 3339. */ |
| 125 | createdAt: string; | |
| 126 | /** RFC 3339. */ | |
| 127 | updatedAt: string; | |
| Initial g1t: services, event bus, intents and attempts | 128 | }; |
| 129 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 130 | /** One file a pull request changes, and by how much. */ |
| 131 | export type ChangedFile = { path: string; additions: number; deletions: number }; | |
| 132 | ||
| 133 | /** | |
| 134 | * Another pull request in progress that changes some of the same files. Two | |
| 135 | * for the same issue are alternatives; two for different issues are heading | |
| 136 | * for a conflict. | |
| 137 | */ | |
| 138 | export type Overlap = { | |
| 139 | number: number; | |
| 140 | title: string; | |
| 141 | /** The number of the issue the other pull request is for. */ | |
| 142 | issue: number | null; | |
| 143 | /** The files both change. */ | |
| 144 | paths: string[]; | |
| 145 | }; | |
| 146 | ||
| Acceptance checks in sandboxes, line comments and review verdicts | 147 | /** `queued` waits for a sandbox; `errored` means the checks could not be run. */ |
| 148 | export type CheckStatus = "queued" | "running" | "passed" | "failed" | "errored"; | |
| 149 | ||
| 150 | /** How one acceptance check went. */ | |
| 151 | export type CheckResult = { | |
| 152 | command: string; | |
| 153 | passed: boolean; | |
| 154 | /** Null when the command was stopped for taking too long. */ | |
| 155 | exitCode: number | null; | |
| 156 | /** What the command printed; the end of it, when there was a lot. */ | |
| 157 | output: string; | |
| 158 | durationMs: number; | |
| 159 | }; | |
| 160 | ||
| 161 | /** | |
| 162 | * One run of an issue's acceptance checks against a pull request's head, in | |
| 163 | * a sandbox that holds nothing but that commit. | |
| 164 | */ | |
| 165 | export type CheckRun = { | |
| 166 | id: string; | |
| 167 | /** The commit that was checked. */ | |
| 168 | headCommit: string; | |
| 169 | status: CheckStatus; | |
| 170 | results: CheckResult[]; | |
| 171 | /** Why the checks could not be run, when `status` is `errored`. */ | |
| 172 | error: string | null; | |
| 173 | /** RFC 3339. */ | |
| 174 | createdAt: string; | |
| 175 | /** RFC 3339. */ | |
| 176 | finishedAt: string | null; | |
| 177 | }; | |
| 178 | ||
| 179 | /** A reviewer's decision on a pull request. */ | |
| 180 | export type Verdict = "approve" | "request_changes"; | |
| 181 | ||
| 182 | /** | |
| 183 | * A comment on an issue or a pull request. On a pull request it can sit on | |
| 184 | * one line of the change, and it can carry a reviewer's verdict. | |
| 185 | */ | |
| Issues and pull requests replace intents and attempts | 186 | export type Comment = { |
| 187 | id: string; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 188 | /** |
| 189 | * Something a person or an agent wrote, or something that happened: an | |
| 190 | * assignment, a review asked for, a close. | |
| 191 | */ | |
| 192 | kind: "comment" | "event"; | |
| Issues and pull requests replace intents and attempts | 193 | author: User; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 194 | /** |
| 195 | * Markdown. For an event, what its author did, as the rest of a sentence | |
| 196 | * that starts with their name: "assigned ana". | |
| 197 | */ | |
| Issues and pull requests replace intents and attempts | 198 | body: string; |
| Acceptance checks in sandboxes, line comments and review verdicts | 199 | /** The file commented on, for a comment on a line. */ |
| 200 | path: string | null; | |
| 201 | /** The line of that file, as numbered after the change. */ | |
| 202 | line: number | null; | |
| 203 | verdict: Verdict | null; | |
| Issues and pull requests replace intents and attempts | 204 | /** RFC 3339. */ |
| 205 | createdAt: string; | |
| 206 | }; | |
| 207 | ||
| Acceptance checks in sandboxes, line comments and review verdicts | 208 | export type NewComment = { |
| 209 | /** May be empty when approving. */ | |
| 210 | body: string; | |
| 211 | path?: string; | |
| 212 | line?: number; | |
| 213 | verdict?: Verdict; | |
| 214 | }; | |
| 215 | ||
| 216 | /** What a sandbox needs to carry out a check run. */ | |
| 217 | export type CheckJob = { | |
| 218 | runId: string; | |
| 219 | /** Lets the sandbox, and nothing else, report this run's results. */ | |
| 220 | token: string; | |
| 221 | commands: string[]; | |
| 222 | /** The repository holding the commit: the fork, or the repository itself. */ | |
| 223 | source: RepoPath; | |
| 224 | commit: string; | |
| 225 | /** Who opened the pull request, and so can read its source. */ | |
| 226 | author: User; | |
| 227 | /** Username of whoever wrote the checks: the issue's author. */ | |
| 228 | requestedBy: string; | |
| 229 | repo: RepoPath; | |
| 230 | number: number; | |
| 231 | }; | |
| 232 | ||
| 233 | export type CheckReport = { results?: CheckResult[]; error?: string; skip?: boolean }; | |
| 234 | ||
| Initial g1t: services, event bus, intents and attempts | 235 | export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note"; |
| 236 | ||
| Issues and pull requests replace intents and attempts | 237 | /** One step of an agent's session: the "why" behind a pull request's commits. */ |
| Initial g1t: services, event bus, intents and attempts | 238 | export type SessionEntry = { |
| 239 | seq: number; | |
| 240 | kind: SessionEntryKind; | |
| 241 | text: string; | |
| 242 | /** For tool calls and results. */ | |
| 243 | tool: string | null; | |
| 244 | /** The fork's head commit when this entry was recorded, if known. */ | |
| 245 | commit: string | null; | |
| Work service in Rust, with RFC 3339 timestamps | 246 | /** RFC 3339. */ |
| 247 | at: string; | |
| Initial g1t: services, event bus, intents and attempts | 248 | }; |
| 249 | ||
| 250 | export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> & | |
| Work service in Rust, with RFC 3339 timestamps | 251 | Partial<Pick<SessionEntry, "tool" | "commit">>; |
| Initial g1t: services, event bus, intents and attempts | 252 | |
| Issues and pull requests replace intents and attempts | 253 | export type IssueDetail = { |
| 254 | issue: Issue; | |
| 255 | /** Every pull request made against it, oldest first. */ | |
| 256 | pulls: Pull[]; | |
| 257 | comments: Comment[]; | |
| 258 | }; | |
| Initial g1t: services, event bus, intents and attempts | 259 | |
| Issues and pull requests replace intents and attempts | 260 | export type PullDetail = { |
| 261 | pull: Pull; | |
| 262 | /** The issue it is for, if any. */ | |
| 263 | issue: Issue | null; | |
| 264 | comments: Comment[]; | |
| Acceptance checks in sandboxes, line comments and review verdicts | 265 | /** The latest run of the issue's acceptance checks. */ |
| 266 | checks: CheckRun | null; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 267 | /** Other pull requests in progress that change the same files. */ |
| 268 | overlaps: Overlap[]; | |
| 269 | /** | |
| 270 | * Whether the branch it would merge into has moved on without it, so that | |
| 271 | * it has to catch up before it can merge. | |
| 272 | */ | |
| 273 | behind: boolean; | |
| 274 | /** Whether a g1t agent is reviewing it right now. */ | |
| 275 | reviewPending: boolean; | |
| 276 | /** | |
| 277 | * Where it stands on its way to being merged, for a pull request g1t is | |
| 278 | * seeing through. Null on anyone else's. | |
| 279 | */ | |
| 280 | lifecycle: Lifecycle | null; | |
| 281 | /** | |
| 282 | * A merge was asked for while it was behind: g1t is bringing it up to | |
| 283 | * date and will then land it. | |
| 284 | */ | |
| 285 | landing: boolean; | |
| 286 | /** Why g1t stopped working on it, if it did. */ | |
| 287 | stalled: string | null; | |
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 288 | /** Messages people sent the agent while it worked, oldest first. */ |
| 289 | messages: AgentMessage[]; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 290 | }; |
| 291 | ||
| 292 | /** | |
| 293 | * A step on the way from an assigned issue to a pull request that is ready | |
| 294 | * to merge. g1t takes each one without being asked: `working` (the agent is | |
| 295 | * making the change), `checking`, `reviewing`, `revising` (the agent is | |
| 296 | * addressing failed checks or a review), `catching_up` (merging in the | |
| 297 | * branch it would land on), then `ready` for a person to merge. `needs_you` | |
| 298 | * means g1t has stopped and a person decides what happens next. | |
| 299 | */ | |
| 300 | export type Stage = | |
| 301 | | "working" | |
| 302 | | "checking" | |
| 303 | | "reviewing" | |
| 304 | | "revising" | |
| 305 | | "catching_up" | |
| 306 | | "queued" | |
| 307 | | "ready" | |
| 308 | | "needs_you"; | |
| 309 | ||
| 310 | export type Lifecycle = { | |
| 311 | stage: Stage; | |
| 312 | /** One sentence saying what is happening, or why it stopped. */ | |
| 313 | detail: string; | |
| 314 | /** How many times the agent has been sent back to revise it. */ | |
| 315 | revisions: number; | |
| 316 | }; | |
| 317 | ||
| 318 | /** What the runner needs to carry out a step of a pull request's lifecycle. */ | |
| 319 | export type LifecycleJob = { | |
| 320 | pullId: string; | |
| 321 | repo: RepoPath; | |
| 322 | number: number; | |
| 323 | /** Who the pull request belongs to. Sandboxes act as them. */ | |
| 324 | author: User; | |
| 325 | /** The repository holding the change: its fork, or the repository itself. */ | |
| 326 | source: RepoPath; | |
| 327 | /** The branch of the source holding the change; its default branch when null. */ | |
| 328 | branch: string | null; | |
| 329 | defaultBranch: string; | |
| 330 | title: string; | |
| 331 | description: string; | |
| 332 | issue: Issue | null; | |
| 333 | /** For a revision: the failed checks or the review to address. */ | |
| 334 | feedback: string; | |
| 335 | /** For a revision: which one this is, from 1. */ | |
| 336 | round: number; | |
| 337 | }; | |
| 338 | ||
| 339 | /** | |
| 340 | * `planning` while an agent reads the repository and writes it; `ready` for | |
| 341 | * a person to read and apply; `failed` if it could not be written; | |
| 342 | * `applied` once its issues are open. | |
| 343 | */ | |
| 344 | export type PlanStatus = "planning" | "ready" | "failed" | "applied"; | |
| 345 | ||
| 346 | /** One issue a plan proposes. */ | |
| 347 | export type PlannedIssue = { | |
| 348 | title: string; | |
| 349 | /** Markdown: what to change, where, and why. */ | |
| 350 | body: string; | |
| 351 | labels: string[]; | |
| 352 | /** Commands that must pass once the change is made. */ | |
| 353 | checks: string[]; | |
| 354 | /** The files it will most likely change. */ | |
| 355 | files: string[]; | |
| 356 | /** | |
| 357 | * The positions, counting from 1, of earlier issues in the plan that have | |
| 358 | * to be merged first. | |
| 359 | */ | |
| 360 | dependsOn: number[]; | |
| 361 | /** Its number, once the plan has been applied and it was kept. */ | |
| 362 | number: number | null; | |
| 363 | }; | |
| 364 | ||
| 365 | /** An outcome someone wrote, and the issues an agent proposes to get there. */ | |
| 366 | export type Plan = { | |
| 367 | id: string; | |
| 368 | repoId: string; | |
| 369 | /** The outcome wanted, as written. */ | |
| 370 | brief: string; | |
| 371 | status: PlanStatus; | |
| 372 | /** The agent's account of how it split the work. */ | |
| 373 | summary: string; | |
| 374 | issues: PlannedIssue[]; | |
| 375 | /** Why it could not be written, when `status` is `failed`. */ | |
| 376 | error: string | null; | |
| 377 | author: User; | |
| 378 | /** RFC 3339. */ | |
| 379 | createdAt: string; | |
| 380 | /** RFC 3339. */ | |
| 381 | finishedAt: string | null; | |
| Dark gray base with lavender as an accent, and a live outcome view for plans | 382 | /** Once applied: where each issue it opened stands now, in plan order. */ |
| 383 | progress: IssueProgress[]; | |
| Agents ask each other, hand each other work, and answer | 384 | /** Questions and handoffs between its pull requests' agents, newest first. */ |
| 385 | exchanges: AgentMessage[]; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 386 | }; |
| 387 | ||
| 388 | /** What a sandbox needs to write a plan. */ | |
| 389 | export type PlanJob = { | |
| 390 | planId: string; | |
| 391 | /** Lets the sandbox, and nothing else, report this plan. */ | |
| 392 | token: string; | |
| 393 | brief: string; | |
| 394 | repo: RepoPath; | |
| Issues and pull requests replace intents and attempts | 395 | }; |
| Initial g1t: services, event bus, intents and attempts | 396 | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 397 | /** An issue waiting for a g1t agent that can be given one now. */ |
| 398 | export type ReadyIssue = { | |
| 399 | repo: RepoPath; | |
| 400 | number: number; | |
| 401 | /** Who queued it, on whose say-so the agent works. */ | |
| 402 | actor: User; | |
| 403 | }; | |
| 404 | ||
| 405 | /** | |
| 406 | * How a repository wants its pull requests handled. A repository that has | |
| 407 | * changed nothing has the defaults. | |
| 408 | */ | |
| 409 | export type RepoSettings = { | |
| 410 | /** | |
| 411 | * Land a g1t agent's pull request without a person once it is ready: | |
| 412 | * checks passed and approved as the settings below require. | |
| 413 | */ | |
| 414 | autoMerge: boolean; | |
| 415 | /** | |
| 416 | * Refuse to merge a pull request that does not contain the default | |
| 417 | * branch's latest commits, so that what merges is what was checked. When | |
| 418 | * off, merging one that is behind brings it up to date first. | |
| 419 | */ | |
| 420 | requireUpToDate: boolean; | |
| 421 | /** | |
| 422 | * How many approving reviews a pull request needs before it may merge. A | |
| 423 | * reviewer who has since asked for changes blocks it. | |
| 424 | */ | |
| 425 | requiredApprovals: number; | |
| 426 | /** Whether a g1t agent's approval counts towards `requiredApprovals`. */ | |
| 427 | countAgentApprovals: boolean; | |
| 428 | /** Whether a member may merge although the acceptance checks did not pass. */ | |
| 429 | allowIgnoringChecks: boolean; | |
| 430 | /** Whether a g1t agent's pull request is reviewed by a second agent unasked. */ | |
| 431 | agentReview: boolean; | |
| 432 | /** | |
| 433 | * How many times a g1t agent is sent back to its pull request before a | |
| 434 | * person is asked instead. | |
| 435 | */ | |
| 436 | maxRevisions: number; | |
| 437 | /** | |
| 438 | * Merge through a queue: pull requests are tested together with those | |
| 439 | * ahead of them, and only a combination that passed reaches the default | |
| 440 | * branch. | |
| 441 | */ | |
| 442 | mergeQueue: boolean; | |
| 443 | /** Username of the member who last changed the settings, if anyone has. */ | |
| 444 | updatedBy: string | null; | |
| 445 | /** RFC 3339. */ | |
| 446 | updatedAt: string | null; | |
| 447 | }; | |
| 448 | ||
| 449 | /** The settings a member can change. */ | |
| 450 | export type RepoSettingsInput = Omit<RepoSettings, "updatedBy" | "updatedAt">; | |
| 451 | ||
| 452 | /** The next step for a pull request g1t is seeing through, already claimed. */ | |
| 453 | export type Advance = | |
| 454 | | { action: "none" } | |
| 455 | | { action: "review" | "revise" | "catch_up"; job: LifecycleJob }; | |
| 456 | ||
| 457 | /** What a sandbox needs to review a pull request. */ | |
| 458 | export type ReviewJob = { | |
| 459 | runId: string; | |
| 460 | /** Lets the sandbox, and nothing else, report this review. */ | |
| 461 | token: string; | |
| 462 | /** The repository holding the commit: the fork, or the repository itself. */ | |
| 463 | source: RepoPath; | |
| 464 | commit: string; | |
| 465 | repo: RepoPath; | |
| 466 | defaultBranch: string; | |
| 467 | number: number; | |
| 468 | title: string; | |
| 469 | description: string; | |
| 470 | /** The issue the pull request is for, which says what it should achieve. */ | |
| 471 | issue: Issue | null; | |
| 472 | /** Who opened the pull request, and so can read its source. */ | |
| 473 | author: User; | |
| 474 | }; | |
| 475 | ||
| Issues and pull requests replace intents and attempts | 476 | export type OpenIssueInput = { |
| 477 | title: string; | |
| 478 | body: string; | |
| 479 | labels?: string[]; | |
| 480 | checks?: string[]; | |
| 481 | }; | |
| 482 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 483 | export type UpdateIssueInput = { |
| 484 | title?: string; | |
| 485 | body?: string; | |
| 486 | labels?: string[]; | |
| 487 | /** Usernames of the people it is assigned to; replaces the whole set. */ | |
| 488 | assignees?: string[]; | |
| 489 | }; | |
| Issues and pull requests replace intents and attempts | 490 | |
| 491 | export type OpenPullInput = { | |
| 492 | /** The number of the issue this is for. */ | |
| 493 | issue?: number; | |
| 494 | /** Defaults to the issue's title; required without an issue. */ | |
| 495 | title?: string; | |
| Pull requests from branches | 496 | /** What changed and why. Usually set later, when a draft is marked ready. */ |
| 497 | body?: string; | |
| 498 | /** | |
| 499 | * A branch of the repository that already holds the change. The pull | |
| 500 | * request is then ready for review at once and has no fork. | |
| 501 | */ | |
| 502 | branch?: string; | |
| Issues and pull requests replace intents and attempts | 503 | agent: string; |
| 504 | runtime: Runtime; | |
| 505 | }; | |
| Initial g1t: services, event bus, intents and attempts | 506 | |
| Issues and pull requests replace intents and attempts | 507 | /** Issues, pull requests, comments and sessions. */ |
| Work service in Rust, with RFC 3339 timestamps | 508 | export interface WorkApi { |
| Issues and pull requests replace intents and attempts | 509 | openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>; |
| 510 | /** Newest first. */ | |
| 511 | listIssues( | |
| 512 | repo: RepoPath, | |
| 513 | viewer: Viewer, | |
| 514 | filter?: { state?: State; label?: string }, | |
| 515 | ): Promise<Result<Issue[]>>; | |
| 516 | getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>; | |
| 517 | /** The author or a member of the workspace may. */ | |
| 518 | updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>; | |
| 519 | closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>; | |
| 520 | reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>; | |
| 521 | /** The default labels, then every other label in use on the repository. */ | |
| 522 | listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<string[]>>; | |
| 523 | /** How many issues and pull requests are open. */ | |
| 524 | counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>; | |
| Initial g1t: services, event bus, intents and attempts | 525 | |
| Acceptance checks in sandboxes, line comments and review verdicts | 526 | /** |
| 527 | * On an issue or a pull request. On a pull request it may name a line of | |
| 528 | * the change and carry a verdict; nobody can give a verdict on their own. | |
| 529 | */ | |
| 530 | addComment(actor: User, repo: RepoPath, number: number, comment: NewComment): Promise<Result<Comment>>; | |
| 531 | ||
| 532 | /** | |
| 533 | * Begins a run of the acceptance checks for a pull request that is ready | |
| 534 | * for review. For the runner service, which starts the sandbox. | |
| 535 | */ | |
| 536 | startChecks(pullId: string): Promise<Result<CheckJob>>; | |
| 537 | /** | |
| 538 | * What a sandbox says about its run. With no results and no error it has | |
| 539 | * started; `skip` forgets a run that will not be carried out. | |
| 540 | */ | |
| 541 | reportChecks(runId: string, token: string, report: CheckReport): Promise<Result<CheckRun>>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 542 | /** Begins a review by a g1t agent. For the runner service. */ |
| 543 | startReview(pullId: string): Promise<Result<ReviewJob>>; | |
| 544 | /** Records that a review could not be written. For the runner service. */ | |
| 545 | failReview(runId: string, token: string, error: string): Promise<Result<boolean>>; | |
| 546 | ||
| 547 | /** | |
| 548 | * Works out the next step for a pull request g1t is seeing through and, | |
| 549 | * if there is one to take now, claims it, so that it is taken once | |
| 550 | * however often this is called. For the runner service. | |
| 551 | */ | |
| 552 | advance(pullId: string): Promise<Advance>; | |
| 553 | /** Records that a step could not be carried out, so a person is asked. */ | |
| 554 | stall(pullId: string, reason: string): Promise<boolean>; | |
| 555 | /** Ids of the open pull requests g1t is seeing through. */ | |
| 556 | managedPulls(repoId?: string): Promise<string[]>; | |
| Issues and pull requests replace intents and attempts | 557 | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 558 | /** A repository's merge queue: what is in it, in order, and what recently left. */ |
| 559 | queue(repo: RepoPath, viewer: Viewer): Promise<Result<QueueView>>; | |
| Pull requests from branches | 560 | /** |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 561 | * The next batch of combined states to test for a repository, one per |
| 562 | * entry; empty while a batch is being tested or nothing waits. | |
| 563 | */ | |
| 564 | queueBuild(repoId: string): Promise<QueueJob[]>; | |
| 565 | /** Reports that a combined state could not be built or checked. */ | |
| 566 | failQueue(entryId: string, token: string, error: string): Promise<Result<QueueState>>; | |
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 567 | /** Sends the agent working on a pull request a message, for its next step. */ |
| 568 | messageAgent(actor: User, repo: RepoPath, number: number, body: string): Promise<Result<AgentMessage>>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 569 | /** Takes a pull request out of the merge queue. Members only. */ |
| 570 | removeFromQueue(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; | |
| 571 | ||
| 572 | getSettings(repo: RepoPath, viewer: Viewer): Promise<Result<RepoSettings>>; | |
| 573 | /** Members of the repository's workspace only. */ | |
| 574 | updateSettings(actor: User, repo: RepoPath, settings: RepoSettingsInput): Promise<Result<RepoSettings>>; | |
| 575 | /** | |
| 576 | * What the runner needs to bring a pull request up to date because a | |
| 577 | * merge of it was asked for. Null if none was. | |
| 578 | */ | |
| 579 | catchUpJob(pullId: string): Promise<LifecycleJob | null>; | |
| 580 | ||
| 581 | /** | |
| Pull requests from branches | 582 | * Opens a pull request: a draft with a fork to push to, or, given a |
| 583 | * branch, one ready for review. | |
| 584 | */ | |
| Issues and pull requests replace intents and attempts | 585 | openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>; |
| 586 | /** Newest first. */ | |
| 587 | listPulls(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Pull[]>>; | |
| 588 | getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 589 | /** |
| 590 | * Changes who a pull request is assigned to and whose review is asked | |
| 591 | * for; each list given replaces the whole set. Asking for `g1t-agent`'s | |
| 592 | * review does not by itself start one: the runner's `review` does. | |
| 593 | */ | |
| 594 | updatePull( | |
| 595 | actor: User, | |
| 596 | repo: RepoPath, | |
| 597 | number: number, | |
| 598 | changes: { assignees?: string[]; reviewers?: string[] }, | |
| 599 | ): Promise<Result<Pull>>; | |
| Issues and pull requests replace intents and attempts | 600 | /** Marks a draft ready for review and sets its description. */ |
| 601 | readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>; | |
| 602 | closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; | |
| Rust repos service with shipping; pull requests kept in the model | 603 | /** |
| Issues and pull requests replace intents and attempts | 604 | * Lands the pull request on the repository's default branch. Unless |
| 605 | * `keepIssueOpen`, that resolves the issue it was for: the issue closes | |
| 606 | * naming this pull request, and the others still in progress for it close | |
| 607 | * as superseded. Only members of the repository's workspace may merge. | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 608 | * |
| 609 | * If the default branch has moved, the pull request is brought up to date | |
| 610 | * first and lands when that is done; it comes back still open, and | |
| 611 | * `PullDetail.landing` is true meanwhile. A repository that requires pull | |
| 612 | * requests to be up to date refuses instead. | |
| Rust repos service with shipping; pull requests kept in the model | 613 | */ |
| Acceptance checks in sandboxes, line comments and review verdicts | 614 | mergePull( |
| 615 | actor: User, | |
| 616 | repo: RepoPath, | |
| 617 | number: number, | |
| 618 | options?: { | |
| 619 | keepIssueOpen?: boolean; | |
| 620 | /** Merge although the acceptance checks have not passed. */ | |
| 621 | ignoreChecks?: boolean; | |
| 622 | }, | |
| 623 | ): Promise<Result<Pull>>; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 624 | /** |
| 625 | * Drafts and open pull requests the viewer started, most recently active | |
| 626 | * first, each with where it stands if g1t is seeing it through. | |
| 627 | */ | |
| 628 | listActivePulls( | |
| 629 | viewer: Viewer, | |
| 630 | ): Promise<{ pull: Pull; issue: Issue | null; lifecycle: Lifecycle | null }[]>; | |
| Initial g1t: services, event bus, intents and attempts | 631 | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 632 | /** |
| 633 | * Records an outcome to plan for. Members only. For the runner service, | |
| 634 | * which starts the sandbox in which an agent writes the plan. | |
| 635 | */ | |
| 636 | startPlan(actor: User, repo: RepoPath, brief: string): Promise<Result<PlanJob>>; | |
| 637 | /** Records that a plan could not be written. For the runner service. */ | |
| 638 | failPlan(planId: string, token: string, error: string): Promise<Result<boolean>>; | |
| 639 | /** Members only. */ | |
| 640 | getPlan(repo: RepoPath, viewer: Viewer, id: string): Promise<Result<Plan>>; | |
| 641 | /** Newest first. Members only. */ | |
| 642 | listPlans(repo: RepoPath, viewer: Viewer): Promise<Result<Plan[]>>; | |
| 643 | /** | |
| 644 | * Opens a plan's issues, each blocked by the ones it depends on. With | |
| 645 | * `assign`, each is queued for a g1t agent. `keep` holds the positions, | |
| 646 | * from 1, of the issues to open; all of them when absent. Once. | |
| 647 | */ | |
| 648 | applyPlan( | |
| 649 | actor: User, | |
| 650 | repo: RepoPath, | |
| 651 | id: string, | |
| 652 | options?: { assign?: boolean; keep?: number[] }, | |
| 653 | ): Promise<Result<Plan>>; | |
| 654 | /** Asks for a g1t agent to take an issue as soon as it can, or withdraws that. */ | |
| 655 | queueIssue(actor: User, repo: RepoPath, number: number, queued: boolean): Promise<Result<boolean>>; | |
| 656 | /** Issues waiting for a g1t agent that can be given one now. For the runner. */ | |
| 657 | readyIssues(repoId?: string): Promise<ReadyIssue[]>; | |
| 658 | ||
| 659 | /** Open issues assigned to the viewer, most recently changed first. */ | |
| 660 | listAssignedIssues(viewer: Viewer): Promise<Issue[]>; | |
| 661 | ||
| Issues and pull requests replace intents and attempts | 662 | appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>; |
| 663 | readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>; | |
| Initial g1t: services, event bus, intents and attempts | 664 | } |
| Pull requests from branches | 665 | |
| 666 | /** | |
| 667 | * What to pass `ReposApi.compare` to see what a pull request changes. | |
| 668 | * | |
| 669 | * A fork is compared as a whole. A branch is compared by name while the | |
| 670 | * pull request is open, and by the commit it was merged or closed at | |
| 671 | * afterwards, so later pushes to the branch do not change the record. | |
| 672 | */ | |
| 673 | export function pullComparison(pull: Pull): { | |
| 674 | repoId: string; | |
| 675 | base: string | null; | |
| 676 | head: string | null; | |
| 677 | } { | |
| 678 | if (pull.forkRepoId) return { repoId: pull.forkRepoId, base: pull.mergeBase, head: null }; | |
| 679 | const settled = pull.status === "merged" || pull.status === "closed"; | |
| 680 | return { | |
| 681 | repoId: pull.repoId, | |
| 682 | base: pull.mergeBase, | |
| 683 | head: (settled && pull.headCommit) || pull.branch, | |
| 684 | }; | |
| 685 | } | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 686 | |
| 687 | ||
| 688 | /** Where a pull request in a merge queue stands. */ | |
| Dark gray base with lavender as an accent, and a live outcome view for plans | 689 | /** Where one issue of an applied plan stands. */ |
| 690 | export type IssueProgress = { | |
| 691 | number: number; | |
| 692 | title: string; | |
| 693 | /** | |
| 694 | * `blocked`, `waiting` (for an agent), `open`, a lifecycle stage, | |
| 695 | * `landed` or `closed`. | |
| 696 | */ | |
| 697 | state: string; | |
| 698 | detail: string; | |
| 699 | /** The issues it is waiting on that are still open. */ | |
| 700 | blockedBy: number[]; | |
| 701 | pull: number | null; | |
| 702 | agent: string | null; | |
| 703 | }; | |
| 704 | ||
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 705 | /** A message a person sent an agent at work on a pull request. */ |
| 706 | export type AgentMessage = { | |
| 707 | id: string; | |
| 708 | author: string; | |
| 709 | body: string; | |
| 710 | createdAt: string; | |
| 711 | /** When the agent received it; null until then. */ | |
| 712 | deliveredAt: string | null; | |
| Agents ask each other, hand each other work, and answer | 713 | /** `message` from a person; from an agent a `question`, `handoff` or `answer`. */ |
| 714 | kind: "message" | "question" | "handoff" | "answer"; | |
| 715 | /** The pull request whose agent sent it, when an agent did. */ | |
| 716 | fromNumber: number | null; | |
| 717 | /** The pull request it was sent to. */ | |
| 718 | toNumber: number; | |
| 719 | /** The reply to a question or handoff, once there is one. */ | |
| 720 | answer: string | null; | |
| 721 | declined: boolean; | |
| 722 | /** For the sending agent: what to expect when the one it asked is not at work. */ | |
| 723 | hint?: string; | |
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 724 | }; |
| 725 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 726 | export type QueueState = "waiting" | "testing" | "passed" | "failed" | "landed" | "removed"; |
| 727 | ||
| 728 | /** One pull request's place in a merge queue. */ | |
| 729 | export type QueueEntry = { | |
| 730 | id: string; | |
| 731 | number: number; | |
| 732 | title: string; | |
| 733 | agent: string; | |
| 734 | state: QueueState; | |
| 735 | /** The pull requests merged ahead of it in the state being tested, in order. */ | |
| 736 | ahead: number[]; | |
| 737 | baseCommit: string | null; | |
| 738 | combinedCommit: string | null; | |
| 739 | error: string | null; | |
| 740 | results: CheckResult[]; | |
| 741 | /** Username of whoever merged it into the queue: a person, or `g1t`. */ | |
| 742 | enqueuedBy: string; | |
| 743 | /** RFC 3339. */ | |
| 744 | createdAt: string; | |
| 745 | /** RFC 3339. */ | |
| 746 | finishedAt: string | null; | |
| 747 | }; | |
| 748 | ||
| 749 | /** A repository's merge queue: what is in it, in order, and what recently left. */ | |
| 750 | export type QueueView = { | |
| 751 | enabled: boolean; | |
| 752 | active: QueueEntry[]; | |
| 753 | /** Newest first. */ | |
| 754 | recent: QueueEntry[]; | |
| 755 | }; | |
| 756 | ||
| 757 | export type QueueStackItem = { | |
| 758 | number: number; | |
| 759 | title: string; | |
| 760 | /** The repository holding the change, and its branch. */ | |
| 761 | source: RepoPath; | |
| 762 | branch: string; | |
| 763 | commit: string; | |
| 764 | }; | |
| 765 | ||
| 766 | /** What a sandbox needs to build and check one combined state. */ | |
| 767 | export type QueueJob = { | |
| 768 | entryId: string; | |
| 769 | token: string; | |
| 770 | repo: RepoPath; | |
| 771 | defaultBranch: string; | |
| 772 | baseCommit: string; | |
| 773 | branch: string; | |
| 774 | stack: QueueStackItem[]; | |
| 775 | checks: string[]; | |
| 776 | /** The checks of issues already completed: the default branch's contract. */ | |
| 777 | contractChecks: string[]; | |
| 778 | actor: User; | |
| 779 | }; |