Skip to content
refs
462 lines · 15.9 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 reviewWaitlist: 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 readonly person: PersonRef;
178 readonly handle: string;
179}
180
181/** Whether an agent mentioned on a task has picked up the mention. `comment` is null for the task description. */
182export interface MentionState {
183 readonly comment: Id | null;
184 readonly agent: string;
185 /** `working`, `approval`, `answered` and `failed` are a sub-agent's run on the agent's machine. */
186 readonly state: "delivered" | "waiting" | "offline" | "working" | "approval" | "answered" | "failed";
187 /** Why a sub-agent couldn't finish; null otherwise. */
188 readonly reason: string | null;
189}
190
191/** A tool approval an agent is waiting for. Only the agent's own human can answer it (`canDecide`). */
192export interface PermissionRequest {
193 readonly session: Id;
194 readonly agent: string;
195 readonly requestId: string;
196 readonly tool: string;
197 readonly description: string;
198 readonly preview: string;
199 readonly at: Timestamp;
200 readonly canDecide: boolean;
201}
202
203/** An agent client the human has authorized over OAuth. */
204export interface AgentGrant {
205 readonly id: Id;
206 readonly client: string;
207 readonly createdAt: Timestamp;
208}
209
210/** An agent session that has called the origin recently, working on a branch or idle. */
211export interface OnlineAgent {
212 readonly session: Id;
213 readonly runtime: string;
214 readonly onBehalfOf: PersonRef;
215 /** The branch the session may push, or null while it has none. */
216 readonly branch: string | null;
217 readonly since: Timestamp;
218 readonly lastSeen: Timestamp;
219 /** The machine whose refs daemon the session runs under, when it came through the refs CLI. */
220 readonly machine: string | null;
221}
222
223export interface PersonRef {
224 readonly id: Id;
225 readonly name: string;
226}
227
228export interface TaskSummary {
229 /** The task's number within its repository, as in `/<repo>/tasks/<number>`. */
230 readonly number: number;
231 readonly repo: string;
232 readonly title: string;
233 readonly status: TaskStatus;
234 readonly author: PersonRef;
235 readonly assignee: PersonRef | null;
236 readonly labels: readonly Label[];
237 readonly comments: number;
238 readonly createdAt: Timestamp;
239 readonly closedAt: Timestamp | null;
240}
241
242export interface TaskDetail extends TaskSummary {
243 readonly body: string;
244 /** Sanitized HTML of `body`, or null when it is empty. */
245 readonly bodyHtml: string | null;
246 readonly updatedAt: Timestamp;
247}
248
249export interface PullSummary {
250 /** The pull request's number within its repository, as in `/<repo>/pulls/<number>`. Pull requests are numbered apart from tasks. */
251 readonly number: number;
252 readonly repo: string;
253 readonly title: string;
254 readonly status: PullStatus;
255 readonly author: PersonRef;
256 /** The runtime of the agent that opened it for `author`, or null when `author` opened it. */
257 readonly agent: string | null;
258 /** Branch names: `head` is merged into `base`. */
259 readonly base: string;
260 readonly head: string;
261 readonly comments: number;
262 readonly createdAt: Timestamp;
263 readonly closedAt: Timestamp | null;
264}
265
266export interface PullDetail extends PullSummary {
267 readonly body: string;
268 readonly bodyHtml: string | null;
269 readonly updatedAt: Timestamp;
270 /** The pull request this one was branched from, and the commit it started at. */
271 readonly branchedFrom: { readonly number: number; readonly title: string; readonly commit: string } | null;
272}
273
274/** A pull request branched from another, and the commit of that one it started at. */
275export interface PullBranch {
276 readonly commit: string;
277 readonly pull: PullSummary;
278}
279
280export type LineSide = "deletions" | "additions";
281
282/** Lines in a diff: `deletions` lines are numbered in the old file, `additions` lines in the new one. */
283export interface LineRange {
284 readonly start: number;
285 readonly side: LineSide;
286 readonly end: number;
287 readonly endSide: LineSide;
288}
289
290/**
291 * A conversation on lines of a pull request's diff, or on one of its decision records. Agents can only mark one
292 * `addressed`, naming the commit they say fixes it, and a decision's thread is addressed by the push that
293 * supersedes the decision; a human with write access resolves it.
294 */
295export interface ReviewThread {
296 readonly id: number;
297 /** The file and lines the thread is on; null on a decision's thread. */
298 readonly path: string | null;
299 readonly range: LineRange | null;
300 /** The decision record the thread is on; null on a thread about lines. */
301 readonly decision: string | null;
302 /** The head commit the thread was started on. */
303 readonly revision: string;
304 /** The lines, or the decision sentence, as they read when the thread started. */
305 readonly code: string;
306 readonly status: "open" | "addressed" | "resolved";
307 readonly addressed: { readonly commit: string; readonly by: Attribution; readonly at: Timestamp } | null;
308 readonly resolved: { readonly by: Attribution; readonly at: Timestamp } | null;
309 /** Ids of the thread's comments in the pull request's timeline, oldest first. */
310 readonly comments: readonly Id[];
311 /** Pushes since the thread started changed its lines, or took its file out of the diff. */
312 readonly outdated: boolean;
313}
314
315/** Whether refs can merge an open pull request: it merges file by file, and a file both sides changed is a conflict. */
316export type Mergeability =
317 | { readonly state: "clean" }
318 | { readonly state: "conflicts"; readonly paths: readonly string[] }
319 | { readonly state: "unavailable"; readonly reason: string };
320
321export interface PullCounts {
322 readonly open: number;
323 /** Closed and merged together, as GitHub counts them. */
324 readonly closed: number;
325}
326
327export interface TaskCounts {
328 readonly open: number;
329 readonly closed: number;
330}
331
332export interface WaitlistEntry extends Person {
333 readonly handle: string;
334 readonly joinedAt: Timestamp;
335}
336
337export interface Member extends Person {
338 readonly role: Role;
339 readonly joinedAt: Timestamp;
340}
341
342export interface Invitation {
343 readonly id: Id;
344 readonly email: string;
345 readonly role: Role;
346 readonly invitedBy: PersonRef;
347 readonly expiresAt: Timestamp;
348 readonly expired: boolean;
349}
350
351export interface AccessToken {
352 readonly id: Id;
353 readonly name: string;
354 readonly createdAt: Timestamp;
355 readonly lastUsedAt: Timestamp | null;
356}
357
358export interface Choice {
359 readonly id: Id;
360 readonly name: string;
361}
362
363export type CodeSymbolKind = "function" | "class" | "method" | "field" | "interface" | "type" | "enum" | "const";
364
365/** A declaration in the code map. Its id is `path#name`, or `path#Class.member` for a class member. */
366export interface CodeSymbol {
367 readonly id: string;
368 readonly file: string;
369 readonly name: string;
370 readonly kind: CodeSymbolKind;
371 readonly parent: string | null;
372 readonly start: number;
373 readonly end: number;
374 readonly exported: boolean;
375 readonly doc: string | null;
376}
377
378export type CodeEdgeKind = "calls" | "creates" | "types" | "reads";
379
380/** One symbol using another, with the number of times it does. */
381export interface CodeEdge {
382 readonly from: string;
383 readonly to: string;
384 readonly kind: CodeEdgeKind;
385 readonly count: number;
386}
387
388export interface CodeFile {
389 readonly path: string;
390 readonly lines: number;
391}
392
393/** The declarations of a commit's TypeScript and JavaScript files and how they use each other. */
394export interface CodeGraph {
395 readonly commit: string;
396 readonly files: readonly CodeFile[];
397 readonly symbols: readonly CodeSymbol[];
398 readonly edges: readonly CodeEdge[];
399 /** Source files left out because they were too large or past the file limit. */
400 readonly skipped: number;
401}
402
403/** The code map of a commit: ready, still being built, or not available with the reason. */
404export type CodeMapState =
405 | { readonly kind: "ready"; readonly graph: CodeGraph }
406 | { readonly kind: "indexing"; readonly commit: string }
407 | { readonly kind: "unavailable"; readonly commit: string; readonly reason: "empty" | "too_large" | "failed" };
408
409/** What a page needs to know about a commit's map before it loads the map itself. */
410export type CodeMapSummary =
411 | { readonly kind: "ready"; readonly commit: string; readonly files: number; readonly symbols: number }
412 | Exclude<CodeMapState, { kind: "ready" }>;
413
414/** The lines a pull request changed in one file, by line number in the head version. */
415export interface CodeChange {
416 readonly path: string;
417 readonly status: ChangeFile["status"];
418 readonly additions: number;
419 readonly deletions: number;
420 /** Line numbers in the head version that the pull request added. */
421 readonly added: readonly number[];
422 /** Removed lines, each placed after a head line (0 places it before the first line). */
423 readonly removed: readonly { readonly after: number; readonly text: string }[];
424}
425
426/** A pull request's code map: the head commit's map and the changes that the map highlights. */
427export interface PullCodeMap {
428 readonly map: CodeMapSummary;
429 readonly head: string;
430 readonly changes: readonly CodeChange[];
431}
432
433export type ModelProvider = "anthropic" | "openai" | "openrouter";
434
435/** An agent that refs runs: built in, set up for a whole namespace, or set up for one repository. */
436export interface HostedAgent {
437 readonly handle: string;
438 readonly scope: "builtin" | "namespace" | "repo";
439 readonly description: string;
440 readonly instructions: string;
441 /** The provider model and the last four characters of its key, or null for the default model on Workers AI. */
442 readonly model: { readonly provider: ModelProvider; readonly model: string; readonly keyHint: string } | null;
443 readonly updatedAt: Timestamp | null;
444 /** A repository agent with the same handle replaces a namespace or built-in agent in that repository. */
445 readonly replaced: boolean;
446}
447
448/** One run of a hosted agent, for the Agents tab. */
449export interface AgentRunView {
450 readonly session: Id;
451 readonly handle: string;
452 /** The person the run acts for: who mentioned the agent, or who started the CI run. */
453 readonly person: string;
454 readonly pull: number | null;
455 readonly via: "mention" | "ci";
456 readonly startedAt: Timestamp;
457 readonly endedAt: Timestamp | null;
458 readonly state: "working" | "answered" | "failed";
459 readonly summary: string | null;
460 /** Each model turn, for a run that still works or that the reader opened; null when not loaded. */
461 readonly steps: readonly { readonly step: number; readonly at: Timestamp; readonly thinking: string; readonly tools: readonly string[] }[] | null;
462}