Skip to content
refs
509 lines · 17.8 KBRaw
1import type { AgentIdentity, Attribution, Person, Role } from "./actor.ts";
2import type { Id, Timestamp } from "./common.ts";
3
4export type Visibility = "public" | "private";
5export type TaskStatus = "open" | "closed";
6export type PullStatus = "open" | "closed" | "merged";
7export type LabelColor = "blue" | "green" | "orange" | "purple" | "red" | "teal" | "neutral";
8
9export interface Org {
10 readonly name: string;
11}
12
13export interface NamespaceRef {
14 readonly slug: string;
15 readonly name: string;
16 readonly kind: "user" | "org";
17}
18
19export interface Viewer {
20 /** The namespace this handle works in: the one in the URL, else the viewer's own. */
21 readonly namespace: NamespaceRef | null;
22 /** The viewer's own account and the organizations they belong to, for switching between them. */
23 readonly namespaces: readonly NamespaceRef[];
24 readonly person: Person | null;
25 readonly agent: AgentIdentity | null;
26 /** Permission hints for rendering. The handles enforce the real rules. */
27 readonly can: { readonly createRepos: boolean; readonly manageMembers: boolean; readonly manageCiSecrets: boolean; readonly manageLabels: boolean; readonly useTasks: boolean; readonly viewAdmin: boolean };
28}
29
30export interface RepoSummary {
31 readonly name: string;
32 readonly description: string;
33 readonly visibility: Visibility;
34 readonly createdAt: Timestamp;
35 readonly openTasks: number;
36 readonly openPulls: number;
37 readonly forks: number;
38 readonly origin: { readonly kind: "fork"; readonly repo: string | null } | { readonly kind: "import"; readonly url: string } | null;
39 readonly cloneUrl: string;
40 readonly can: { readonly write: boolean; readonly admin: boolean };
41}
42
43export interface RefList {
44 readonly defaultRef: string | null;
45 readonly branches: readonly string[];
46 readonly tags: readonly string[];
47}
48
49export interface BranchSummary {
50 readonly name: string;
51 readonly isDefault: boolean;
52 readonly commit: CommitSummary | null;
53 /** The open pull request that uses this branch as its head or its base. */
54 readonly pull: number | null;
55 /** The runtime of an agent that holds this branch now. */
56 readonly agent: string | null;
57}
58
59/** Where a path inside a repository resolved to. `ref` may be a branch, tag or full commit hash. */
60export interface Location {
61 readonly ref: string;
62 readonly path: readonly string[];
63}
64
65export interface CommitSummary {
66 readonly hash: string;
67 readonly title: string;
68 readonly author: string;
69 readonly committedAt: Timestamp;
70 /** The full commit message. Present on commit history and change sets, where commits carry reasoning. */
71 readonly message?: string;
72 /** Paths the commit changed against its first parent. Present on a branch's change set. */
73 readonly files?: readonly string[];
74 /** Who pushed it through refs, when known. Absent for commits imported from elsewhere. */
75 readonly pushedBy?: Attribution;
76}
77
78export interface DiffLine {
79 readonly kind: "context" | "add" | "delete";
80 readonly text: string;
81 readonly oldLine: number | null;
82 readonly newLine: number | null;
83}
84
85export interface ChangeFile {
86 readonly path: string;
87 readonly status: "added" | "deleted" | "modified" | "type_changed";
88 readonly kind: "text" | "binary" | "too_large" | "missing";
89 readonly additions: number;
90 readonly deletions: number;
91 /** Both versions' text for a `text` file, null where the file does not exist on that side or is not shown. */
92 readonly before: string | null;
93 readonly after: string | null;
94 /** The line counts are estimates because the edit script was too long to trace. */
95 readonly truncated: boolean;
96}
97
98export interface ChangeSet {
99 readonly base: string;
100 readonly head: string;
101 readonly commits: readonly CommitSummary[];
102 readonly files: readonly ChangeFile[];
103 readonly additions: number;
104 readonly deletions: number;
105 readonly truncated: boolean;
106}
107
108export interface CommitDetail {
109 readonly hash: string;
110 readonly message: string;
111 readonly author: { readonly name: string; readonly email: string };
112 readonly committer: { readonly name: string; readonly email: string };
113 readonly authoredAt: Timestamp;
114 readonly committedAt: Timestamp;
115 readonly parents: readonly string[];
116 readonly changes: ChangeSet;
117}
118
119export type EntryType = "tree" | "blob" | "symlink" | "gitlink" | "exec";
120
121export interface TreeEntry {
122 readonly name: string;
123 readonly type: EntryType;
124}
125
126export interface Tree {
127 readonly location: Location;
128 readonly commit: CommitSummary;
129 readonly entries: readonly TreeEntry[];
130 /** Sanitized HTML. */
131 readonly readme: { readonly name: string; readonly html: string } | null;
132}
133
134export type FileBody =
135 | { readonly kind: "text"; readonly lines: readonly string[] }
136 | { readonly kind: "markdown"; readonly html: string }
137 | { readonly kind: "image"; readonly rawUrl: string }
138 | { readonly kind: "binary"; readonly rawUrl: string }
139 | { readonly kind: "too_large"; readonly rawUrl: string };
140
141export interface File {
142 readonly location: Location;
143 readonly name: string;
144 readonly size: number;
145 readonly body: FileBody;
146}
147
148export interface RawFile {
149 readonly name: string;
150 readonly contentType: string;
151 readonly body: ReadableStream<Uint8Array>;
152 readonly cacheable: boolean;
153}
154
155export interface LastChanges {
156 readonly asOf: Timestamp;
157 /** Keyed by entry name. Entries changed before the searched history are absent. */
158 readonly changes: Readonly<Record<string, CommitSummary>>;
159}
160
161export interface Label {
162 readonly id: Id;
163 readonly name: string;
164 readonly color: LabelColor;
165 readonly description: string;
166}
167
168export interface LabelWithUsage extends Label {
169 readonly openTasks: number;
170}
171
172/** What a consent page shows when an agent client asks to act for the signed-in human. `client` and `redirectHost` come from the client: escape them. */
173export interface AgentConsentView {
174 readonly client: string;
175 readonly redirectHost: string;
176 readonly loopback: boolean;
177 /** The client asks to use Git as the person, on every repository they can reach. */
178 readonly git: boolean;
179 readonly person: PersonRef;
180 readonly handle: string;
181}
182
183/** Whether an agent mentioned on a task has picked up the mention. `comment` is null for the task description. */
184export interface MentionState {
185 readonly comment: Id | null;
186 readonly agent: string;
187 /** The handle of a hosted agent that refs runs, with its run's session; null for an agent that a person connects. */
188 readonly hosted: { readonly handle: string; readonly session: Id; readonly startedAt: number; readonly lastStep: { readonly step: number; readonly tools: readonly string[]; readonly at: number } | null } | null;
189 /** `working`, `approval`, `answered` and `failed` are a sub-agent's run on the agent's machine. */
190 readonly state: "delivered" | "waiting" | "offline" | "working" | "approval" | "answered" | "failed";
191 /** Why a sub-agent couldn't finish; null otherwise. */
192 readonly reason: string | null;
193}
194
195/** A tool approval an agent is waiting for. Only the agent's own human can answer it (`canDecide`). */
196export interface PermissionRequest {
197 readonly session: Id;
198 readonly agent: string;
199 readonly requestId: string;
200 readonly tool: string;
201 readonly description: string;
202 readonly preview: string;
203 readonly at: Timestamp;
204 readonly canDecide: boolean;
205}
206
207/** An agent client the human has authorized over OAuth. */
208export interface AgentGrant {
209 readonly id: Id;
210 readonly client: string;
211 readonly createdAt: Timestamp;
212}
213
214/** An agent session that has called the origin recently, working on a branch or idle. */
215export interface OnlineAgent {
216 readonly session: Id;
217 readonly runtime: string;
218 readonly onBehalfOf: PersonRef;
219 /** The branch the session may push, or null while it has none. */
220 readonly branch: string | null;
221 readonly since: Timestamp;
222 readonly lastSeen: Timestamp;
223 /** The machine whose refs daemon the session runs under, when it came through the refs CLI. */
224 readonly machine: string | null;
225}
226
227export interface PersonRef {
228 readonly id: Id;
229 readonly name: string;
230}
231
232export interface TaskSummary {
233 /** The task's number within its repository, as in `/<repo>/tasks/<number>`. */
234 readonly number: number;
235 readonly repo: string;
236 readonly title: string;
237 readonly status: TaskStatus;
238 readonly author: PersonRef;
239 readonly assignee: PersonRef | null;
240 readonly labels: readonly Label[];
241 readonly comments: number;
242 readonly createdAt: Timestamp;
243 readonly closedAt: Timestamp | null;
244}
245
246export interface TaskDetail extends TaskSummary {
247 readonly body: string;
248 /** Sanitized HTML of `body`, or null when it is empty. */
249 readonly bodyHtml: string | null;
250 readonly updatedAt: Timestamp;
251}
252
253export interface PullSummary {
254 /** The pull request's number within its repository, as in `/<repo>/pulls/<number>`. Pull requests are numbered apart from tasks. */
255 readonly number: number;
256 readonly repo: string;
257 readonly title: string;
258 readonly status: PullStatus;
259 readonly author: PersonRef;
260 /** The runtime of the agent that opened it for `author`, or null when `author` opened it. */
261 readonly agent: string | null;
262 /** Branch names: `head` is merged into `base`. */
263 readonly base: string;
264 readonly head: string;
265 readonly comments: number;
266 readonly createdAt: Timestamp;
267 readonly closedAt: Timestamp | null;
268}
269
270export interface PullDetail extends PullSummary {
271 readonly body: string;
272 readonly bodyHtml: string | null;
273 readonly updatedAt: Timestamp;
274 /** The pull request this one was branched from, and the commit it started at. */
275 readonly branchedFrom: { readonly number: number; readonly title: string; readonly commit: string } | null;
276}
277
278/** A pull request branched from another, and the commit of that one it started at. */
279export interface PullBranch {
280 readonly commit: string;
281 readonly pull: PullSummary;
282}
283
284export type LineSide = "deletions" | "additions";
285
286/** Lines in a diff: `deletions` lines are numbered in the old file, `additions` lines in the new one. */
287export interface LineRange {
288 readonly start: number;
289 readonly side: LineSide;
290 readonly end: number;
291 readonly endSide: LineSide;
292}
293
294/**
295 * A conversation on lines of a pull request's diff, or on one of its decision records. Agents can only mark one
296 * `addressed`, naming the commit they say fixes it, and a decision's thread is addressed by the push that
297 * supersedes the decision; a human with write access resolves it.
298 */
299export interface ReviewThread {
300 readonly id: number;
301 /** The file and lines the thread is on; null on a decision's thread. */
302 readonly path: string | null;
303 readonly range: LineRange | null;
304 /** The decision record the thread is on; null on a thread about lines. */
305 readonly decision: string | null;
306 /** The head commit the thread was started on. */
307 readonly revision: string;
308 /** The lines, or the decision sentence, as they read when the thread started. */
309 readonly code: string;
310 readonly status: "open" | "addressed" | "resolved";
311 readonly addressed: { readonly commit: string; readonly by: Attribution; readonly at: Timestamp } | null;
312 readonly resolved: { readonly by: Attribution; readonly at: Timestamp } | null;
313 /** Ids of the thread's comments in the pull request's timeline, oldest first. */
314 readonly comments: readonly Id[];
315 /** Pushes since the thread started changed its lines, or took its file out of the diff. */
316 readonly outdated: boolean;
317}
318
319/** Whether refs can merge an open pull request: it merges file by file, and a file both sides changed is a conflict. */
320export type Mergeability =
321 | { readonly state: "clean" }
322 | { readonly state: "conflicts"; readonly paths: readonly string[] }
323 | { readonly state: "unavailable"; readonly reason: string };
324
325export interface PullCounts {
326 readonly open: number;
327 /** Closed and merged together, as GitHub counts them. */
328 readonly closed: number;
329}
330
331export interface TaskCounts {
332 readonly open: number;
333 readonly closed: number;
334}
335
336export interface AdminTotals {
337 readonly people: number;
338 readonly activeToday: number;
339 readonly active7d: number;
340 readonly active30d: number;
341 readonly signups7d: number;
342 readonly signups30d: number;
343 readonly orgs: number;
344 readonly repos: number;
345 readonly pulls: number;
346 readonly mergedPulls: number;
347 readonly agentSessions: number;
348 readonly decisions: number;
349}
350
351/** One UTC day. `active` counts people who did something: an event of theirs or their agents, or a new agent session. */
352export interface AdminDay {
353 readonly day: string;
354 readonly signups: number;
355 readonly active: number;
356 readonly agentSessions: number;
357 readonly events: number;
358}
359
360export interface AdminPerson extends Person {
361 readonly handle: string | null;
362 readonly status: "active" | "waitlisted";
363 readonly joinedAt: Timestamp;
364 /** The last request with their browser session or access token. Null before this was recorded. */
365 readonly lastSeenAt: Timestamp | null;
366 readonly lastAgentAt: Timestamp | null;
367 readonly repos: number;
368 readonly pulls: number;
369 readonly agentSessions: number;
370 readonly events: number;
371}
372
373export interface AdminOverview {
374 readonly totals: AdminTotals;
375 /** The last 30 days, oldest first, with no gaps. */
376 readonly days: readonly AdminDay[];
377 readonly runtimes: readonly { readonly runtime: string; readonly sessions: number }[];
378 /** Event kinds in the last 30 days, most frequent first. */
379 readonly actions: readonly { readonly kind: string; readonly count: number }[];
380 /** Newest sign-up first. */
381 readonly people: readonly AdminPerson[];
382}
383
384export interface Member extends Person {
385 readonly role: Role;
386 readonly joinedAt: Timestamp;
387}
388
389export interface Invitation {
390 readonly id: Id;
391 readonly email: string;
392 readonly role: Role;
393 readonly invitedBy: PersonRef;
394 readonly expiresAt: Timestamp;
395 readonly expired: boolean;
396}
397
398export interface AccessToken {
399 readonly id: Id;
400 readonly name: string;
401 readonly createdAt: Timestamp;
402 readonly lastUsedAt: Timestamp | null;
403}
404
405export interface Choice {
406 readonly id: Id;
407 readonly name: string;
408}
409
410export type CodeSymbolKind = "function" | "class" | "method" | "field" | "interface" | "type" | "enum" | "const";
411
412/** A declaration in the code map. Its id is `path#name`, or `path#Class.member` for a class member. */
413export interface CodeSymbol {
414 readonly id: string;
415 readonly file: string;
416 readonly name: string;
417 readonly kind: CodeSymbolKind;
418 readonly parent: string | null;
419 readonly start: number;
420 readonly end: number;
421 readonly exported: boolean;
422 readonly doc: string | null;
423}
424
425export type CodeEdgeKind = "calls" | "creates" | "types" | "reads";
426
427/** One symbol using another, with the number of times it does. */
428export interface CodeEdge {
429 readonly from: string;
430 readonly to: string;
431 readonly kind: CodeEdgeKind;
432 readonly count: number;
433}
434
435export interface CodeFile {
436 readonly path: string;
437 readonly lines: number;
438}
439
440/** The declarations of a commit's TypeScript and JavaScript files and how they use each other. */
441export interface CodeGraph {
442 readonly commit: string;
443 readonly files: readonly CodeFile[];
444 readonly symbols: readonly CodeSymbol[];
445 readonly edges: readonly CodeEdge[];
446 /** Source files left out because they were too large or past the file limit. */
447 readonly skipped: number;
448}
449
450/** The code map of a commit: ready, still being built, or not available with the reason. */
451export type CodeMapState =
452 | { readonly kind: "ready"; readonly graph: CodeGraph }
453 | { readonly kind: "indexing"; readonly commit: string }
454 | { readonly kind: "unavailable"; readonly commit: string; readonly reason: "empty" | "too_large" | "failed" };
455
456/** What a page needs to know about a commit's map before it loads the map itself. */
457export type CodeMapSummary =
458 | { readonly kind: "ready"; readonly commit: string; readonly files: number; readonly symbols: number }
459 | Exclude<CodeMapState, { kind: "ready" }>;
460
461/** The lines a pull request changed in one file, by line number in the head version. */
462export interface CodeChange {
463 readonly path: string;
464 readonly status: ChangeFile["status"];
465 readonly additions: number;
466 readonly deletions: number;
467 /** Line numbers in the head version that the pull request added. */
468 readonly added: readonly number[];
469 /** Removed lines, each placed after a head line (0 places it before the first line). */
470 readonly removed: readonly { readonly after: number; readonly text: string }[];
471}
472
473/** A pull request's code map: the head commit's map and the changes that the map highlights. */
474export interface PullCodeMap {
475 readonly map: CodeMapSummary;
476 readonly head: string;
477 readonly changes: readonly CodeChange[];
478}
479
480export type ModelProvider = "anthropic" | "openai" | "openrouter";
481
482/** An agent that refs runs: built in, set up for a whole namespace, or set up for one repository. */
483export interface HostedAgent {
484 readonly handle: string;
485 readonly scope: "builtin" | "namespace" | "repo";
486 readonly description: string;
487 readonly instructions: string;
488 /** The provider model and the last four characters of its key, or null for the default model on Workers AI. */
489 readonly model: { readonly provider: ModelProvider; readonly model: string; readonly keyHint: string } | null;
490 readonly updatedAt: Timestamp | null;
491 /** A repository agent with the same handle replaces a namespace or built-in agent in that repository. */
492 readonly replaced: boolean;
493}
494
495/** One run of a hosted agent, for the Agents tab. */
496export interface AgentRunView {
497 readonly session: Id;
498 readonly handle: string;
499 /** The person the run acts for: who mentioned the agent, or who started the CI run. */
500 readonly person: string;
501 readonly pull: number | null;
502 readonly via: "mention" | "ci";
503 readonly startedAt: Timestamp;
504 readonly endedAt: Timestamp | null;
505 readonly state: "working" | "answered" | "failed";
506 readonly summary: string | null;
507 /** Each model turn, for a run that still works or that the reader opened; null when not loaded. */
508 readonly steps: readonly { readonly step: number; readonly at: Timestamp; readonly thinking: string; readonly tools: readonly string[] }[] | null;
509}