g1t/packages/contracts/src/events.ts

231 lines10,720 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Initial g1t: services, event bus, intents and attempts1/**
2 * Every state change in g1t is published as an event. Services react to
3 * each other through events rather than direct calls, and the same stream
Sidebar: the panels really slide4 * feeds timelines, webhooks and workflows.
Initial g1t: services, event bus, intents and attempts5 *
6 * The envelope follows CloudEvents: `type` says what happened, `subject`
7 * says to what, `data` is the type-specific payload.
8 */
Agents as a team: lifecycle, merge queue, billing and a new shell9
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look10import type { RepoRole } from "./access";
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step11import type { Confidence, Verdict } from "./work";
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look12
13/** The payload of the `repo.collaborator_*` events. */
14export type RepoCollaboratorData = {
15 repoId: string;
16 namespace: string;
17 name: string;
18 username: string;
19 role: RepoRole | null;
20 previousRole: RepoRole | null;
21};
Initial g1t: services, event bus, intents and attempts22export type EventPayloads = {
23 "repo.created": { repoId: string; namespace: string; name: string; isPrivate: boolean };
Issues and pull requests replace intents and attempts24 "repo.forked": { repoId: string; sourceRepoId: string; pullId: string };
Events service in Rust, with RFC 3339 times and accurate push events25 /**
Search across all of g1t, Explore, and a command palette26 * A repository's description, topics or visibility changed.
27 * `visibilityChanged` says whether it went public or private, which
28 * `repo.visibility_changed` also announces on its own.
29 */
30 "repo.updated": { repoId: string; namespace: string; name: string; isPrivate: boolean; visibilityChanged: boolean };
31 "repo.visibility_changed": { repoId: string; isPrivate: boolean };
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look32 /**
33 * A repository's name changed within its workspace `namespace`, from
34 * `from` to `to`, keeping its id. A path change like `repo.transferred`:
35 * services move rows kept under its path to its *current* path (see
36 * `repoMove`, `currentMovedPath`).
37 */
38 "repo.renamed": { repoId: string; namespace: string; from: string; to: string };
39 /**
40 * A repository was deleted. It is hidden and git refuses it, but it can
41 * be restored until `purgeAfter`: services stop what runs for it and hide
42 * it, and keep their rows until `repo.purged`.
43 */
44 "repo.deleted": { repoId: string; namespace: string; name: string; isPrivate: boolean; purgeAfter: string };
45 /** A deleted repository is back, as it was. Services start again what they stopped. */
46 "repo.restored": { repoId: string; namespace: string; name: string; isPrivate: boolean };
47 /**
48 * A deleted repository is gone for good, its git data with it. Services
49 * drop every row they keep for it, except a workspace's history (ledgers,
50 * invoices, the audit log).
51 */
52 "repo.purged": { repoId: string; namespace: string; name: string };
53 /**
54 * A repository was archived (read-only: pushes, merges, agents and
55 * workflows refused; issues and pull requests locked; deployments keep
56 * serving), or unarchived.
57 */
58 "repo.archived": { repoId: string; namespace: string; name: string; archived: true };
59 "repo.unarchived": { repoId: string; namespace: string; name: string; archived: false };
60 /** The default branch is now `to`; `renamed` when `from` was renamed to it. */
61 "repo.default_branch_changed": { repoId: string; from: string; to: string; renamed: boolean };
62 /** A branch was renamed. Pull requests from it follow. */
63 "branch.renamed": { repoId: string; from: string; to: string; defaultBranch: boolean };
Search across all of g1t, Explore, and a command palette64 /** An account was made, or changed what its profile shows. Ask identity for the profile. */
65 "user.updated": { username: string };
66 /** A workspace was made, or its name, description or icon changed. */
67 "workspace.updated": { workspaceId: string; slug: string };
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look68 /** Someone, or g1t staff, made an invite. Never the code or the address. */
69 "invite.created": { inviteId: string; inviterId: string | null; workspaceId: string | null; bound: boolean };
70 /** An invite was used: by a new account, or by an account joining a workspace. */
71 "invite.redeemed": {
72 inviteId: string;
73 userId: string;
74 inviterId: string | null;
75 workspaceId: string | null;
76 createdAccount: boolean;
77 };
78 /** Someone asked for access while registration is invite-only. The address is not in the event. */
79 "waitlist.requested": { entryId: string };
Search across all of g1t, Explore, and a command palette80 /**
Events service in Rust, with RFC 3339 times and accurate push events81 * One branch moved by a push. `ref` is the full ref, `after` the commit it
82 * points to now, and `defaultBranch` whether it is the default branch.
83 */
84 "git.push": { repoId: string; ref: string; after: string; defaultBranch: boolean };
Issues and pull requests replace intents and attempts85 "issue.opened": { issueId: string; repoId: string; number: number; title: string };
86 "issue.updated": { issueId: string; repoId: string; number: number };
Agents as a team: lifecycle, merge queue, billing and a new shell87 /** The people an issue is assigned to changed; `assignees` is the new set. */
88 "issue.assigned": { issueId: string; repoId: string; number: number; assignees: string[] };
Issues and pull requests replace intents and attempts89 /** `resolvedBy` is the number of the pull request whose merge closed it. */
90 "issue.closed": {
91 issueId: string;
92 repoId: string;
93 number: number;
94 reason: "completed" | "not_planned";
95 resolvedBy?: number;
96 };
97 "issue.reopened": { issueId: string; repoId: string; number: number };
98 /** `issue` is the number of the issue the pull request is for. */
99 "pull.opened": { pullId: string; repoId: string; number: number; issue?: number; agent: string };
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step100 /** `confidence`, on a g1t agent's change once g1t has worked it out, is on every pull request event. */
101 "pull.ready": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
Acceptance checks in sandboxes, line comments and review verdicts102 /** A push moved the head of a pull request that is ready for review. */
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step103 "pull.updated": { pullId: string; repoId: string; number: number; issue?: number; commit: string; confidence?: Confidence };
Agents as a team: lifecycle, merge queue, billing and a new shell104 /** A merge was asked for while the pull request was behind; it has to catch up first. */
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step105 "pull.merge_requested": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
106 "pull.closed": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
Agents and memory, checks and conflicts, profiles, slug renames, custom domains107 /**
108 * The pull request's head or its target moved and the files both changed
109 * overlap: a sandbox should find out whether it still merges cleanly.
110 * `commit` is its head.
111 */
112 "pull.mergecheck": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
113 /** Whether the pull request merges cleanly was settled. */
114 "pull.mergeability": { pullId: string; repoId: string; number: number; issue?: number };
Agents asked while not at work are woken to answer115 /** Another agent asked the agent on a pull request, which was not at work, a question or handed it work. */
116 "agent.asked": { pullId: string; repoId: string; number: number; issue?: number };
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step117 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string; confidence?: Confidence };
Acceptance checks in sandboxes, line comments and review verdicts118 /** A run of the acceptance checks finished. `commit` is what was checked. */
119 "checks.completed": {
120 pullId: string;
121 repoId: string;
122 number: number;
123 status: "passed" | "failed" | "errored";
124 commit: string;
125 };
Agents as a team: lifecycle, merge queue, billing and a new shell126 /** A g1t agent finished reviewing a pull request; no verdict if it could not. */
127 "review.completed": {
128 pullId: string;
129 repoId: string;
130 number: number;
131 verdict?: "approve" | "request_changes";
132 };
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look133 /** A person was given a role on one repository directly, had it changed, or lost it. `role` is null once removed. */
134 "repo.collaborator_added": RepoCollaboratorData;
135 "repo.collaborator_removed": RepoCollaboratorData;
136 "repo.collaborator_role_changed": RepoCollaboratorData;
Agents as a team: lifecycle, merge queue, billing and a new shell137 /** A repository's merge queue gained, lost or settled an entry. */
138 "queue.changed": { repoId: string };
What happened across an outcome, as a feed beside its graph139 /** `number` is the issue or pull request commented on. */
Agents as a team: lifecycle, merge queue, billing and a new shell140 "comment.created": {
141 commentId: string;
142 repoId: string;
143 number: number;
144 /** Set when the comment is on a pull request. */
145 pullId?: string;
146 /** Set when the comment is a review. */
147 verdict?: Verdict;
148 };
Issues and pull requests replace intents and attempts149 "session.appended": { pullId: string; repoId: string; number: number; count: number };
Agents and memory, checks and conflicts, profiles, slug renames, custom domains150 /**
151 * A workspace's slug changed from `from` to `to`. Services that store a
152 * slug move their rows to the workspace's *current* slug (see
153 * `currentWorkspaceSlug`), so a repeated or late delivery after a second
154 * rename still lands in the right place.
155 */
156 "workspace.renamed": { workspaceId: string; from: string; to: string };
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API157 /**
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look158 * A repository moved from workspace `from` to `to`, keeping its id and
159 * name. Services that store its path or its workspace's slug move those
160 * rows to its *current* path (ask repos `path_by_id`), so a repeated or
161 * late delivery after a second transfer still lands in the right place.
162 */
163 "repo.transferred": { repoId: string; name: string; from: string; to: string };
164 /**
165 * A workspace is gone. Services drop what they keep for it alone; ledgers,
166 * invoices and the audit log stay under its slug, which is never reused.
167 */
168 "workspace.deleted": { workspaceId: string; slug: string };
169 /**
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API170 * A memory was added, changed, reviewed or forgotten. No text: ask the
171 * work service for it by id. `repoId` is the project's, or null for the
172 * workspace's memory. `status` is `deleted` once forgotten.
173 */
174 "memory.changed": { memoryId: string; workspace: string; status: "candidate" | "kept" | "dismissed" | "deleted" };
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look175 /**
176 * A sandbox was stopped because it looked like it was mining: CPU pinned
177 * with little I/O and no progress, or a miner seen by name. For g1t's
178 * staff, in sudo; published with no `repoId` so it never reaches a
179 * repository's timeline or webhooks. `metrics` is what the sandbox
180 * measured (`Verdict` in crates/runner abuse.rs), or null if it could
181 * not say.
182 */
183 "abuse.flagged": {
184 workspace: string;
185 repo: string | null;
186 /** The agent run, when the sandbox had one. */
187 run: string | null;
188 /** What the sandbox was for: agent, checks, queue, actions, deploy... */
189 kind: string;
190 sandbox: string;
191 metrics: Record<string, unknown> | null;
192 };
Initial g1t: services, event bus, intents and attempts193};
194
195export type EventType = keyof EventPayloads;
196
197export type G1tEvent<T extends EventType = EventType> = {
198 [K in T]: {
199 id: string;
200 type: K;
201 /** The service that published it. */
202 source: string;
Events service in Rust, with RFC 3339 times and accurate push events203 /** RFC 3339. */
204 time: string;
Initial g1t: services, event bus, intents and attempts205 /** The repo the event concerns, used to scope timelines and deliveries. */
206 repoId: string | null;
207 /** The user or agent that caused it, if any. */
208 actor: string | null;
209 data: EventPayloads[K];
210 };
211}[T];
212
213/** What a publisher supplies; the bus fills in `id` and `time`. */
214export type NewEvent<T extends EventType = EventType> = {
215 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
216}[T];
217
218export type EventQuery = {
219 repoId?: string;
220 types?: EventType[];
221 /** Return events older than this event id. */
222 before?: string;
223 limit?: number;
224};
225
226/** The event bus and its durable log. */
227export interface EventsApi {
228 publish(events: NewEvent[]): Promise<void>;
229 /** Newest first. */
230 list(query: EventQuery): Promise<G1tEvent[]>;
231}