import type { AgentIdentity, Attribution, Person, Role } from "./actor.ts"; import type { Id, Timestamp } from "./common.ts"; export type Visibility = "public" | "private"; export type TaskStatus = "open" | "closed"; export type PullStatus = "open" | "closed" | "merged"; export type LabelColor = "blue" | "green" | "orange" | "purple" | "red" | "teal" | "neutral"; export interface Org { readonly name: string; } export interface NamespaceRef { readonly slug: string; readonly name: string; readonly kind: "user" | "org"; } export interface Viewer { /** The namespace this handle works in: the one in the URL, else the viewer's own. */ readonly namespace: NamespaceRef | null; /** The viewer's own account and the organizations they belong to, for switching between them. */ readonly namespaces: readonly NamespaceRef[]; readonly person: Person | null; readonly agent: AgentIdentity | null; /** Permission hints for rendering. The handles enforce the real rules. */ readonly can: { readonly createRepos: boolean; readonly manageMembers: boolean; readonly manageCiSecrets: boolean; readonly manageLabels: boolean; readonly useTasks: boolean; readonly reviewWaitlist: boolean }; } export interface RepoSummary { readonly name: string; readonly description: string; readonly visibility: Visibility; readonly createdAt: Timestamp; readonly openTasks: number; readonly openPulls: number; readonly forks: number; readonly origin: { readonly kind: "fork"; readonly repo: string | null } | { readonly kind: "import"; readonly url: string } | null; readonly cloneUrl: string; readonly can: { readonly write: boolean; readonly admin: boolean }; } export interface RefList { readonly defaultRef: string | null; readonly branches: readonly string[]; readonly tags: readonly string[]; } export interface BranchSummary { readonly name: string; readonly isDefault: boolean; readonly commit: CommitSummary | null; /** The open pull request that uses this branch as its head or its base. */ readonly pull: number | null; /** The runtime of an agent that holds this branch now. */ readonly agent: string | null; } /** Where a path inside a repository resolved to. `ref` may be a branch, tag or full commit hash. */ export interface Location { readonly ref: string; readonly path: readonly string[]; } export interface CommitSummary { readonly hash: string; readonly title: string; readonly author: string; readonly committedAt: Timestamp; /** The full commit message. Present on commit history and change sets, where commits carry reasoning. */ readonly message?: string; /** Paths the commit changed against its first parent. Present on a branch's change set. */ readonly files?: readonly string[]; /** Who pushed it through refs, when known. Absent for commits imported from elsewhere. */ readonly pushedBy?: Attribution; } export interface DiffLine { readonly kind: "context" | "add" | "delete"; readonly text: string; readonly oldLine: number | null; readonly newLine: number | null; } export interface ChangeFile { readonly path: string; readonly status: "added" | "deleted" | "modified" | "type_changed"; readonly kind: "text" | "binary" | "too_large" | "missing"; readonly additions: number; readonly deletions: number; /** Both versions' text for a `text` file, null where the file does not exist on that side or is not shown. */ readonly before: string | null; readonly after: string | null; /** The line counts are estimates because the edit script was too long to trace. */ readonly truncated: boolean; } export interface ChangeSet { readonly base: string; readonly head: string; readonly commits: readonly CommitSummary[]; readonly files: readonly ChangeFile[]; readonly additions: number; readonly deletions: number; readonly truncated: boolean; } export interface CommitDetail { readonly hash: string; readonly message: string; readonly author: { readonly name: string; readonly email: string }; readonly committer: { readonly name: string; readonly email: string }; readonly authoredAt: Timestamp; readonly committedAt: Timestamp; readonly parents: readonly string[]; readonly changes: ChangeSet; } export type EntryType = "tree" | "blob" | "symlink" | "gitlink" | "exec"; export interface TreeEntry { readonly name: string; readonly type: EntryType; } export interface Tree { readonly location: Location; readonly commit: CommitSummary; readonly entries: readonly TreeEntry[]; /** Sanitized HTML. */ readonly readme: { readonly name: string; readonly html: string } | null; } export type FileBody = | { readonly kind: "text"; readonly lines: readonly string[] } | { readonly kind: "markdown"; readonly html: string } | { readonly kind: "image"; readonly rawUrl: string } | { readonly kind: "binary"; readonly rawUrl: string } | { readonly kind: "too_large"; readonly rawUrl: string }; export interface File { readonly location: Location; readonly name: string; readonly size: number; readonly body: FileBody; } export interface RawFile { readonly name: string; readonly contentType: string; readonly body: ReadableStream; readonly cacheable: boolean; } export interface LastChanges { readonly asOf: Timestamp; /** Keyed by entry name. Entries changed before the searched history are absent. */ readonly changes: Readonly>; } export interface Label { readonly id: Id; readonly name: string; readonly color: LabelColor; readonly description: string; } export interface LabelWithUsage extends Label { readonly openTasks: number; } /** 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. */ export interface AgentConsentView { readonly client: string; readonly redirectHost: string; readonly loopback: boolean; readonly person: PersonRef; readonly handle: string; } /** Whether an agent mentioned on a task has picked up the mention. `comment` is null for the task description. */ export interface MentionState { readonly comment: Id | null; readonly agent: string; /** `working`, `approval`, `answered` and `failed` are a sub-agent's run on the agent's machine. */ readonly state: "delivered" | "waiting" | "offline" | "working" | "approval" | "answered" | "failed"; /** Why a sub-agent couldn't finish; null otherwise. */ readonly reason: string | null; } /** A tool approval an agent is waiting for. Only the agent's own human can answer it (`canDecide`). */ export interface PermissionRequest { readonly session: Id; readonly agent: string; readonly requestId: string; readonly tool: string; readonly description: string; readonly preview: string; readonly at: Timestamp; readonly canDecide: boolean; } /** An agent client the human has authorized over OAuth. */ export interface AgentGrant { readonly id: Id; readonly client: string; readonly createdAt: Timestamp; } /** An agent session that has called the origin recently, working on a branch or idle. */ export interface OnlineAgent { readonly session: Id; readonly runtime: string; readonly onBehalfOf: PersonRef; /** The branch the session may push, or null while it has none. */ readonly branch: string | null; readonly since: Timestamp; readonly lastSeen: Timestamp; /** The machine whose refs daemon the session runs under, when it came through the refs CLI. */ readonly machine: string | null; } export interface PersonRef { readonly id: Id; readonly name: string; } export interface TaskSummary { /** The task's number within its repository, as in `//tasks/`. */ readonly number: number; readonly repo: string; readonly title: string; readonly status: TaskStatus; readonly author: PersonRef; readonly assignee: PersonRef | null; readonly labels: readonly Label[]; readonly comments: number; readonly createdAt: Timestamp; readonly closedAt: Timestamp | null; } export interface TaskDetail extends TaskSummary { readonly body: string; /** Sanitized HTML of `body`, or null when it is empty. */ readonly bodyHtml: string | null; readonly updatedAt: Timestamp; } export interface PullSummary { /** The pull request's number within its repository, as in `//pulls/`. Pull requests are numbered apart from tasks. */ readonly number: number; readonly repo: string; readonly title: string; readonly status: PullStatus; readonly author: PersonRef; /** The runtime of the agent that opened it for `author`, or null when `author` opened it. */ readonly agent: string | null; /** Branch names: `head` is merged into `base`. */ readonly base: string; readonly head: string; readonly comments: number; readonly createdAt: Timestamp; readonly closedAt: Timestamp | null; } export interface PullDetail extends PullSummary { readonly body: string; readonly bodyHtml: string | null; readonly updatedAt: Timestamp; /** The pull request this one was branched from, and the commit it started at. */ readonly branchedFrom: { readonly number: number; readonly title: string; readonly commit: string } | null; } /** A pull request branched from another, and the commit of that one it started at. */ export interface PullBranch { readonly commit: string; readonly pull: PullSummary; } export type LineSide = "deletions" | "additions"; /** Lines in a diff: `deletions` lines are numbered in the old file, `additions` lines in the new one. */ export interface LineRange { readonly start: number; readonly side: LineSide; readonly end: number; readonly endSide: LineSide; } /** * A conversation on lines of a pull request's diff, or on one of its decision records. Agents can only mark one * `addressed`, naming the commit they say fixes it, and a decision's thread is addressed by the push that * supersedes the decision; a human with write access resolves it. */ export interface ReviewThread { readonly id: number; /** The file and lines the thread is on; null on a decision's thread. */ readonly path: string | null; readonly range: LineRange | null; /** The decision record the thread is on; null on a thread about lines. */ readonly decision: string | null; /** The head commit the thread was started on. */ readonly revision: string; /** The lines, or the decision sentence, as they read when the thread started. */ readonly code: string; readonly status: "open" | "addressed" | "resolved"; readonly addressed: { readonly commit: string; readonly by: Attribution; readonly at: Timestamp } | null; readonly resolved: { readonly by: Attribution; readonly at: Timestamp } | null; /** Ids of the thread's comments in the pull request's timeline, oldest first. */ readonly comments: readonly Id[]; /** Pushes since the thread started changed its lines, or took its file out of the diff. */ readonly outdated: boolean; } /** Whether refs can merge an open pull request: it merges file by file, and a file both sides changed is a conflict. */ export type Mergeability = | { readonly state: "clean" } | { readonly state: "conflicts"; readonly paths: readonly string[] } | { readonly state: "unavailable"; readonly reason: string }; export interface PullCounts { readonly open: number; /** Closed and merged together, as GitHub counts them. */ readonly closed: number; } export interface TaskCounts { readonly open: number; readonly closed: number; } export interface WaitlistEntry extends Person { readonly handle: string; readonly joinedAt: Timestamp; } export interface Member extends Person { readonly role: Role; readonly joinedAt: Timestamp; } export interface Invitation { readonly id: Id; readonly email: string; readonly role: Role; readonly invitedBy: PersonRef; readonly expiresAt: Timestamp; readonly expired: boolean; } export interface AccessToken { readonly id: Id; readonly name: string; readonly createdAt: Timestamp; readonly lastUsedAt: Timestamp | null; } export interface Choice { readonly id: Id; readonly name: string; } export type CodeSymbolKind = "function" | "class" | "method" | "field" | "interface" | "type" | "enum" | "const"; /** A declaration in the code map. Its id is `path#name`, or `path#Class.member` for a class member. */ export interface CodeSymbol { readonly id: string; readonly file: string; readonly name: string; readonly kind: CodeSymbolKind; readonly parent: string | null; readonly start: number; readonly end: number; readonly exported: boolean; readonly doc: string | null; } export type CodeEdgeKind = "calls" | "creates" | "types" | "reads"; /** One symbol using another, with the number of times it does. */ export interface CodeEdge { readonly from: string; readonly to: string; readonly kind: CodeEdgeKind; readonly count: number; } export interface CodeFile { readonly path: string; readonly lines: number; } /** The declarations of a commit's TypeScript and JavaScript files and how they use each other. */ export interface CodeGraph { readonly commit: string; readonly files: readonly CodeFile[]; readonly symbols: readonly CodeSymbol[]; readonly edges: readonly CodeEdge[]; /** Source files left out because they were too large or past the file limit. */ readonly skipped: number; } /** The code map of a commit: ready, still being built, or not available with the reason. */ export type CodeMapState = | { readonly kind: "ready"; readonly graph: CodeGraph } | { readonly kind: "indexing"; readonly commit: string } | { readonly kind: "unavailable"; readonly commit: string; readonly reason: "empty" | "too_large" | "failed" }; /** What a page needs to know about a commit's map before it loads the map itself. */ export type CodeMapSummary = | { readonly kind: "ready"; readonly commit: string; readonly files: number; readonly symbols: number } | Exclude; /** The lines a pull request changed in one file, by line number in the head version. */ export interface CodeChange { readonly path: string; readonly status: ChangeFile["status"]; readonly additions: number; readonly deletions: number; /** Line numbers in the head version that the pull request added. */ readonly added: readonly number[]; /** Removed lines, each placed after a head line (0 places it before the first line). */ readonly removed: readonly { readonly after: number; readonly text: string }[]; } /** A pull request's code map: the head commit's map and the changes that the map highlights. */ export interface PullCodeMap { readonly map: CodeMapSummary; readonly head: string; readonly changes: readonly CodeChange[]; } export type ModelProvider = "anthropic" | "openai" | "openrouter"; /** An agent that refs runs: built in, set up for a whole namespace, or set up for one repository. */ export interface HostedAgent { readonly handle: string; readonly scope: "builtin" | "namespace" | "repo"; readonly description: string; readonly instructions: string; /** The provider model and the last four characters of its key, or null for the default model on Workers AI. */ readonly model: { readonly provider: ModelProvider; readonly model: string; readonly keyHint: string } | null; readonly updatedAt: Timestamp | null; /** A repository agent with the same handle replaces a namespace or built-in agent in that repository. */ readonly replaced: boolean; } /** One run of a hosted agent, for the Agents tab. */ export interface AgentRunView { readonly session: Id; readonly handle: string; /** The person the run acts for: who mentioned the agent, or who started the CI run. */ readonly person: string; readonly pull: number | null; readonly via: "mention" | "ci"; readonly startedAt: Timestamp; readonly endedAt: Timestamp | null; readonly state: "working" | "answered" | "failed"; readonly summary: string | null; /** Each model turn, for a run that still works or that the reader opened; null when not loaded. */ readonly steps: readonly { readonly step: number; readonly at: Timestamp; readonly thinking: string; readonly tools: readonly string[] }[] | null; }