Skip to content

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.sh
1,511 linesCodeBlameRaw
1import type { ChecksApi } from "./checks";
2import type { CodeownersReport, PullCodeOwners } from "./codeowners";
3import type { G1tEvent } from "./events";
4import type { User, Viewer } from "./identity";
5import type { PullBranchUpdate, RepoPath, UpdateMethod } from "./repos";
6import type { MergeMethod } from "./rules";
7import type { Result } from "./result";
8import type { MergeRules, RulesApi } from "./rules";
9
10/**
11 * The filter on lists of issues and pull requests. An open pull request is
12 * a draft or one ready for review; a closed one was merged or closed
13 * without merging.
14 */
15export type State = "open" | "closed";
16
17/** Why an issue was closed. */
18export type IssueReason = "completed" | "not_planned";
19
20/**
21 * Something that should change in a repository: a bug, a feature, a
22 * question. Opened by a person, an agent or an integration. Pull requests
23 * are made against it; the one that is merged resolves it.
24 *
25 * Issues and pull requests share one sequence of numbers per repository.
26 */
27export type Issue = {
28 id: string;
29 repoId: string;
30 /** Shown as `#12`. */
31 number: number;
32 title: string;
33 /** Markdown. Also what an agent is given to work from. */
34 body: string;
35 labels: string[];
36 state: State;
37 /** Set when closed. */
38 reason: IssueReason | null;
39 /** The number of the pull request whose merge closed this issue. */
40 resolvedBy: number | null;
41 /** Who opened it: a person, an integration, or g1t (`kind` `agent`) for one its agent filed while at work. */
42 author: User;
43 /**
44 * For an issue g1t's agent filed: the person it was working for. They may
45 * manage it as its author could. See `workOwner`.
46 */
47 requestedBy: User | null;
48 /** RFC 3339. */
49 createdAt: string;
50 /** RFC 3339. */
51 updatedAt: string;
52 /** RFC 3339. */
53 closedAt: string | null;
54 /** Pull requests made against this issue, in any state. */
55 pullCount: number;
56 commentCount: number;
57 /** Usernames of the people it is assigned to. */
58 assignees: string[];
59 /** The numbers of the issues that have to be merged before this one is worked on. */
60 blockedBy: number[];
61 /**
62 * The agent working on it now: the one behind its newest pull request
63 * that is still in progress in a fork, such as `g1t`.
64 */
65 agent: string | null;
66 /** The milestone it is in, if any. */
67 milestone?: MilestoneRef | null;
68};
69
70/**
71 * A label of a repository: a name, a color and what it means. Issues and
72 * pull requests carry labels by name; names are lowercase.
73 */
74export type Label = {
75 name: string;
76 /** Six hex digits, without `#`. */
77 color: string;
78 description: string;
79 /** How many issues carry it, open or closed. */
80 issues: number;
81 /** How many pull requests carry it, in any state. */
82 pulls: number;
83};
84
85/** A milestone, as an issue or pull request names it. */
86export type MilestoneRef = { number: number; title: string };
87
88/**
89 * A goal, with an optional due date, that issues and pull requests are
90 * gathered under. Its progress is how many of them are closed.
91 */
92export type Milestone = {
93 /** Numbered from 1 in each repository, apart from issues. */
94 number: number;
95 title: string;
96 /** Markdown. */
97 description: string;
98 /** `YYYY-MM-DD`. */
99 dueOn: string | null;
100 state: State;
101 /** Open issues and pull requests in it. */
102 openItems: number;
103 /** Closed issues, and merged or closed pull requests, in it. */
104 closedItems: number;
105 createdAt: string;
106 updatedAt: string;
107 closedAt: string | null;
108};
109
110/** One milestone and what is in it, newest first. */
111export type MilestoneDetail = { milestone: Milestone; issues: Issue[]; pulls: Pull[] };
112
113/** How `setLabels` changes an item's labels. */
114export type LabelChange = "set" | "add" | "remove";
115
116/**
117 * Whose an issue or a pull request is to answer for: whoever asked g1t for
118 * it, or its author. They may change, close and steer it, are never asked to
119 * review it and cannot approve it, and see it as theirs. Mirrors
120 * `Pull::owner` in the Rust contracts.
121 */
122export function workOwner(item: Pick<Pull, "author" | "requestedBy">): User {
123 return item.requestedBy ?? item.author;
124}
125
126/** `draft` is still being worked on; `open` is ready for review. */
127export type PullStatus = "draft" | "open" | "merged" | "closed";
128
129/** Where the agent runs: on g1t's sandboxes, or in someone's own session. */
130export type Runtime = "hosted" | "external";
131
132/**
133 * A proposed change. It is made either in a fork created for it, which is
134 * how agents work, on a branch pushed to the repository itself, or on a
135 * branch of someone's fork of it (`headRepo`).
136 */
137export type Pull = {
138 id: string;
139 repoId: string;
140 /** Shown as `#12`. */
141 number: number;
142 /** The number of the issue this is for, if any. */
143 issue: number | null;
144 title: string;
145 /** Markdown: what changed and why. Set when marked ready. */
146 body: string | null;
147 /** A label for the agent doing the work, e.g. `claude-code`. */
148 agent: string;
149 runtime: Runtime;
150 status: PullStatus;
151 /** The fork holding the change, unless it is on a branch. */
152 fork: RepoPath | null;
153 /** The fork's repository id. */
154 forkRepoId: string | null;
155 /**
156 * The branch holding the change, unless it is in a working copy (`fork`):
157 * of `headRepo` when set, else of the repository.
158 */
159 branch: string | null;
160 /**
161 * A fork of the repository (its `parentId`, directly or through other
162 * forks) whose `branch` holds the change, when it was opened from one.
163 * Null for a branch of the repository itself and for a working copy.
164 */
165 headRepo?: RepoPath | null;
166 /** `headRepo`'s id. */
167 headRepoId?: string | null;
168 headCommit: string | null;
169 /**
170 * For a merged pull request, what the branch pointed to before the merge.
171 * Comparing against it shows what the pull request changed.
172 */
173 mergeBase: string | null;
174 /** Username of whoever merged it. */
175 mergedBy: string | null;
176 /** RFC 3339. */
177 mergedAt: string | null;
178 /** How it merged, once merged. */
179 mergeMethod?: MergeMethod | null;
180 /** Where its merge left the base: the merge or squash commit, the last rebased one, or its head. */
181 mergeCommit?: string | null;
182 /** Merge it on its own once everything it needs is met, as a person asked. */
183 autoMerge?: AutoMerge | null;
184 /**
185 * The issues it closes when it merges into the default branch: its issue and
186 * those its title and description name after a closing keyword (`Fixes #12`).
187 */
188 closes?: number[];
189 /** Its branch was deleted after it merged or closed, and can be restored at `headCommit`. */
190 headBranchDeleted?: boolean;
191 /**
192 * Set on a pull request closed because another one for the same issue was
193 * merged: that one's number.
194 */
195 supersededBy: number | null;
196 /**
197 * Where the latest run of the issue's acceptance checks stands, if there
198 * has been one against the current head.
199 */
200 checkStatus: CheckStatus | null;
201 /** The files it changes, as of its latest push. */
202 files: ChangedFile[];
203 /** Usernames of the people it is assigned to. */
204 assignees: string[];
205 /**
206 * Those whose review was asked for: usernames, and `g1t` when a g1t
207 * agent was asked.
208 */
209 reviewers: string[];
210 /**
211 * Teams whose review was asked for, as `workspace/slug`. A team stays here
212 * after review assignment picks people from it, who are in `reviewers`.
213 */
214 teamReviewers?: string[];
215 /** The labels it carries, by name. */
216 labels?: string[];
217 /** The milestone it is in, if any. */
218 milestone?: MilestoneRef | null;
219 /**
220 * The branch it merges into. Lists and `getPull` name it; null only in
221 * what services pass between themselves, for the default branch.
222 */
223 base?: string | null;
224 /** Who opened it: a person, or g1t (`kind` `agent`, username `g1t`) for a change g1t made. */
225 author: User;
226 /**
227 * For a change g1t made: the person who asked for it, by assigning an issue
228 * or handing g1t the work. They answer for it as its author would. See
229 * `workOwner`.
230 */
231 requestedBy: User | null;
232 /** RFC 3339. */
233 createdAt: string;
234 /** RFC 3339. */
235 updatedAt: string;
236 /** Who last moved its head (a user id), and when; absent until a push after rulesets arrived. */
237 headPushedBy?: string;
238 headPushedAt?: string;
239};
240
241/** One file a pull request changes, and by how much. */
242export type ChangedFile = { path: string; additions: number; deletions: number };
243
244/**
245 * Another pull request in progress that changes some of the same files. Two
246 * for the same issue are alternatives; two for different issues are heading
247 * for a conflict.
248 */
249export type Overlap = {
250 number: number;
251 title: string;
252 /** The number of the issue the other pull request is for. */
253 issue: number | null;
254 /** The files both change. */
255 paths: string[];
256};
257
258/**
259 * On a pull request, `failed` means the merge queue took it out, until its
260 * head moves. The other states are from runs of commands written on issues,
261 * which g1t no longer runs.
262 */
263export type CheckStatus = "queued" | "running" | "passed" | "failed" | "errored";
264
265/** How one command went, in a run recorded before checks were workflows. */
266export type CheckResult = {
267 command: string;
268 passed: boolean;
269 /** Null when the command was stopped for taking too long. */
270 exitCode: number | null;
271 /** What the command printed; the end of it, when there was a lot. */
272 output: string;
273 durationMs: number;
274};
275
276/**
277 * A record against a pull request's head: the merge queue taking it out,
278 * with why, or an earlier run of commands written on its issue.
279 */
280export type CheckRun = {
281 id: string;
282 /** The commit that was checked. */
283 headCommit: string;
284 status: CheckStatus;
285 results: CheckResult[];
286 /** Why the checks could not be run, when `status` is `errored`. */
287 error: string | null;
288 /** RFC 3339. */
289 createdAt: string;
290 /** RFC 3339. */
291 finishedAt: string | null;
292};
293
294/** A reviewer's decision on a pull request. */
295export type Verdict = "approve" | "request_changes";
296
297/**
298 * A comment on an issue or a pull request. On a pull request it can sit on
299 * one line of the change, and it can carry a reviewer's verdict.
300 */
301export type Comment = {
302 id: string;
303 /**
304 * Something a person or an agent wrote, or something that happened: an
305 * assignment, a review asked for, a close.
306 */
307 kind: "comment" | "event";
308 author: User;
309 /**
310 * Markdown. For an event, what its author did, as the rest of a sentence
311 * that starts with their name: "assigned ana".
312 */
313 body: string;
314 /** The file commented on, for a comment on a line. */
315 path: string | null;
316 /** The line of that file, as numbered after the change. */
317 line: number | null;
318 verdict: Verdict | null;
319 /** RFC 3339. */
320 createdAt: string;
321 /** When its text was last edited, RFC 3339; absent if it never was. */
322 editedAt?: string;
323 /**
324 * Set when one of the workspace's agents wrote it, as itself. `author`
325 * is then the agent (its id, its handle as `username`, kind `agent`):
326 * show it by `agent.displayName` with an Agent badge, never as a person.
327 */
328 agent?: AgentRef;
329 /** Who the agent acted for, whose access capped it. Set with `agent`. */
330 actingFor?: User;
331 /**
332 * An agent's review. Its `verdict` (none for a review that only
333 * comments) is shown but advisory: it never counts toward required
334 * approvals or code owners, and never blocks a merge.
335 */
336 advisory?: boolean;
337};
338
339/**
340 * One of a workspace's own agents, as a comment or review it wrote before
341 * g1t's agents were removed shows it: Margo (@margo), with the face drawn
342 * from `avatarSeed`. Kept so those comments still render.
343 */
344export type AgentRef = {
345 id: string;
346 handle: string;
347 displayName: string;
348 avatarSeed: string;
349};
350
351export type NewComment = {
352 /** May be empty when approving. */
353 body: string;
354 path?: string;
355 line?: number;
356 verdict?: Verdict;
357};
358
359export type CheckReport = { results?: CheckResult[]; error?: string; skip?: boolean };
360
361export type SessionEntryKind = "prompt" | "message" | "tool_call" | "tool_result" | "note" | "skill";
362
363/** One step of an agent's session: the "why" behind a pull request's commits. */
364export type SessionEntry = {
365 seq: number;
366 kind: SessionEntryKind;
367 text: string;
368 /** For tool calls and results. */
369 tool: string | null;
370 /** The fork's head commit when this entry was recorded, if known. */
371 commit: string | null;
372 /** RFC 3339. */
373 at: string;
374};
375
376export type NewSessionEntry = Pick<SessionEntry, "kind" | "text"> &
377 Partial<Pick<SessionEntry, "tool" | "commit">>;
378
379export type IssueDetail = {
380 issue: Issue;
381 /** Every pull request made against it, oldest first. */
382 pulls: Pull[];
383 comments: Comment[];
384};
385
386export type PullDetail = {
387 pull: Pull;
388 /** The issue it is for, if any. */
389 issue: Issue | null;
390 comments: Comment[];
391 /** The latest record against its head: the merge queue taking it out. */
392 checks: CheckRun | null;
393 /** Other pull requests in progress that change the same files. */
394 overlaps: Overlap[];
395 /**
396 * Whether the branch it would merge into has moved on without it, so that
397 * it has to catch up before it can merge.
398 */
399 behind: boolean;
400 /**
401 * Where it stands on its way to being merged, for a pull request g1t is
402 * seeing through. Null on anyone else's.
403 */
404 lifecycle: Lifecycle | null;
405 /**
406 * A merge was asked for while it was behind: g1t is bringing it up to
407 * date and will then land it.
408 */
409 landing: boolean;
410 /** Why g1t stopped working on it, if it did. */
411 stalled: string | null;
412 /** What workflow runs said about its head commit, one per workflow. */
413 statuses?: CommitStatus[];
414 /**
415 * Whether it merges cleanly into the branch it targets, worked out ahead
416 * of time whenever either side moves.
417 */
418 mergeable?: Mergeable;
419 /** When `mergeable` is `conflicting`: the files that conflict. */
420 conflicts?: string[];
421 /** Earlier records like `checks`, newest first, without their output. */
422 earlierChecks?: CheckRun[];
423 /**
424 * The checks the default branch's protection requires, each as it stands
425 * on the head commit. Empty when none are required.
426 */
427 requiredChecks?: RequiredCheck[];
428 /**
429 * Who owns the files it changes (the CODEOWNERS file of the branch it
430 * merges into) and whose approval is still needed. Absent without one.
431 */
432 codeOwners?: PullCodeOwners | null;
433 /**
434 * The rules of the branch it merges into it does not meet yet, for whoever
435 * is looking: what refuses the merge, what they may bypass, and what rulesets
436 * in evaluate would refuse. Absent once it is closed or merged.
437 */
438 rules?: MergeRules | null;
439};
440
441/** Where a required check stands on a commit; `expected` when nothing has reported it yet. */
442export type RequiredState = "success" | "failure" | "pending" | "expected";
443
444/** One check a branch's protection requires, as it stands on a commit. */
445export type RequiredCheck = {
446 /** A workflow's name, such as `CI`, or another status's context. */
447 name: string;
448 state: RequiredState;
449 description: string | null;
450 /** Where to see more: the workflow run, for one a workflow reported. */
451 targetUrl: string | null;
452};
453
454/** A check name reported on a repository's commits lately, for choosing required checks. */
455export type SeenCheck = {
456 name: string;
457 /** The events it was reported for, such as `pull_request`; empty for a status that names none. */
458 events: string[];
459 /** RFC 3339. */
460 lastSeen: string;
461};
462
463/**
464 * A status context's check name: `CI / pull_request` is the `CI` check,
465 * reported for a `pull_request` event. A context that does not end in an
466 * event, such as `g1t / deploy`, is its own name. As the work service reads it.
467 */
468export function checkName(context: string): string {
469 const at = context.lastIndexOf(" / ");
470 if (at <= 0) return context;
471 return STATUS_EVENTS.has(context.slice(at + 3)) ? context.slice(0, at) : context;
472}
473
474const STATUS_EVENTS = new Set([
475 "push",
476 "pull_request",
477 "pull_request_target",
478 "pull_request_review",
479 "merge_group",
480 "workflow_dispatch",
481 "workflow_run",
482 "workflow_call",
483 "schedule",
484 "release",
485 "issues",
486 "issue_comment",
487 "repository_dispatch",
488]);
489
490/**
491 * Whether a pull request merges cleanly into the branch it targets:
492 * `unknown` when it was never worked out or could not be, `checking` while
493 * a probe merges the two.
494 */
495export type Mergeable = "clean" | "conflicting" | "unknown" | "checking";
496
497/** What a sandbox needs to find out whether a pull request merges cleanly. */
498export type MergecheckJob = {
499 pullId: string;
500 /** Lets the sandbox, and nothing else, report this probe. */
501 token: string;
502 repo: RepoPath;
503 number: number;
504 defaultBranch: string;
505 /** The default branch's commit to merge into. */
506 base: string;
507 /** The repository holding the change: its fork, or the repository. */
508 source: RepoPath;
509 /** The branch of `source` holding it. */
510 branch: string;
511 /** The change's commit. */
512 head: string;
513 /** Who the pull request is for (`workOwner`: whoever asked g1t for it, or its author), and so can read its source. */
514 author: User;
515};
516
517/** What a workflow run (or another tool) says about a commit. */
518export type CommitStatus = {
519 /** What reported it, such as `CI / push`. */
520 context: string;
521 state: "pending" | "success" | "failure" | "error";
522 description: string | null;
523 targetUrl: string | null;
524 updatedAt: string;
525 /** The integration that reported it: `actions`, `deployments`, `security`, `g1t` or `api`. */
526 source?: string;
527 /** Set on the status a check run stands as: the check run's id. */
528 checkRunId?: string;
529};
530
531/**
532 * A step on the way from an assigned issue to a pull request that is ready
533 * to merge. g1t takes each one without being asked: `working` (the agent is
534 * making the change), `checking`, `reviewing`, `revising` (the agent is
535 * addressing failed checks or a review), `catching_up` (merging in the
536 * branch it would land on), `answering` (woken to answer another agent),
537 * then `ready` for a person to merge. `needs_you`
538 * means g1t has stopped and a person decides what happens next.
539 */
540export type Stage =
541 | "working"
542 | "checking"
543 | "reviewing"
544 | "revising"
545 | "catching_up"
546 | "answering"
547 | "queued"
548 | "ready"
549 | "needs_you";
550
551export type Lifecycle = {
552 stage: Stage;
553 /** One sentence saying what is happening, or why it stopped. */
554 detail: string;
555 /** How many times the agent has been sent back to revise it. */
556 revisions: number;
557};
558
559/**
560 * How a repository wants its pull requests handled. A repository that has
561 * changed nothing has the defaults.
562 */
563export type RepoSettings = {
564 /**
565 * Land a g1t agent's pull request without a person once it is ready:
566 * checks passed and approved as the settings below require.
567 */
568 autoMerge: boolean;
569 /**
570 * The checks that must pass on a pull request's head before it may merge
571 * into the default branch, by name: a workflow's name (`CI`) or another
572 * status's context (`g1t / deploy`). The same for people and agents, and
573 * for the merge queue.
574 */
575 requiredChecks: string[];
576 /**
577 * Refuse to merge a pull request that does not contain the default
578 * branch's latest commits, so that what merges is what was checked. When
579 * off, merging one that is behind brings it up to date first.
580 */
581 requireUpToDate: boolean;
582 /**
583 * How many approving reviews a pull request needs before it may merge. A
584 * reviewer who has since asked for changes blocks it.
585 */
586 requiredApprovals: number;
587 /** Whether a g1t agent's approval counts towards `requiredApprovals`. */
588 countAgentApprovals: boolean;
589 /** Whether someone who may merge can bypass required checks that have not passed. */
590 allowIgnoringChecks: boolean;
591 /**
592 * Merge through a queue: pull requests are tested together with those
593 * ahead of them, and only a combination that passed reaches the default
594 * branch.
595 */
596 mergeQueue: boolean;
597 /**
598 * Refuse to merge until the code owners of every file it changes have
599 * approved, as many as each section asks. People only; `g1t` only where
600 * the file names `@g1t`.
601 */
602 requireCodeOwnerReview?: boolean;
603 /**
604 * Whether issues can be opened in it: null for the default, which is on
605 * for a repository and off for a fork of one. Existing issues stay
606 * readable either way.
607 */
608 hasIssues?: boolean | null;
609 /** Whether issues can be opened in it now: `hasIssues`, or its default. */
610 issuesEnabled?: boolean;
611 /** Which merge methods pull requests may use (at least one); rules can narrow them per branch. */
612 allowMergeCommit: boolean;
613 allowSquashMerge: boolean;
614 allowRebaseMerge: boolean;
615 allowFastForward: boolean;
616 /** The method offered first, and used when none is named. */
617 defaultMergeMethod: MergeMethod;
618 /** What merge and squash commits say unless their merger writes it. */
619 mergeCommitMessage: CommitMessageDefault;
620 squashCommitMessage: CommitMessageDefault;
621 /**
622 * For `custom`: templates whose `{title}`, `{number}`, `{body}`, `{branch}`,
623 * `{head_repo}`, `{base}`, `{author}`, `{commits}`, `{issues}` and
624 * `{co_authors}` are filled in.
625 */
626 mergeCommitTemplate: string | null;
627 squashCommitTemplate: string | null;
628 /** Offer to bring a pull request up to date whenever its base has new commits. */
629 suggestUpdatingBranches: boolean;
630 /** Let people turn on auto-merge for a pull request. */
631 allowAutoMerge: boolean;
632 /** Delete a pull request's branch once it merges (restorable from it). */
633 deleteBranchOnMerge: boolean;
634 /** Commits made on g1t.sh carry a `Signed-off-by:` trailer for whoever made them. */
635 requireWebCommitSignOff: boolean;
636 /** Let anyone who can read it comment on its commits. */
637 allowCommitComments: boolean;
638 /** Close the issues a pull request names when it merges into the default branch. */
639 autoCloseIssues: boolean;
640 /** Username of the member who last changed the settings, if anyone has. */
641 updatedBy: string | null;
642 /** RFC 3339. */
643 updatedAt: string | null;
644};
645
646/** What a merge or squash commit's message says by default (`pull_title_and_commits` is squash only). */
647export type CommitMessageDefault = "default" | "pull_title" | "pull_title_and_description" | "pull_title_and_commits" | "custom";
648
649/** A person's request that a pull request merge on its own once it may. */
650export type AutoMerge = {
651 method: MergeMethod;
652 commitTitle: string | null;
653 commitMessage: string | null;
654 /** Username of who asked. */
655 enabledBy: string;
656 /** RFC 3339. */
657 enabledAt: string;
658};
659
660/** A comment on a commit, or on one line (`path`, `line`) of a file it changed. */
661export type CommitComment = {
662 id: string;
663 repoId: string;
664 /** The commit's full hash. */
665 commit: string;
666 path: string | null;
667 line: number | null;
668 /** Username. */
669 author: string;
670 /** Markdown. */
671 body: string;
672 /** RFC 3339. */
673 createdAt: string;
674 updatedAt: string | null;
675};
676
677/** How a pull request may merge now, for whoever is looking (`mergeChoices`). */
678export type MergeChoices = {
679 /** The methods it may merge by: the repository's, as the rules for its base allow. In the order offered. */
680 methods: MergeMethod[];
681 /** The one offered first: the repository's default when it may be used, else the first of `methods`. */
682 defaultMethod: MergeMethod | null;
683 /** Each of `methods`, with its default commit message and whether it can be used now. */
684 options: MergeChoice[];
685 /** Its base has commits it does not have. */
686 behind: boolean;
687 /** It contains its base's head, so it can fast-forward as it is. */
688 canFastForward: boolean;
689 /** Offer to bring it up to date: it is behind, and the repository suggests (or requires) it. */
690 suggestUpdate: boolean;
691 /** The repository requires it to be up to date before it merges. */
692 requireUpToDate: boolean;
693 /** It merges through the merge queue, which lands it as tested whatever method is chosen. */
694 mergeQueue: boolean;
695 /** The viewer may turn on auto-merge for it. */
696 autoMergeAllowed: boolean;
697 /** Whether "delete the branch" starts ticked. */
698 deleteBranchDefault: boolean;
699 /** Its branch can be deleted once it merges (never a working copy's). */
700 canDeleteBranch: boolean;
701 /** Commits made merging it carry a `Signed-off-by:` trailer for the merger. */
702 signOff: boolean;
703};
704
705/** One way a pull request may merge. */
706export type MergeChoice = {
707 method: MergeMethod;
708 /** For `merge` and `squash`: the commit's default title and the rest of its message. */
709 commitTitle: string | null;
710 commitMessage: string | null;
711 /** Why it cannot merge this way now, if it cannot. */
712 unavailable: string | null;
713};
714
715/** How a pull request merges, as the merger chose. */
716export type MergeOptions = {
717 keepIssueOpen?: boolean;
718 /** Merge although required checks have not passed, where the rule requiring them allows it. */
719 ignoreChecks?: boolean;
720 /** Merge past rules a ruleset lets the actor bypass. Recorded as a bypass. */
721 bypassRules?: boolean;
722 /** The repository's default when absent. */
723 mergeMethod?: MergeMethod;
724 /** For `merge` and `squash`: the commit's title and the rest of its message. */
725 commitTitle?: string;
726 commitMessage?: string;
727 /** Refuse if its head is no longer this commit. */
728 expectedHead?: string;
729 /** Delete its branch once merged; the repository's setting when absent. */
730 deleteBranch?: boolean;
731};
732
733/** The settings a member can change. */
734export type RepoSettingsInput = Omit<RepoSettings, "updatedBy" | "updatedAt" | "issuesEnabled">;
735
736/**
737 * What the runner is to do next for a pull request: always nothing now,
738 * since no step of a pull request is carried out in a sandbox any more.
739 */
740export type Advance = { action: "none" };
741
742export type OpenIssueInput = {
743 title: string;
744 body: string;
745 labels?: string[];
746 /** Deprecated: commands, added to the body under "Definition of done". */
747 checks?: string[];
748 /** The number of the milestone to put it in. Needs the Triage role. */
749 milestone?: number;
750};
751
752export type UpdateIssueInput = {
753 title?: string;
754 body?: string;
755 labels?: string[];
756 /** Usernames of the people it is assigned to; replaces the whole set. */
757 assignees?: string[];
758 /** The number of the milestone to put it in; 0 takes it out. */
759 milestone?: number;
760 /** The issues of the same repository that have to land first; replaces the whole set. */
761 blocked_by?: number[];
762};
763
764export type OpenPullInput = {
765 /** The number of the issue this is for. */
766 issue?: number;
767 /** Defaults to the issue's title; required without an issue. */
768 title?: string;
769 /** What changed and why. Usually set later, when a draft is marked ready. */
770 body?: string;
771 /**
772 * A branch of the repository that already holds the change. The pull
773 * request is then ready for review at once and has no fork.
774 */
775 branch?: string;
776 /**
777 * A fork of the repository (directly or through other forks) whose
778 * `branch` holds the change. Needs `branch`.
779 */
780 headRepo?: RepoPath;
781 agent: string;
782 runtime: Runtime;
783 /** The branch to merge into: the default branch when left out. */
784 base?: string;
785 /**
786 * Opened from a branch as a draft, still being worked on: it can't merge
787 * until it is marked ready.
788 */
789 draft?: boolean;
790};
791
792/** One repository's pull requests from `pullsForRepos`, newest first. */
793export type RepoPulls = {
794 repoId: string;
795 /** Draft and open. */
796 open: Pull[];
797 /** Merged and closed. */
798 closed: Pull[];
799};
800
801/** Issues, pull requests, comments and sessions. */
802export interface WorkApi extends RulesApi, ChecksApi, CoordinationApi {
803 openIssue(actor: User, repo: RepoPath, input: OpenIssueInput): Promise<Result<Issue>>;
804 /** Newest first. */
805 listIssues(
806 repo: RepoPath,
807 viewer: Viewer,
808 filter?: { state?: State; label?: string; milestone?: number },
809 ): Promise<Result<Issue[]>>;
810 getIssue(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<IssueDetail>>;
811 /** The author or a member of the workspace may. */
812 updateIssue(actor: User, repo: RepoPath, number: number, input: UpdateIssueInput): Promise<Result<Issue>>;
813 closeIssue(actor: User, repo: RepoPath, number: number, reason?: IssueReason): Promise<Result<Issue>>;
814 reopenIssue(actor: User, repo: RepoPath, number: number): Promise<Result<Issue>>;
815 /** A repository's labels, by name, each with how many issues and pull requests carry it. */
816 listLabels(repo: RepoPath, viewer: Viewer): Promise<Result<Label[]>>;
817 /**
818 * Creates a label, or with `name` changes one; renaming it renames it on
819 * everything that carries it. Needs the Triage role.
820 */
821 saveLabel(
822 actor: User,
823 repo: RepoPath,
824 label: { name?: string; newName?: string; color?: string; description?: string },
825 ): Promise<Result<Label>>;
826 /** Removes a label from the repository and everything carrying it. */
827 deleteLabel(actor: User, repo: RepoPath, name: string): Promise<Result<boolean>>;
828 /** Adds the default labels the repository does not have yet; returns them all. */
829 addDefaultLabels(actor: User, repo: RepoPath): Promise<Result<Label[]>>;
830 /**
831 * The labels of an issue or a pull request, replaced, added to or taken
832 * from. Labels the repository lacks are created for someone with the
833 * Triage role. Returns its labels now.
834 */
835 setLabels(
836 actor: User,
837 repo: RepoPath,
838 number: number,
839 labels: string[],
840 change?: LabelChange,
841 ): Promise<Result<string[]>>;
842 /** Open ones by due date, then closed ones; both unless `state` says. */
843 listMilestones(repo: RepoPath, viewer: Viewer, state?: State): Promise<Result<Milestone[]>>;
844 getMilestone(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<MilestoneDetail>>;
845 /** Creates a milestone, or with `number` changes the fields given. Needs the Triage role. */
846 saveMilestone(
847 actor: User,
848 repo: RepoPath,
849 milestone: { number?: number; title?: string; description?: string; dueOn?: string; state?: State },
850 ): Promise<Result<Milestone>>;
851 deleteMilestone(actor: User, repo: RepoPath, number: number): Promise<Result<boolean>>;
852 /** How many issues and pull requests are open. */
853 counts(repo: RepoPath, viewer: Viewer): Promise<Result<{ issues: number; pulls: number }>>;
854
855 /**
856 * On an issue or a pull request. On a pull request it may name a line of
857 * the change and carry a verdict; nobody can give a verdict on their own.
858 */
859 addComment(actor: User, repo: RepoPath, number: number, comment: NewComment): Promise<Result<Comment>>;
860 /**
861 * Changes a comment's text. Its author may, and so may anyone with the
862 * Maintain role or higher; notes of what happened cannot be changed.
863 */
864 editComment(actor: User, repo: RepoPath, commentId: string, body: string): Promise<Result<Comment>>;
865 /**
866 * Deletes a comment: its author, or anyone with the Maintain role or
867 * higher. A review that gave a verdict cannot be deleted, only edited.
868 */
869 deleteComment(actor: User, repo: RepoPath, commentId: string): Promise<Result<boolean>>;
870
871 /**
872 * What a sandbox says about a run from before checks were workflows: so
873 * one still finishing is recorded.
874 */
875 reportChecks(runId: string, token: string, report: CheckReport): Promise<Result<CheckRun>>;
876 /**
877 * Claims the probe of whether a pull request merges cleanly that a
878 * `pull.mergecheck` event asked for. Refused when it is no longer wanted
879 * or the repository has as many running as it may. For the runner service.
880 */
881 startMergecheck(pullId: string): Promise<Result<MergecheckJob>>;
882 /** Records that a probe could not be carried out. For the runner service. */
883 failMergecheck(pullId: string, token: string, error: string): Promise<Result<Mergeable>>;
884
885 /**
886 * Works out the next step for a pull request g1t is seeing through and,
887 * if there is one to take now, claims it, so that it is taken once
888 * however often this is called. For the runner service.
889 */
890 advance(pullId: string): Promise<Advance>;
891 /** Ids of the open pull requests g1t is seeing through. */
892 managedPulls(repoId?: string): Promise<string[]>;
893
894 /** A repository's merge queue: what is in it, in order, and what recently left. */
895 queue(repo: RepoPath, viewer: Viewer): Promise<Result<QueueView>>;
896 /**
897 * The next batch of combined states to test for a repository, one per
898 * entry; empty while a batch is being tested or nothing waits.
899 */
900 queueBuild(repoId: string): Promise<QueueJob[]>;
901 /** Reports that a combined state could not be built or checked. */
902 failQueue(entryId: string, token: string, error: string): Promise<Result<QueueState>>;
903 /** Takes a pull request out of the merge queue. Members only. */
904 removeFromQueue(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
905
906 getSettings(repo: RepoPath, viewer: Viewer): Promise<Result<RepoSettings>>;
907 /** The check names reported on the repository's commits in the last 30 days, most recent first. */
908 seenChecks(repo: RepoPath, viewer: Viewer): Promise<Result<SeenCheck[]>>;
909 /** Members of the repository's workspace only. */
910 updateSettings(actor: User, repo: RepoPath, settings: RepoSettingsInput): Promise<Result<RepoSettings>>;
911 /** The CODEOWNERS file at a branch (the default when left out), checked. Needs Read. */
912 codeownersErrors(repo: RepoPath, viewer: Viewer, ref?: string | null): Promise<Result<CodeownersReport>>;
913
914 /**
915 * Opens a pull request: a draft with a fork to push to, or, given a
916 * branch, one ready for review.
917 */
918 openPull(actor: User, repo: RepoPath, input: OpenPullInput): Promise<Result<Pull>>;
919 /** Newest first. */
920 listPulls(
921 repo: RepoPath,
922 viewer: Viewer,
923 state?: State,
924 filter?: { label?: string; milestone?: number; base?: string },
925 ): Promise<Result<Pull[]>>;
926 /**
927 * Delivery for up to 100 repositories over UTC days `from` through
928 * `until`, over their whole history. Repositories the viewer cannot read,
929 * and forks, are left out of `projects`.
930 */
931 deliveryInsights(repoIds: string[], viewer: Viewer, from: string, until: string): Promise<DeliveryInsights>;
932 /**
933 * The newest `limit` open and closed pull requests of each repository,
934 * in one call. Repositories the viewer cannot read, and forks, are left
935 * out: ask those with `listPulls`.
936 */
937 pullsForRepos(repoIds: string[], viewer: Viewer, limit: number): Promise<RepoPulls[]>;
938 getPull(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<PullDetail>>;
939 /**
940 * Changes who a pull request is assigned to and whose review is asked
941 * for; each list given replaces the whole set. Asking for `g1t`'s
942 * review does not by itself start one: the runner's `review` does.
943 */
944 updatePull(
945 actor: User,
946 repo: RepoPath,
947 number: number,
948 changes: {
949 assignees?: string[];
950 reviewers?: string[];
951 labels?: string[];
952 /** 0 takes it out of its milestone. */
953 milestone?: number;
954 /** The branch it merges into. Needs the Write role. */
955 base?: string;
956 },
957 ): Promise<Result<Pull>>;
958 /**
959 * Brings a pull request up to date with the default branch in seconds,
960 * without a sandbox, when the two changed different files: the merge
961 * commit is pushed to its branch as `actor`, who must be whoever opened
962 * it (for a fork) or a member (for a branch). Otherwise `needs_agent`, and
963 * nothing is pushed: the runner's `update` is the way on.
964 */
965 catchUpPull(
966 actor: User,
967 repo: RepoPath,
968 number: number,
969 options?: { updateMethod?: UpdateMethod; expectedHead?: string },
970 ): Promise<Result<PullBranchUpdate>>;
971 /**
972 * Turns a pull request's auto-merge on (with how to merge) or off. On needs
973 * Write, since it merges as whoever turned it on; its author may also turn
974 * it off. Refused where the repository does not allow auto-merge or the
975 * method. One that may merge already merges at once.
976 */
977 setAutoMerge(
978 actor: User,
979 repo: RepoPath,
980 number: number,
981 enabled: boolean,
982 options?: { mergeMethod?: MergeMethod; commitTitle?: string; commitMessage?: string },
983 ): Promise<Result<Pull>>;
984 /** How a pull request may merge now: methods, default messages, auto-merge and branch deletion. */
985 mergeChoices(viewer: Viewer, repo: RepoPath, number: number): Promise<Result<MergeChoices>>;
986 /** Deletes a merged or closed pull request's branch (Push on where it is). */
987 deleteHeadBranch(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
988 /** Makes a deleted pull request branch again at its head. */
989 restoreHeadBranch(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
990 /** A commit's comments, oldest first; with no commit, the repository's, newest first, 30 a page. */
991 commitComments(viewer: Viewer, repo: RepoPath, commit?: string | null, page?: number): Promise<Result<CommitComment[]>>;
992 /** Comments on a commit, or on one line of a file it changed. Needs Read, where commit comments are on. */
993 addCommitComment(
994 actor: User,
995 repo: RepoPath,
996 commit: string,
997 body: string,
998 at?: { path: string; line: number },
999 ): Promise<Result<CommitComment>>;
1000 editCommitComment(actor: User, repo: RepoPath, id: string, body: string): Promise<Result<CommitComment>>;
1001 deleteCommitComment(actor: User, repo: RepoPath, id: string): Promise<Result<boolean>>;
1002 /** Marks a draft ready for review and sets its description. */
1003 readyPull(actor: User, repo: RepoPath, number: number, summary: string): Promise<Result<Pull>>;
1004 closePull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
1005 /** Opens a closed pull request again, as the draft it was if it was closed as one. Never a merged one. */
1006 reopenPull(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
1007 /** Turns an open pull request back into a draft; it leaves the merge queue. */
1008 convertPullToDraft(actor: User, repo: RepoPath, number: number): Promise<Result<Pull>>;
1009 /**
1010 * Lands the pull request on the repository's default branch. Unless
1011 * `keepIssueOpen`, that resolves the issue it was for: the issue closes
1012 * naming this pull request, and the others still in progress for it close
1013 * as superseded. Only members of the repository's workspace may merge.
1014 *
1015 * If the default branch has moved, the pull request is brought up to date
1016 * first and lands when that is done; it comes back still open, and
1017 * `PullDetail.landing` is true meanwhile. A repository that requires pull
1018 * requests to be up to date refuses instead.
1019 */
1020 mergePull(actor: User, repo: RepoPath, number: number, options?: MergeOptions): Promise<Result<Pull>>;
1021 /**
1022 * Drafts and open pull requests the viewer started, most recently active
1023 * first, each with where it stands if g1t is seeing it through.
1024 */
1025 listActivePulls(
1026 viewer: Viewer,
1027 ): Promise<{ pull: Pull; issue: Issue | null; lifecycle: Lifecycle | null }[]>;
1028 /**
1029 * The issues and pull requests a person opened, a page at a time, only
1030 * on repositories the viewer may read. Not found for no such account.
1031 */
1032 byAuthor(username: string, viewer: Viewer, filter?: AuthoredFilter): Promise<Result<Authored>>;
1033 /**
1034 * What a person did each day of the last year (issues and pull requests
1035 * opened, reviews given), only on repositories the viewer may read: the
1036 * calendar on their profile. Not found for no such account.
1037 */
1038 contributions(username: string, viewer: Viewer): Promise<Result<Contributions>>;
1039
1040
1041
1042 appendSession(actor: User, repo: RepoPath, number: number, entries: NewSessionEntry[]): Promise<Result<{ count: number }>>;
1043 readSession(repo: RepoPath, number: number, viewer: Viewer, afterSeq?: number): Promise<Result<SessionEntry[]>>;
1044}
1045
1046/**
1047 * What to pass `ReposApi.compare` to see what a pull request changes.
1048 *
1049 * A working copy is compared as a whole. A branch, of the repository or of
1050 * a fork of it, is compared by name while the pull request is open, and by
1051 * the commit it was merged or closed at afterwards, so later pushes to the
1052 * branch do not change the record. A fork's branch is compared from the
1053 * repository it merges into (`targetId`).
1054 */
1055export function pullComparison(pull: Pull): {
1056 repoId: string;
1057 base: string | null;
1058 head: string | null;
1059 /** The branch it merges into, which it is compared from. */
1060 baseBranch: string | null;
1061 /** For a fork's branch: the repository it merges into. */
1062 targetId: string | null;
1063} {
1064 const baseBranch = pull.base ?? null;
1065 if (pull.forkRepoId) return { repoId: pull.forkRepoId, base: pull.mergeBase, head: null, baseBranch, targetId: null };
1066 const settled = pull.status === "merged" || pull.status === "closed";
1067 return {
1068 repoId: pull.headRepoId ?? pull.repoId,
1069 base: pull.mergeBase,
1070 // A fork's branch by the commit it was last seen at, which the repository
1071 // it merges into holds too, so those who read that repository can read it.
1072 head: ((settled || pull.headRepoId) && pull.headCommit) || pull.branch,
1073 baseBranch,
1074 targetId: pull.headRepoId ? pull.repoId : null,
1075 };
1076}
1077
1078/** The id of the repository holding a pull request's change: its working copy, its fork, or the repository. */
1079export function pullSourceId(pull: Pull): string {
1080 return pull.forkRepoId ?? pull.headRepoId ?? pull.repoId;
1081}
1082
1083
1084export type QueueState = "waiting" | "testing" | "passed" | "failed" | "landed" | "removed";
1085
1086/** One pull request's place in a merge queue. */
1087export type QueueEntry = {
1088 id: string;
1089 number: number;
1090 title: string;
1091 agent: string;
1092 state: QueueState;
1093 /** The pull requests merged ahead of it in the state being tested, in order. */
1094 ahead: number[];
1095 baseCommit: string | null;
1096 combinedCommit: string | null;
1097 error: string | null;
1098 results: CheckResult[];
1099 /** Username of whoever merged it into the queue: a person, or `g1t`. */
1100 enqueuedBy: string;
1101 /** RFC 3339. */
1102 createdAt: string;
1103 /** RFC 3339. */
1104 finishedAt: string | null;
1105};
1106
1107/** A repository's merge queue: what is in it, in order, and what recently left. */
1108export type QueueView = {
1109 enabled: boolean;
1110 active: QueueEntry[];
1111 /** Newest first. */
1112 recent: QueueEntry[];
1113};
1114
1115export type QueueStackItem = {
1116 number: number;
1117 title: string;
1118 /** The repository holding the change, and its branch. */
1119 source: RepoPath;
1120 branch: string;
1121 commit: string;
1122};
1123
1124/** What a sandbox needs to build and check one combined state. */
1125export type QueueJob = {
1126 entryId: string;
1127 token: string;
1128 repo: RepoPath;
1129 defaultBranch: string;
1130 baseCommit: string;
1131 branch: string;
1132 stack: QueueStackItem[];
1133 /** Always empty: the state is checked by the merge_group workflows run on it. */
1134 checks: string[];
1135 /** Always empty, as `checks`. */
1136 contractChecks: string[];
1137 actor: User;
1138};
1139
1140// --- A person's work ---------------------------------------------------------
1141// Mirrors the `Authored*` types in `crates/contracts/src/work.rs`.
1142
1143export type AuthoredKind = "issue" | "pull";
1144/** `closed` takes in merged pull requests too; `merged` is only those. */
1145export type AuthoredState = "open" | "closed" | "merged";
1146/** `created` is newest first, `updated` most recently changed, `oldest` oldest first. */
1147export type AuthoredSort = "created" | "updated" | "oldest";
1148
1149/** The most items one `byAuthor` page holds. */
1150export const AUTHORED_PAGE = 25;
1151
1152export type AuthoredFilter = {
1153 kind?: AuthoredKind;
1154 state?: AuthoredState;
1155 /** `namespace/name`. */
1156 repo?: string;
1157 sort?: AuthoredSort;
1158 /** The `next` of the page before. */
1159 before?: string;
1160 limit?: number;
1161};
1162
1163export type AuthoredItem = {
1164 kind: AuthoredKind;
1165 repo: RepoPath;
1166 number: number;
1167 title: string;
1168 /** A merged pull request is closed. */
1169 state: State;
1170 /** A pull request's own status; null on an issue. */
1171 status: PullStatus | null;
1172 /** Why an issue was closed. */
1173 reason: IssueReason | null;
1174 draft: boolean;
1175 merged: boolean;
1176 /** RFC 3339. */
1177 createdAt: string;
1178 /** RFC 3339. */
1179 updatedAt: string;
1180 /** RFC 3339. */
1181 mergedAt: string | null;
1182};
1183
1184/** Over every repository the viewer may read, whatever the filters. */
1185export type AuthoredCounts = {
1186 pullsMerged: number;
1187 pullsOpen: number;
1188 pulls: number;
1189 issues: number;
1190 issuesOpen: number;
1191};
1192
1193export type Authored = {
1194 items: AuthoredItem[];
1195 /** Pass as `before` for the next page; null on the last. */
1196 next: string | null;
1197 counts: AuthoredCounts;
1198 /** The repositories they worked in that the viewer may read, most work first. */
1199 repos: { repo: RepoPath; count: number }[];
1200};
1201
1202// Mirrors `Contributions` in `crates/contracts/src/work.rs`.
1203
1204/** How many days `contributions` covers: today and the 364 before it. */
1205export const CONTRIBUTION_DAYS = 365;
1206
1207/** One day with something on it; days with nothing are left out. */
1208export type ContributionDay = {
1209 /** `YYYY-MM-DD`, UTC. */
1210 date: string;
1211 /** Everything that day, commits included. */
1212 count: number;
1213 /** How many of `count` are commits they pushed to a default branch. */
1214 commits?: number;
1215};
1216
1217/** A person's year, as far as the viewer may see. */
1218export type Contributions = {
1219 /** Oldest first. */
1220 days: ContributionDay[];
1221 total: number;
1222 /** The first day counted, `YYYY-MM-DD`; the last is today (UTC). */
1223 from: string;
1224};
1225
1226// --- Coordinating work: sessions, claims and dependencies -----------------
1227// Mirrors `crates/contracts/src/work/coordination.rs`.
1228
1229/** The harness a session runs in. */
1230export type Harness = "claude_code" | "claude_managed_agents" | "codex" | "cursor" | "copilot" | "other";
1231
1232/** Active: heard from in 15 minutes; idle: not since; ended: ended, or quiet for 2 hours. */
1233export type SessionState = "active" | "idle" | "ended";
1234
1235/** One run of someone's own harness on a repository. */
1236export type WorkSession = {
1237 /** `ses_…`. */
1238 id: string;
1239 repoId: string;
1240 issue: number | null;
1241 pull: number | null;
1242 branch: string | null;
1243 actor: { id: string; username: string };
1244 harness: Harness;
1245 harnessSessionId: string | null;
1246 title: string | null;
1247 state: SessionState;
1248 headCommit: string | null;
1249 startedAt: string;
1250 lastSeenAt: string;
1251 endedAt: string | null;
1252 /** What the harness said, or `timed_out`. */
1253 endReason: string | null;
1254 /** For a subagent: the session that started it. */
1255 parentId?: string | null;
1256 /** For a subagent: its kind (Explore, security-reviewer). */
1257 agentType?: string | null;
1258 /** For a subagent: the task it was given, in a few words. */
1259 task?: string | null;
1260 /** For a subagent: the prompt its parent gave it. */
1261 prompt?: string | null;
1262 /** What it reported when it finished: a subagent's final message. */
1263 result?: string | null;
1264 model?: string | null;
1265 /** How many subagents it started. */
1266 subagents?: number;
1267 /** In a list, for one with no title: the start of the first prompt it recorded. */
1268 firstPrompt?: string | null;
1269};
1270
1271/** What kind of thing a session touched. */
1272export type TouchKind = "file" | "commit" | "branch" | "pull" | "issue";
1273
1274/** Something a session touched, kept once per session. */
1275export type SessionTouch = { sessionId: string; kind: TouchKind; value: string; at: string };
1276
1277/** How a session was tied to an issue or pull request. */
1278export type LinkVia = "attached" | "claim" | "branch" | "commit" | "trailer" | "opened" | "ref";
1279
1280/** An issue or pull request a session, or one of its subagents, worked on. */
1281export type SessionLink = {
1282 kind: "issue" | "pull";
1283 number: number;
1284 title: string;
1285 /** The issue's state or the pull request's status. */
1286 state: string;
1287 via: LinkVia[];
1288 sessionIds: string[];
1289};
1290
1291/** A skill a session used, by name. */
1292export type SessionSkill = { sessionId: string; name: string; uses: number };
1293
1294export type ClaimState = "active" | "released" | "expired" | "handed_off";
1295
1296/** An advisory, expiring "I'm working on #N". Never a lock. */
1297export type Claim = {
1298 /** `clm_…`. */
1299 id: string;
1300 repoId: string;
1301 issue: number;
1302 sessionId: string | null;
1303 actor: { id: string; username: string };
1304 harness: Harness | null;
1305 note: string | null;
1306 state: ClaimState;
1307 createdAt: string;
1308 expiresAt: string;
1309 endedAt: string | null;
1310 endReason: string | null;
1311 /** For a hand-off: who it was handed to; null for anyone. */
1312 handoffTo: string | null;
1313};
1314
1315/** `session.started` and `session.ended`. */
1316export type SessionEventData = { repoId: string; number?: number; issue?: number; session: WorkSession };
1317
1318/** `work.claimed`, `work.released`, `work.claim_expired` and `work.handoff_requested`. */
1319export type ClaimEventData = {
1320 repoId: string;
1321 number: number;
1322 issue: number;
1323 claim: Claim;
1324 others?: Claim[];
1325 tookOver?: string;
1326 reason?: string;
1327 from?: string;
1328 to?: string;
1329 note?: string;
1330};
1331
1332/** `dependency.changed`. */
1333export type DependencyChangedData = {
1334 repoId: string;
1335 number: number;
1336 issue: number;
1337 blockedBy: number[];
1338 added: number[];
1339 removed: number[];
1340 cleared: number[];
1341 remaining: number[];
1342 mergedPull?: number;
1343};
1344
1345/** `overlap.detected` between two pull requests, sent once for each side of a new overlap. */
1346export type PullOverlapData = {
1347 repoId: string;
1348 number: number;
1349 pull: number;
1350 otherPull: number;
1351 files: string[];
1352 issue?: number;
1353 otherIssue?: number;
1354};
1355
1356/** `overlap.detected` between two sessions that touched the same files (siblings included), once for each side. */
1357export type SessionOverlapData = {
1358 repoId: string;
1359 number?: number;
1360 sessionId: string;
1361 otherSessionId: string;
1362 otherActor: string;
1363 files: string[];
1364 issue?: number;
1365 otherIssue?: number;
1366};
1367
1368/** `overlap.detected`: between pull requests, or between sessions (with `sessionId`). */
1369export type OverlapDetectedData = PullOverlapData | SessionOverlapData;
1370
1371/** `session.progressed`: a session recorded more (at most every few seconds). */
1372export type SessionProgressedData = { repoId: string; number?: number; sessionId: string; rootId?: string };
1373
1374/** An issue in brief. */
1375export type IssueBrief = { number: number; title: string; state: State };
1376
1377/** A pull request in brief. */
1378export type PullBrief = { number: number; title: string; status: PullStatus };
1379
1380/** An issue another is blocked by, and where it stands. */
1381export type Blocker = {
1382 number: number;
1383 title: string;
1384 state: State;
1385 /** Active claims on it. */
1386 claims: Claim[];
1387 pulls: PullBrief[];
1388};
1389
1390/** A pull request's place in the merge queue; `position` 1 is the front. */
1391export type QueuePlace = { state: QueueState; position: number };
1392
1393/** One of an issue's pull requests, with where it stands. */
1394export type WorkPull = {
1395 number: number;
1396 title: string;
1397 status: PullStatus;
1398 branch: string | null;
1399 headCommit: string | null;
1400 author: { id: string; username: string };
1401 /** `failed` when the merge queue took it out, until its head moves. */
1402 checkStatus: CheckStatus | null;
1403 requiredChecks: RequiredCheck[];
1404 mergeable: Mergeable;
1405 /** Other pull requests in progress changing the same files. */
1406 overlaps: Overlap[];
1407 /** Its place in the merge queue, while it is in it. */
1408 queue: QueuePlace | null;
1409};
1410
1411// --- Decision records (crates/contracts/src/decisions.rs) ------------------
1412
1413export type DecisionKind =
1414 | "proposal"
1415 | "claim"
1416 | "integration_failure"
1417 | "integration_passed"
1418 | "fix"
1419 | "approval"
1420 | "merge"
1421 | "note";
1422
1423/** Claimed: someone said so. Tested: a check or the merge queue proved it. Approved: a person approved it. */
1424export type DecisionConfidence = "claimed" | "tested" | "approved";
1425
1426/** A structured reason kept on an issue or pull request, with how sure it is. */
1427export type Decision = {
1428 /** `dec_…`. */
1429 id: string;
1430 issue: number | null;
1431 pull: number | null;
1432 sessionId: string | null;
1433 /** Username of who recorded it; null when g1t did. */
1434 actor: string | null;
1435 kind: DecisionKind;
1436 confidence: DecisionConfidence;
1437 summary: string;
1438 /**
1439 * What it rests on, kept as recorded, in snake_case: `commit`, `check`
1440 * (`name`, `conclusion`, `url`), `combination`, `other_pulls`,
1441 * `suspects`, `bisected`, `merge_queue`.
1442 */
1443 evidence: Record<string, unknown>;
1444 /** RFC 3339. */
1445 createdAt: string;
1446};
1447
1448/** Everything about an issue an agent needs to pick it up: `get_work`. */
1449export type WorkContext = {
1450 issue: Issue;
1451 /** The items under its "Definition of done" heading. */
1452 definitionOfDone: string[];
1453 /** The checks every pull request into the default branch must pass. */
1454 requiredChecks: string[];
1455 /** Active claims on it. */
1456 claims: Claim[];
1457 /** Sessions on it or its pull requests, most recently heard from first. */
1458 sessions: WorkSession[];
1459 pulls: WorkPull[];
1460 blockedBy: Blocker[];
1461 /** The issues it blocks. */
1462 blocks: IssueBrief[];
1463 /** On it and its pull requests, newest first. */
1464 decisions: Decision[];
1465 /** The latest `integration_failure` decision among them. */
1466 lastIntegrationFailure: Decision | null;
1467 /** Its latest coordination events, newest first. */
1468 recent: G1tEvent[];
1469};
1470
1471/** A harness session and what it recorded. */
1472export type WorkSessionDetail = {
1473 /** Pending repository coordination events; reading does not acknowledge them. */
1474 updates?: { id: string; kind: string; data: unknown; at: string }[];
1475 session: WorkSession;
1476 entries: SessionEntry[];
1477 /** Its subagents and theirs, in the order they started. */
1478 children?: WorkSession[];
1479 /** What it and its subagents touched. */
1480 touched?: SessionTouch[];
1481 /** The issues and pull requests it and its subagents worked on. */
1482 links?: SessionLink[];
1483 skills?: SessionSkill[];
1484 /** For a subagent: the session at the top of its tree. */
1485 root?: WorkSession | null;
1486};
1487
1488/** Reading coordination: work service methods (services/work/src/coordination, decisions.rs). */
1489export interface CoordinationApi {
1490 getWork(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<WorkContext>>;
1491 /** Newest first; active ones unless `state` says otherwise. */
1492 listClaims(repo: RepoPath, viewer: Viewer, filter?: { state?: ClaimState; issue?: number }): Promise<Result<Claim[]>>;
1493 /** Most recently heard from first. */
1494 listWorkSessions(
1495 repo: RepoPath,
1496 viewer: Viewer,
1497 filter?: { state?: SessionState; issue?: number; pull?: number; path?: string; subagents?: boolean },
1498 ): Promise<Result<WorkSession[]>>;
1499 getWorkSession(repo: RepoPath, id: string, viewer: Viewer, afterSeq?: number): Promise<Result<WorkSessionDetail>>;
1500 /** An issue's (with its pull requests') or a pull request's, oldest first. */
1501 listDecisions(repo: RepoPath, number: number, viewer: Viewer): Promise<Result<Decision[]>>;
1502}
1503
1504/**
1505 * Delivery counts cover the requested UTC days; waiting counts are current.
1506 * `checking` and `failed` count each open pull request once, by its head's
1507 * checks (statuses, check runs and g1t Actions jobs); one with none is in neither.
1508 */
1509export type DeliveryMetrics = { repoId: string; opened: number; merged: number; active: number; unreviewed: number; checking: number; failed: number; queued: number; leadSeconds: number; reviewSeconds: number; reviewed: number };
1510/** `checksUnavailable`: g1t Actions could not be read, so `checking` and `failed` are not known. */
1511export type DeliveryInsights = { projects: DeliveryMetrics[]; days: { day: string; merged: number }[]; checksUnavailable: boolean };