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