pr_01m47d15m3e54sn21z27rpy5n9/packages/contracts/src/work.ts
| 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { RepoPath } from "./repos"; |
| 3 | import type { Result } from "./result"; |
| 4 | |
| 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"; |
| 14 | |
| 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 = { |
| 23 | id: string; |
| 24 | repoId: string; |
| 25 | /** Shown as `#12`. */ |
| 26 | number: number; |
| 27 | title: string; |
| 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. */ |
| 32 | checks: string[]; |
| 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; |
| 38 | author: User; |
| 39 | /** RFC 3339. */ |
| 40 | createdAt: string; |
| 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; |
| 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; |
| 62 | }; |
| 63 | |
| 64 | /** `draft` is still being worked on; `open` is ready for review. */ |
| 65 | export type PullStatus = "draft" | "open" | "merged" | "closed"; |
| 66 | |
| 67 | /** Where the agent runs: on g1t's sandboxes, or in someone's own session. */ |
| 68 | export type Runtime = "hosted" | "external"; |
| 69 | |
| 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 | */ |
| 74 | export type Pull = { |
| 75 | id: string; |
| 76 | repoId: string; |
| 77 | /** Shown as `#12`. */ |
| 78 | number: number; |
| 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; |
| 84 | /** A label for the agent doing the work, e.g. `claude-code`. */ |
| 85 | agent: string; |
| 86 | runtime: Runtime; |
| 87 | status: PullStatus; |
| 88 | /** The fork holding the change, unless it is on a branch. */ |
| 89 | fork: RepoPath | null; |
| 90 | /** The fork's repository id. */ |
| 91 | forkRepoId: string | null; |
| 92 | /** The branch of the repository holding the change, unless it is in a fork. */ |
| 93 | branch: string | null; |
| 94 | headCommit: string | null; |
| 95 | /** |
| 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. |
| 107 | */ |
| 108 | supersededBy: number | null; |
| 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; |
| 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[]; |
| 123 | author: User; |
| 124 | /** RFC 3339. */ |
| 125 | createdAt: string; |
| 126 | /** RFC 3339. */ |
| 127 | updatedAt: string; |
| 128 | }; |
| 129 | |
| 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 | |
| 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 | */ |
| 186 | export type Comment = { |
| 187 | id: string; |
| 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"; |
| 193 | author: User; |
| 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 | */ |
| 198 | body: string; |
| 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; |
| 204 | /** RFC 3339. */ |
| 205 | createdAt: string; |
| 206 | }; |
| 207 | |
| 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 | |
| 235 | export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note"; |
| 236 | |
| 237 | /** One step of an agent's session: the "why" behind a pull request's commits. */ |
| 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; |
| 246 | /** RFC 3339. */ |
| 247 | at: string; |
| 248 | }; |
| 249 | |
| 250 | export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> & |
| 251 | Partial<Pick<SessionEntry, "tool" | "commit">>; |
| 252 | |
| 253 | export type IssueDetail = { |
| 254 | issue: Issue; |
| 255 | /** Every pull request made against it, oldest first. */ |
| 256 | pulls: Pull[]; |
| 257 | comments: Comment[]; |
| 258 | }; |
| 259 | |
| 260 | export type PullDetail = { |
| 261 | pull: Pull; |
| 262 | /** The issue it is for, if any. */ |
| 263 | issue: Issue | null; |
| 264 | comments: Comment[]; |
| 265 | /** The latest run of the issue's acceptance checks. */ |
| 266 | checks: CheckRun | null; |
| 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; |
| 288 | /** Messages people sent the agent while it worked, oldest first. */ |
| 289 | messages: AgentMessage[]; |
| 290 | /** What workflow runs said about its head commit, one per workflow. */ |
| 291 | statuses?: CommitStatus[]; |
| 292 | }; |
| 293 | |
| 294 | /** What a workflow run (or another tool) says about a commit. */ |
| 295 | export type CommitStatus = { |
| 296 | /** What reported it, such as `CI / push`. */ |
| 297 | context: string; |
| 298 | state: "pending" | "success" | "failure" | "error"; |
| 299 | description: string | null; |
| 300 | targetUrl: string | null; |
| 301 | updatedAt: string; |
| 302 | }; |
| 303 | |
| 304 | /** |
| 305 | * A step on the way from an assigned issue to a pull request that is ready |
| 306 | * to merge. g1t takes each one without being asked: `working` (the agent is |
| 307 | * making the change), `checking`, `reviewing`, `revising` (the agent is |
| 308 | * addressing failed checks or a review), `catching_up` (merging in the |
| 309 | * branch it would land on), `answering` (woken to answer another agent), |
| 310 | * then `ready` for a person to merge. `needs_you` |
| 311 | * means g1t has stopped and a person decides what happens next. |
| 312 | */ |
| 313 | export type Stage = |
| 314 | | "working" |
| 315 | | "checking" |
| 316 | | "reviewing" |
| 317 | | "revising" |
| 318 | | "catching_up" |
| 319 | | "answering" |
| 320 | | "queued" |
| 321 | | "ready" |
| 322 | | "needs_you"; |
| 323 | |
| 324 | export type Lifecycle = { |
| 325 | stage: Stage; |
| 326 | /** One sentence saying what is happening, or why it stopped. */ |
| 327 | detail: string; |
| 328 | /** How many times the agent has been sent back to revise it. */ |
| 329 | revisions: number; |
| 330 | }; |
| 331 | |
| 332 | /** What the runner needs to carry out a step of a pull request's lifecycle. */ |
| 333 | export type LifecycleJob = { |
| 334 | pullId: string; |
| 335 | repo: RepoPath; |
| 336 | number: number; |
| 337 | /** Who the pull request belongs to. Sandboxes act as them. */ |
| 338 | author: User; |
| 339 | /** The repository holding the change: its fork, or the repository itself. */ |
| 340 | source: RepoPath; |
| 341 | /** The branch of the source holding the change; its default branch when null. */ |
| 342 | branch: string | null; |
| 343 | defaultBranch: string; |
| 344 | title: string; |
| 345 | description: string; |
| 346 | issue: Issue | null; |
| 347 | /** For a revision: the failed checks or the review to address. */ |
| 348 | feedback: string; |
| 349 | /** For a revision: which one this is, from 1. */ |
| 350 | round: number; |
| 351 | }; |
| 352 | |
| 353 | /** An agent woken to answer what other agents sent it while it was not at work. */ |
| 354 | export type Wake = { job: LifecycleJob; messages: AgentMessage[] }; |
| 355 | |
| 356 | /** |
| 357 | * `planning` while an agent reads the repository and writes it; `ready` for |
| 358 | * a person to read and apply; `failed` if it could not be written; |
| 359 | * `applied` once its issues are open. |
| 360 | */ |
| 361 | export type PlanStatus = "planning" | "ready" | "failed" | "applied"; |
| 362 | |
| 363 | /** One issue a plan proposes. */ |
| 364 | export type PlannedIssue = { |
| 365 | title: string; |
| 366 | /** Markdown: what to change, where, and why. */ |
| 367 | body: string; |
| 368 | labels: string[]; |
| 369 | /** Commands that must pass once the change is made. */ |
| 370 | checks: string[]; |
| 371 | /** The files it will most likely change. */ |
| 372 | files: string[]; |
| 373 | /** |
| 374 | * The positions, counting from 1, of earlier issues in the plan that have |
| 375 | * to be merged first. |
| 376 | */ |
| 377 | dependsOn: number[]; |
| 378 | /** Its number, once the plan has been applied and it was kept. */ |
| 379 | number: number | null; |
| 380 | }; |
| 381 | |
| 382 | /** An outcome someone wrote, and the issues an agent proposes to get there. */ |
| 383 | export type Plan = { |
| 384 | id: string; |
| 385 | repoId: string; |
| 386 | /** The outcome wanted, as written. */ |
| 387 | brief: string; |
| 388 | status: PlanStatus; |
| 389 | /** The agent's account of how it split the work. */ |
| 390 | summary: string; |
| 391 | issues: PlannedIssue[]; |
| 392 | /** Why it could not be written, when `status` is `failed`. */ |
| 393 | error: string | null; |
| 394 | author: User; |
| 395 | /** RFC 3339. */ |
| 396 | createdAt: string; |
| 397 | /** RFC 3339. */ |
| 398 | finishedAt: string | null; |
| 399 | /** Once applied: where each issue it opened stands now, in plan order. */ |
| 400 | progress: IssueProgress[]; |
| 401 | /** Questions and handoffs between its pull requests' agents, newest first. */ |
| 402 | exchanges: AgentMessage[]; |
| 403 | }; |
| 404 | |
| 405 | /** What a sandbox needs to write a plan. */ |
| 406 | export type PlanJob = { |
| 407 | planId: string; |
| 408 | /** Lets the sandbox, and nothing else, report this plan. */ |
| 409 | token: string; |
| 410 | brief: string; |
| 411 | repo: RepoPath; |
| 412 | }; |
| 413 | |
| 414 | /** An issue waiting for a g1t agent that can be given one now. */ |
| 415 | export type ReadyIssue = { |
| 416 | repo: RepoPath; |
| 417 | number: number; |
| 418 | /** Who queued it, on whose say-so the agent works. */ |
| 419 | actor: User; |
| 420 | }; |
| 421 | |
| 422 | /** |
| 423 | * How a repository wants its pull requests handled. A repository that has |
| 424 | * changed nothing has the defaults. |
| 425 | */ |
| 426 | export type RepoSettings = { |
| 427 | /** |
| 428 | * Land a g1t agent's pull request without a person once it is ready: |
| 429 | * checks passed and approved as the settings below require. |
| 430 | */ |
| 431 | autoMerge: boolean; |
| 432 | /** |
| 433 | * Refuse to merge a pull request that does not contain the default |
| 434 | * branch's latest commits, so that what merges is what was checked. When |
| 435 | * off, merging one that is behind brings it up to date first. |
| 436 | */ |
| 437 | requireUpToDate: boolean; |
| 438 | /** |
| 439 | * How many approving reviews a pull request needs before it may merge. A |
| 440 | * reviewer who has since asked for changes blocks it. |
| 441 | */ |
| 442 | requiredApprovals: number; |
| 443 | /** Whether a g1t agent's approval counts towards `requiredApprovals`. */ |
| 444 | countAgentApprovals: boolean; |
| 445 | /** Whether a member may merge although the acceptance checks did not pass. */ |
| 446 | allowIgnoringChecks: boolean; |
| 447 | /** Whether a g1t agent's pull request is reviewed by a second agent unasked. */ |
| 448 | agentReview: boolean; |
| 449 | /** |
| 450 | * How many times a g1t agent is sent back to its pull request before a |
| 451 | * person is asked instead. |
| 452 | */ |
| 453 | maxRevisions: number; |
| 454 | /** |
| 455 | * Merge through a queue: pull requests are tested together with those |
| 456 | * ahead of them, and only a combination that passed reaches the default |
| 457 | * branch. |
| 458 | */ |
| 459 | mergeQueue: boolean; |
| 460 | /** Username of the member who last changed the settings, if anyone has. */ |
| 461 | updatedBy: string | null; |
| 462 | /** RFC 3339. */ |
| 463 | updatedAt: string | null; |
| 464 | }; |
| 465 | |
| 466 | /** The settings a member can change. */ |
| 467 | export type RepoSettingsInput = Omit<RepoSettings, "updatedBy" | "updatedAt">; |
| 468 | |
| 469 | /** The next step for a pull request g1t is seeing through, already claimed. */ |
| 470 | export type Advance = |
| 471 | | { action: "none" } |
| 472 | | { action: "review" | "revise" | "catch_up"; job: LifecycleJob }; |
| 473 | |
| 474 | /** What a sandbox needs to review a pull request. */ |
| 475 | export type ReviewJob = { |
| 476 | runId: string; |
| 477 | /** Lets the sandbox, and nothing else, report this review. */ |
| 478 | token: string; |
| 479 | /** The repository holding the commit: the fork, or the repository itself. */ |
| 480 | source: RepoPath; |
| 481 | commit: string; |
| 482 | repo: RepoPath; |
| 483 | defaultBranch: string; |
| 484 | number: number; |
| 485 | title: string; |
| 486 | description: string; |
| 487 | /** The issue the pull request is for, which says what it should achieve. */ |
| 488 | issue: Issue | null; |
| 489 | /** Who opened the pull request, and so can read its source. */ |
| 490 | author: User; |
| 491 | }; |
| 492 | |
| 493 | export type OpenIssueInput = { |
| 494 | title: string; |
| 495 | body: string; |
| 496 | labels?: string[]; |
| 497 | checks?: string[]; |
| 498 | }; |
| 499 | |
| 500 | export type UpdateIssueInput = { |
| 501 | title?: string; |
| 502 | body?: string; |
| 503 | labels?: string[]; |
| 504 | /** Usernames of the people it is assigned to; replaces the whole set. */ |
| 505 | assignees?: string[]; |
| 506 | }; |
| 507 | |
| 508 | export type OpenPullInput = { |
| 509 | /** The number of the issue this is for. */ |
| 510 | issue?: number; |
| 511 | /** Defaults to the issue's title; required without an issue. */ |
| 512 | title?: string; |
| 513 | /** What changed and why. Usually set later, when a draft is marked ready. */ |
| 514 | body?: string; |
| 515 | /** |
| 516 | * A branch of the repository that already holds the change. The pull |
| 517 | * request is then ready for review at once and has no fork. |
| 518 | */ |
| 519 | branch?: string; |
| 520 | agent: string; |
| 521 | runtime: Runtime; |
| 522 | }; |
| 523 | |
| 524 | /** Issues, pull requests, comments and sessions. */ |
| 525 | export interface WorkApi { |
| 526 | openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>; |
| 527 | /** Newest first. */ |
| 528 | listIssues( |
| 529 | repo: RepoPath, |
| 530 | viewer: Viewer, |
| 531 | filter?: { state?: State; label?: string }, |
| 532 | ): Promise<Result<Issue[]>>; |
| 533 | getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>; |
| 534 | /** The author or a member of the workspace may. */ |
| 535 | updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>; |
| 536 | closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>; |
| 537 | reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>; |
| 538 | /** The default labels, then every other label in use on the repository. */ |
| 539 | listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<string[]>>; |
| 540 | /** How many issues and pull requests are open. */ |
| 541 | counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>; |
| 542 | |
| 543 | /** |
| 544 | * On an issue or a pull request. On a pull request it may name a line of |
| 545 | * the change and carry a verdict; nobody can give a verdict on their own. |
| 546 | */ |
| 547 | addComment(actor: User, repo: RepoPath, number: number, comment: NewComment): Promise<Result<Comment>>; |
| 548 | |
| 549 | /** |
| 550 | * Begins a run of the acceptance checks for a pull request that is ready |
| 551 | * for review. For the runner service, which starts the sandbox. |
| 552 | */ |
| 553 | startChecks(pullId: string): Promise<Result<CheckJob>>; |
| 554 | /** |
| 555 | * What a sandbox says about its run. With no results and no error it has |
| 556 | * started; `skip` forgets a run that will not be carried out. |
| 557 | */ |
| 558 | reportChecks(runId: string, token: string, report: CheckReport): Promise<Result<CheckRun>>; |
| 559 | /** Begins a review by a g1t agent. For the runner service. */ |
| 560 | startReview(pullId: string): Promise<Result<ReviewJob>>; |
| 561 | /** Records that a review could not be written. For the runner service. */ |
| 562 | failReview(runId: string, token: string, error: string): Promise<Result<boolean>>; |
| 563 | |
| 564 | /** |
| 565 | * Works out the next step for a pull request g1t is seeing through and, |
| 566 | * if there is one to take now, claims it, so that it is taken once |
| 567 | * however often this is called. For the runner service. |
| 568 | */ |
| 569 | advance(pullId: string): Promise<Advance>; |
| 570 | /** Records that a step could not be carried out, so a person is asked. */ |
| 571 | stall(pullId: string, reason: string): Promise<boolean>; |
| 572 | /** Ids of the open pull requests g1t is seeing through. */ |
| 573 | managedPulls(repoId?: string): Promise<string[]>; |
| 574 | |
| 575 | /** A repository's merge queue: what is in it, in order, and what recently left. */ |
| 576 | queue(repo: RepoPath, viewer: Viewer): Promise<Result<QueueView>>; |
| 577 | /** |
| 578 | * The next batch of combined states to test for a repository, one per |
| 579 | * entry; empty while a batch is being tested or nothing waits. |
| 580 | */ |
| 581 | queueBuild(repoId: string): Promise<QueueJob[]>; |
| 582 | /** Reports that a combined state could not be built or checked. */ |
| 583 | failQueue(entryId: string, token: string, error: string): Promise<Result<QueueState>>; |
| 584 | /** Sends the agent working on a pull request a message, for its next step. */ |
| 585 | messageAgent(actor: User, repo: RepoPath, number: number, body: string): Promise<Result<AgentMessage>>; |
| 586 | /** Takes a pull request out of the merge queue. Members only. */ |
| 587 | removeFromQueue(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 588 | |
| 589 | getSettings(repo: RepoPath, viewer: Viewer): Promise<Result<RepoSettings>>; |
| 590 | /** Members of the repository's workspace only. */ |
| 591 | updateSettings(actor: User, repo: RepoPath, settings: RepoSettingsInput): Promise<Result<RepoSettings>>; |
| 592 | /** |
| 593 | * What the runner needs to bring a pull request up to date because a |
| 594 | * merge of it was asked for. Null if none was. |
| 595 | */ |
| 596 | catchUpJob(pullId: string): Promise<LifecycleJob | null>; |
| 597 | /** |
| 598 | * Claims a short step for the agent on a pull request to answer the |
| 599 | * questions and handoffs it was sent while not at work, and hands them |
| 600 | * over, marked read. Null when there is nothing waiting or it cannot |
| 601 | * take a step now. |
| 602 | */ |
| 603 | wakeForMessages(pullId: string): Promise<Wake | null>; |
| 604 | |
| 605 | /** |
| 606 | * Opens a pull request: a draft with a fork to push to, or, given a |
| 607 | * branch, one ready for review. |
| 608 | */ |
| 609 | openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>; |
| 610 | /** Newest first. */ |
| 611 | listPulls(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Pull[]>>; |
| 612 | getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>; |
| 613 | /** |
| 614 | * Changes who a pull request is assigned to and whose review is asked |
| 615 | * for; each list given replaces the whole set. Asking for `g1t-agent`'s |
| 616 | * review does not by itself start one: the runner's `review` does. |
| 617 | */ |
| 618 | updatePull( |
| 619 | actor: User, |
| 620 | repo: RepoPath, |
| 621 | number: number, |
| 622 | changes: { assignees?: string[]; reviewers?: string[] }, |
| 623 | ): Promise<Result<Pull>>; |
| 624 | /** Marks a draft ready for review and sets its description. */ |
| 625 | readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>; |
| 626 | closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>; |
| 627 | /** |
| 628 | * Lands the pull request on the repository's default branch. Unless |
| 629 | * `keepIssueOpen`, that resolves the issue it was for: the issue closes |
| 630 | * naming this pull request, and the others still in progress for it close |
| 631 | * as superseded. Only members of the repository's workspace may merge. |
| 632 | * |
| 633 | * If the default branch has moved, the pull request is brought up to date |
| 634 | * first and lands when that is done; it comes back still open, and |
| 635 | * `PullDetail.landing` is true meanwhile. A repository that requires pull |
| 636 | * requests to be up to date refuses instead. |
| 637 | */ |
| 638 | mergePull( |
| 639 | actor: User, |
| 640 | repo: RepoPath, |
| 641 | number: number, |
| 642 | options?: { |
| 643 | keepIssueOpen?: boolean; |
| 644 | /** Merge although the acceptance checks have not passed. */ |
| 645 | ignoreChecks?: boolean; |
| 646 | }, |
| 647 | ): Promise<Result<Pull>>; |
| 648 | /** |
| 649 | * Drafts and open pull requests the viewer started, most recently active |
| 650 | * first, each with where it stands if g1t is seeing it through. |
| 651 | */ |
| 652 | listActivePulls( |
| 653 | viewer: Viewer, |
| 654 | ): Promise<{ pull: Pull; issue: Issue | null; lifecycle: Lifecycle | null }[]>; |
| 655 | |
| 656 | /** |
| 657 | * Records an outcome to plan for. Members only. For the runner service, |
| 658 | * which starts the sandbox in which an agent writes the plan. |
| 659 | */ |
| 660 | startPlan(actor: User, repo: RepoPath, brief: string): Promise<Result<PlanJob>>; |
| 661 | /** Records that a plan could not be written. For the runner service. */ |
| 662 | failPlan(planId: string, token: string, error: string): Promise<Result<boolean>>; |
| 663 | /** Members only. */ |
| 664 | getPlan(repo: RepoPath, viewer: Viewer, id: string): Promise<Result<Plan>>; |
| 665 | /** Newest first. Members only. */ |
| 666 | listPlans(repo: RepoPath, viewer: Viewer): Promise<Result<Plan[]>>; |
| 667 | /** |
| 668 | * Opens a plan's issues, each blocked by the ones it depends on. With |
| 669 | * `assign`, each is queued for a g1t agent. `keep` holds the positions, |
| 670 | * from 1, of the issues to open; all of them when absent. Once. |
| 671 | */ |
| 672 | applyPlan( |
| 673 | actor: User, |
| 674 | repo: RepoPath, |
| 675 | id: string, |
| 676 | options?: { assign?: boolean; keep?: number[] }, |
| 677 | ): Promise<Result<Plan>>; |
| 678 | /** Asks for a g1t agent to take an issue as soon as it can, or withdraws that. */ |
| 679 | queueIssue(actor: User, repo: RepoPath, number: number, queued: boolean): Promise<Result<boolean>>; |
| 680 | /** Issues waiting for a g1t agent that can be given one now. For the runner. */ |
| 681 | readyIssues(repoId?: string): Promise<ReadyIssue[]>; |
| 682 | |
| 683 | /** Open issues assigned to the viewer, most recently changed first. */ |
| 684 | listAssignedIssues(viewer: Viewer): Promise<Issue[]>; |
| 685 | |
| 686 | appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>; |
| 687 | readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * What to pass `ReposApi.compare` to see what a pull request changes. |
| 692 | * |
| 693 | * A fork is compared as a whole. A branch is compared by name while the |
| 694 | * pull request is open, and by the commit it was merged or closed at |
| 695 | * afterwards, so later pushes to the branch do not change the record. |
| 696 | */ |
| 697 | export function pullComparison(pull: Pull): { |
| 698 | repoId: string; |
| 699 | base: string | null; |
| 700 | head: string | null; |
| 701 | } { |
| 702 | if (pull.forkRepoId) return { repoId: pull.forkRepoId, base: pull.mergeBase, head: null }; |
| 703 | const settled = pull.status === "merged" || pull.status === "closed"; |
| 704 | return { |
| 705 | repoId: pull.repoId, |
| 706 | base: pull.mergeBase, |
| 707 | head: (settled && pull.headCommit) || pull.branch, |
| 708 | }; |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /** Where a pull request in a merge queue stands. */ |
| 713 | /** Where one issue of an applied plan stands. */ |
| 714 | export type IssueProgress = { |
| 715 | number: number; |
| 716 | title: string; |
| 717 | /** |
| 718 | * `blocked`, `waiting` (for an agent), `open`, a lifecycle stage, |
| 719 | * `landed` or `closed`. |
| 720 | */ |
| 721 | state: string; |
| 722 | detail: string; |
| 723 | /** The issues it is waiting on that are still open. */ |
| 724 | blockedBy: number[]; |
| 725 | pull: number | null; |
| 726 | agent: string | null; |
| 727 | }; |
| 728 | |
| 729 | /** A message a person sent an agent at work on a pull request. */ |
| 730 | export type AgentMessage = { |
| 731 | id: string; |
| 732 | author: string; |
| 733 | body: string; |
| 734 | createdAt: string; |
| 735 | /** When the agent received it; null until then. */ |
| 736 | deliveredAt: string | null; |
| 737 | /** `message` from a person; from an agent a `question`, `handoff` or `answer`. */ |
| 738 | kind: "message" | "question" | "handoff" | "answer"; |
| 739 | /** The pull request whose agent sent it, when an agent did. */ |
| 740 | fromNumber: number | null; |
| 741 | /** The pull request it was sent to. */ |
| 742 | toNumber: number; |
| 743 | /** The reply to a question or handoff, once there is one. */ |
| 744 | answer: string | null; |
| 745 | declined: boolean; |
| 746 | /** For the sending agent: what to expect when the one it asked is not at work. */ |
| 747 | hint?: string; |
| 748 | }; |
| 749 | |
| 750 | export type QueueState = "waiting" | "testing" | "passed" | "failed" | "landed" | "removed"; |
| 751 | |
| 752 | /** One pull request's place in a merge queue. */ |
| 753 | export type QueueEntry = { |
| 754 | id: string; |
| 755 | number: number; |
| 756 | title: string; |
| 757 | agent: string; |
| 758 | state: QueueState; |
| 759 | /** The pull requests merged ahead of it in the state being tested, in order. */ |
| 760 | ahead: number[]; |
| 761 | baseCommit: string | null; |
| 762 | combinedCommit: string | null; |
| 763 | error: string | null; |
| 764 | results: CheckResult[]; |
| 765 | /** Username of whoever merged it into the queue: a person, or `g1t`. */ |
| 766 | enqueuedBy: string; |
| 767 | /** RFC 3339. */ |
| 768 | createdAt: string; |
| 769 | /** RFC 3339. */ |
| 770 | finishedAt: string | null; |
| 771 | }; |
| 772 | |
| 773 | /** A repository's merge queue: what is in it, in order, and what recently left. */ |
| 774 | export type QueueView = { |
| 775 | enabled: boolean; |
| 776 | active: QueueEntry[]; |
| 777 | /** Newest first. */ |
| 778 | recent: QueueEntry[]; |
| 779 | }; |
| 780 | |
| 781 | export type QueueStackItem = { |
| 782 | number: number; |
| 783 | title: string; |
| 784 | /** The repository holding the change, and its branch. */ |
| 785 | source: RepoPath; |
| 786 | branch: string; |
| 787 | commit: string; |
| 788 | }; |
| 789 | |
| 790 | /** What a sandbox needs to build and check one combined state. */ |
| 791 | export type QueueJob = { |
| 792 | entryId: string; |
| 793 | token: string; |
| 794 | repo: RepoPath; |
| 795 | defaultBranch: string; |
| 796 | baseCommit: string; |
| 797 | branch: string; |
| 798 | stack: QueueStackItem[]; |
| 799 | checks: string[]; |
| 800 | /** The checks of issues already completed: the default branch's contract. */ |
| 801 | contractChecks: string[]; |
| 802 | actor: User; |
| 803 | }; |