Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
711 linesCodeBlameRaw
1/**
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
4 * feeds timelines, webhooks and workflows.
5 *
6 * The envelope follows CloudEvents: `type` says what happened, `subject`
7 * says to what, `data` is the type-specific payload.
8 */
9
10import type { Release } from "./about";
11import type { RepoRole } from "./access";
12import type { CheckRunEventData, CheckSuiteEventData, StatusEventData } from "./checks";
13import type { DeploymentStatus, RepoDeployment } from "./deployments";
14import type { TeamRole, TeamVisibility } from "./teams";
15import type { AgentRef, Confidence, Verdict } from "./work";
16
17/** What every `package.*` event names. */
18export type PackageEventData = {
19 packageId: string;
20 workspace: string;
21 ecosystem: string;
22 name: string;
23 repoId: string | null;
24};
25
26/** What `deployment.succeeded` and `deployment.failed` carry. */
27export type DeploymentEventData = {
28 deploymentId: string;
29 projectId: string;
30 repoId: string;
31 workspace: string;
32 project: string;
33 kind: "production" | "preview";
34 branch: string | null;
35 number: number | null;
36 commit: string;
37 path: string;
38 error: string | null;
39 recovered: boolean;
40 /** A username, or `g1t`. */
41 triggeredBy: string;
42};
43
44/** What every `release.*` event carries. */
45export type ReleaseEventData = {
46 releaseId: string;
47 repoId: string;
48 tagName: string;
49 release: Release;
50 /** On `release.edited`: what the title and notes were before. */
51 changes?: { name?: { from: string | null }; body?: { from: string } };
52 /** Set when a workflow job's token made the change: the run's id. */
53 causedByJob?: string;
54};
55
56/** The payload of the `repo.collaborator_*` events. */
57export type RepoCollaboratorData = {
58 repoId: string;
59 namespace: string;
60 name: string;
61 username: string;
62 role: RepoRole | null;
63 previousRole: RepoRole | null;
64};
65/** A team asked to review a pull request. */
66export type TeamRequested = { team: string; notified: string[]; assigned: string[] };
67
68/** The payload of the `team.*` events; each sets the fields that apply. */
69/** How someone came to be a member of a workspace (`workspace.member_joined`). */
70export type JoinedHow = "invitation" | "created" | "joined";
71
72/** The payload of `workspace.member_joined`. Mirrors `MemberJoined` in events.rs. */
73export type MemberJoinedData = {
74 workspaceId: string;
75 /** The workspace's slug. */
76 workspace: string;
77 userId: string;
78 username: string;
79 role: "owner" | "member";
80 how: JoinedHow;
81};
82
83export type TeamChangedData = {
84 workspace: string;
85 teamId: string;
86 team: string;
87 name: string;
88 visibility: TeamVisibility | null;
89 parent?: string;
90 changes?: string[];
91 username?: string;
92 role?: TeamRole;
93 previousRole?: TeamRole;
94 repoId?: string;
95 repo?: string;
96 repoRole?: RepoRole;
97 previousRepoRole?: RepoRole;
98};
99
100export type EventPayloads = {
101 "repo.created": { repoId: string; namespace: string; name: string; isPrivate: boolean };
102 "repo.forked": { repoId: string; sourceRepoId: string; pullId: string };
103 /**
104 * A repository's description, topics or visibility changed.
105 * `visibilityChanged` says whether it went public or private, which
106 * `repo.visibility_changed` also announces on its own.
107 */
108 "repo.updated": { repoId: string; namespace: string; name: string; isPrivate: boolean; visibilityChanged: boolean };
109 "repo.visibility_changed": { repoId: string; isPrivate: boolean };
110 /**
111 * A repository's name changed within its workspace `namespace`, from
112 * `from` to `to`, keeping its id. A path change like `repo.transferred`:
113 * services move rows kept under its path to its *current* path (see
114 * `repoMove`, `currentMovedPath`).
115 */
116 "repo.renamed": { repoId: string; namespace: string; from: string; to: string };
117 /**
118 * A repository was deleted. It is hidden and git refuses it, but it can
119 * be restored until `purgeAfter`: services stop what runs for it and hide
120 * it, and keep their rows until `repo.purged`.
121 */
122 "repo.deleted": {
123 repoId: string;
124 namespace: string;
125 name: string;
126 isPrivate: boolean;
127 purgeAfter: string;
128 /** It went with its workspace (`workspace.deleting`); deployments leaves it to that. */
129 withWorkspace?: boolean;
130 };
131 /** A deleted repository is back, as it was. Services start again what they stopped. */
132 "repo.restored": {
133 repoId: string;
134 namespace: string;
135 name: string;
136 isPrivate: boolean;
137 /** It came back with its workspace (`workspace.restored`). */
138 withWorkspace?: boolean;
139 };
140 /**
141 * A deleted repository is gone for good, its git data with it. Services
142 * drop every row they keep for it, except a workspace's history (ledgers,
143 * invoices, the audit log).
144 */
145 "repo.purged": { repoId: string; namespace: string; name: string };
146 /**
147 * A repository was archived (read-only: pushes, merges, agents and
148 * workflows refused; issues and pull requests locked; deployments keep
149 * serving), or unarchived.
150 */
151 "repo.archived": { repoId: string; namespace: string; name: string; archived: true };
152 "repo.unarchived": { repoId: string; namespace: string; name: string; archived: false };
153 /** The default branch is now `to`; `renamed` when `from` was renamed to it. */
154 "repo.default_branch_changed": { repoId: string; from: string; to: string; renamed: boolean };
155 /** A branch was renamed. Pull requests from it follow. */
156 "branch.renamed": { repoId: string; from: string; to: string; defaultBranch: boolean };
157 /** An account was made, or changed what its profile shows. Ask identity for the profile. */
158 "user.updated": { username: string };
159 /**
160 * An account was deleted, by the person or by g1t's staff; staff can
161 * restore it until `purgeAfter`. Its sessions, tokens and keys have ended
162 * and it has left every workspace. Services stop what they do for it and
163 * keep their rows; `user.restored` undoes that, and `user.deleted` follows
164 * once `purgeAfter` passes.
165 */
166 "user.deleting": { userId: string; username: string; byStaff: boolean; purgeAfter: string };
167 /** Staff brought a deleted account back. Services undo what they did on `user.deleting`. */
168 "user.restored": { userId: string; username: string };
169 /**
170 * An account is gone for good. Services drop what they keep for it alone
171 * and show what it wrote as `ghost` (`GHOST_USERNAME`, `GHOST_ID`).
172 * Ledgers, invoices and audit logs keep its username, which is never given
173 * to anyone again.
174 */
175 "user.deleted": { userId: string; username: string };
176 /** A workspace was made, or its name, description or icon changed. */
177 "workspace.updated": { workspaceId: string; slug: string };
178 /**
179 * A person became a member of a workspace. `how` says by which door;
180 * the workspace's creator is `created`, so a listener that greets new
181 * members leaves them out (the agents service's @g1t welcomes everyone
182 * else, once). Never for an agent or a token.
183 */
184 "workspace.member_joined": MemberJoinedData;
185 /** Someone, or g1t staff, made an invite. Never the code or the address. */
186 "invite.created": { inviteId: string; inviterId: string | null; workspaceId: string | null; bound: boolean };
187 /** An invite was used: by a new account, or by an account joining a workspace. */
188 "invite.redeemed": {
189 inviteId: string;
190 userId: string;
191 inviterId: string | null;
192 workspaceId: string | null;
193 createdAccount: boolean;
194 };
195 /**
196 * One branch moved by a push. `ref` is the full ref, `after` the commit it
197 * points to now, and `defaultBranch` whether it is the default branch.
198 */
199 /**
200 * `before` is where the ref pointed before; absent for a new branch or
201 * tag. `causedByJob` is set when a workflow job's token pushed: the run's id.
202 */
203 "git.push": {
204 repoId: string;
205 ref: string;
206 before?: string;
207 after: string;
208 defaultBranch: boolean;
209 causedByJob?: string;
210 /**
211 * How many commits the push brought to the branch, along its
212 * first-parent line from `after` back to `before` (a merge commit is
213 * one), at most 50; one for a new branch. Absent when it was not
214 * counted: a tag, a branch deleted, a pull request landed, a push the
215 * store could not read back, or one from before this was recorded.
216 */
217 commits?: number;
218 };
219 /**
220 * A branch or tag was deleted by a push. `before` is the commit it pointed
221 * to. `causedByJob` is set when a workflow job's token deleted it: the run's id.
222 */
223 "git.deleted": { repoId: string; ref: string; before: string; causedByJob?: string };
224 /**
225 * `author` is who opened it: g1t, for one its agent filed while at work,
226 * with `requestedBy` the person it was working for. Every issue and pull
227 * request event carries both.
228 */
229 "issue.opened": {
230 issueId: string;
231 repoId: string;
232 number: number;
233 title: string;
234 author?: { id: string; username: string };
235 requestedBy?: { id: string; username: string };
236 };
237 "issue.updated": { issueId: string; repoId: string; number: number };
238 /** The people an issue is assigned to changed; `assignees` is the new set, `added` those newly assigned. */
239 "issue.assigned": { issueId: string; repoId: string; number: number; assignees: string[]; added?: string[] };
240 /** `resolvedBy` is the number of the pull request whose merge closed it. */
241 "issue.closed": {
242 issueId: string;
243 repoId: string;
244 number: number;
245 reason: "completed" | "not_planned";
246 resolvedBy?: number;
247 };
248 "issue.reopened": { issueId: string; repoId: string; number: number };
249 /**
250 * `issue` is the number of the issue the pull request is for. `author` is
251 * who opened it: g1t, for a change g1t made, with `requestedBy` the person
252 * who asked for it.
253 */
254 "pull.opened": {
255 pullId: string;
256 repoId: string;
257 number: number;
258 issue?: number;
259 agent: string;
260 author?: { id: string; username: string };
261 requestedBy?: { id: string; username: string };
262 };
263 /** `confidence`, on a g1t agent's change once g1t has worked it out, is on every pull request event. */
264 "pull.ready": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
265 /** A push moved the head of a pull request that is ready for review. */
266 "pull.updated": { pullId: string; repoId: string; number: number; issue?: number; commit: string; confidence?: Confidence };
267 /** A merge was asked for while the pull request was behind; it has to catch up first. */
268 "pull.merge_requested": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
269 "pull.closed": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
270 /** A closed pull request was opened again. `commit` is its head. */
271 "pull.reopened": { pullId: string; repoId: string; number: number; issue?: number; commit?: string; confidence?: Confidence };
272 /** A pull request that was ready for review was turned back into a draft. */
273 "pull.converted_to_draft": { pullId: string; repoId: string; number: number; issue?: number; confidence?: Confidence };
274 /** People were assigned to a pull request: `assignees` is the new set, `added` those newly assigned. */
275 "pull.assigned": { pullId: string; repoId: string; number: number; issue?: number; assignees: string[]; added: string[] };
276 /** Reviewers were asked for a pull request (`reviewers`), or no longer are. */
277 "pull.review_requested": {
278 pullId: string;
279 repoId: string;
280 number: number;
281 issue?: number;
282 reviewers?: string[];
283 /** Teams asked: `team` is `workspace/slug`, `notified` who is told, `assigned` who review assignment picked. */
284 teams?: TeamRequested[];
285 /** Asked because they own files it changes (its CODEOWNERS file). */
286 codeOwners?: boolean;
287 };
288 "pull.review_request_removed": {
289 pullId: string;
290 repoId: string;
291 number: number;
292 issue?: number;
293 reviewers?: string[];
294 teams?: TeamRequested[];
295 };
296 /** g1t stopped seeing a pull request through until a person steps in; `detail` says why. */
297 "pull.stalled": { pullId: string; repoId: string; number: number; issue?: number; detail: string };
298 /** A pull request g1t had stopped on is going again. */
299 "pull.resumed": { pullId: string; repoId: string; number: number; issue?: number };
300 /**
301 * The pull request's head or its target moved and the files both changed
302 * overlap: a sandbox should find out whether it still merges cleanly.
303 * `commit` is its head.
304 */
305 "pull.mergecheck": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
306 /** Whether the pull request merges cleanly was settled. */
307 "pull.mergeability": { pullId: string; repoId: string; number: number; issue?: number };
308 /** Another agent asked the agent on a pull request, which was not at work, a question or handed it work. */
309 "agent.asked": { pullId: string; repoId: string; number: number; issue?: number };
310 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string; confidence?: Confidence };
311 /** A run of the acceptance checks finished. `commit` is what was checked. */
312 "checks.completed": {
313 pullId: string;
314 repoId: string;
315 number: number;
316 status: "passed" | "failed" | "errored";
317 commit: string;
318 };
319 /** A status was set on a commit through the API. */
320 "status.created": StatusEventData;
321 /** A check run was reported on a commit through the API, completed, asked to run again, or had one of its buttons pressed (`requestedAction`). */
322 "check_run.created": CheckRunEventData;
323 "check_run.completed": CheckRunEventData;
324 "check_run.rerequested": CheckRunEventData;
325 "check_run.requested_action": CheckRunEventData;
326 /** A reporter's check runs on a commit all completed, or it was asked to run them again. */
327 "check_suite.completed": CheckSuiteEventData;
328 "check_suite.rerequested": CheckSuiteEventData;
329 /** A g1t agent finished reviewing a pull request; no verdict if it could not. */
330 "review.completed": {
331 pullId: string;
332 repoId: string;
333 number: number;
334 verdict?: "approve" | "request_changes";
335 };
336 /** A person was given a role on one repository directly, had it changed, or lost it. `role` is null once removed. */
337 "repo.collaborator_added": RepoCollaboratorData;
338 "repo.collaborator_removed": RepoCollaboratorData;
339 "repo.collaborator_role_changed": RepoCollaboratorData;
340 /** A team of a workspace was created, changed (`changes` says what) or deleted. */
341 "team.created": TeamChangedData;
342 "team.edited": TeamChangedData;
343 "team.deleted": TeamChangedData;
344 /** Someone joined a team, had their role in it changed, or left it. */
345 "team.member_added": TeamChangedData;
346 "team.member_role_changed": TeamChangedData;
347 "team.member_removed": TeamChangedData;
348 /** A team was given a role on a repository, had it changed, or lost it. */
349 "team.repo_added": TeamChangedData;
350 "team.repo_role_changed": TeamChangedData;
351 "team.repo_removed": TeamChangedData;
352 /** A repository's merge queue gained, lost or settled an entry. */
353 "queue.changed": { repoId: string };
354 /** `number` is the issue or pull request commented on. */
355 "comment.created": {
356 commentId: string;
357 repoId: string;
358 number: number;
359 /** Set when the comment is on a pull request. */
360 pullId?: string;
361 /** Set when the comment is a review. */
362 verdict?: Verdict;
363 /**
364 * Set when one of the workspace's agents wrote it, as itself; the
365 * event's actor is then the person it acted for (`actingFor`).
366 */
367 agent?: AgentRef;
368 actingFor?: { id: string; username: string };
369 /** An agent's review: its verdict is advisory and counts toward nothing. */
370 advisory?: boolean;
371 };
372 /** A comment's text changed; `changes.body.from` is what it said before. */
373 "comment.edited": {
374 commentId: string;
375 repoId: string;
376 number: number;
377 /** Set when the comment is on a pull request. */
378 pullId?: string;
379 changes: { body: { from: string } };
380 };
381 /** A comment was deleted; `comment` is the comment as it was. */
382 "comment.deleted": {
383 commentId: string;
384 repoId: string;
385 number: number;
386 /** Set when the comment was on a pull request. */
387 pullId?: string;
388 comment: {
389 id: string;
390 body: string;
391 author: { id: string; username: string };
392 createdAt: string;
393 path: string | null;
394 line: number | null;
395 };
396 };
397 "session.appended": { pullId: string; repoId: string; number: number; count: number };
398 /**
399 * A build of a project finished, for production or one pull request's
400 * preview (`number`). `path` is the deployment's page on the site;
401 * `recovered`, on a success, says the build before it failed.
402 */
403 "deployment.succeeded": DeploymentEventData;
404 "deployment.failed": DeploymentEventData;
405 /**
406 * A deployment was made, wherever it runs: reported through the API, by
407 * a g1t Actions job with an `environment:`, or a g1t.page build. Its
408 * `payload` is left out: read the deployment for it.
409 */
410 "deployment.created": { repoId: string; deployment: Omit<RepoDeployment, "payload">; causedByJob?: string };
411 /**
412 * A deployment has a new status; `deployment` is as it is now.
413 * `causedByJob` (as on every event a workflow job's token causes) is the
414 * run whose job made it, so no workflow starts for it.
415 */
416 "deployment_status.created": {
417 repoId: string;
418 deployment: Omit<RepoDeployment, "payload">;
419 deploymentStatus: DeploymentStatus;
420 causedByJob?: string;
421 };
422 /**
423 * A release changed, one event per GitHub release activity it amounts
424 * to: made (`created`; a published one is also `published`, and
425 * `released` or `prereleased`), a draft published, edited, made a draft
426 * again (`unpublished`) or deleted. `release` is as it is now (as it was,
427 * for `release.deleted`).
428 */
429 "release.created": ReleaseEventData;
430 "release.published": ReleaseEventData;
431 "release.released": ReleaseEventData;
432 "release.prereleased": ReleaseEventData;
433 "release.edited": ReleaseEventData;
434 "release.unpublished": ReleaseEventData;
435 "release.deleted": ReleaseEventData;
436 /**
437 * A package version was published, such as an image pushed by
438 * `docker push`. `tags` are the tags that now point to it; `repoId` (and
439 * the event's) is the repository the package is linked to, if any.
440 */
441 "package.published": PackageEventData & { version: string; digest: string; size: number; tags: string[] };
442 /** One version of a package was deleted, with the tags that pointed to it. */
443 "package.version_deleted": PackageEventData & { version: string; digest: string };
444 /** A package was deleted with every version it had. */
445 "package.deleted": PackageEventData;
446 /** A package became public or private. */
447 "package.visibility_changed": PackageEventData & { visibility: "public" | "private" };
448 /**
449 * A workspace's slug changed from `from` to `to`. Services that store a
450 * slug move their rows to the workspace's *current* slug (see
451 * `currentWorkspaceSlug`), so a repeated or late delivery after a second
452 * rename still lands in the right place.
453 */
454 "workspace.renamed": { workspaceId: string; from: string; to: string };
455 /**
456 * A repository moved from workspace `from` to `to`, keeping its id and
457 * name. Services that store its path or its workspace's slug move those
458 * rows to its *current* path (ask repos `path_by_id`), so a repeated or
459 * late delivery after a second transfer still lands in the right place.
460 */
461 "repo.transferred": { repoId: string; name: string; from: string; to: string };
462 /**
463 * A workspace is gone. Services drop what they keep for it alone; ledgers,
464 * invoices and the audit log stay under its slug, which is never reused.
465 */
466 "workspace.deleted": { workspaceId: string; slug: string };
467 /**
468 * An owner deleted a workspace; staff can restore it until `purgeAfter`,
469 * and nobody can reach it meanwhile. Services hide what they keep for it
470 * and stop what runs for it, keeping their rows: repos deletes its
471 * repositories softly (`repo.deleted` with `withWorkspace`), deployments
472 * pauses its apps, search drops it. `workspace.restored` undoes exactly
473 * that; `workspace.deleted` follows once `purgeAfter` passes. `by` is the
474 * owner's username.
475 */
476 "workspace.deleting": { workspaceId: string; slug: string; by: string; purgeAfter: string };
477 /**
478 * Staff brought a deleted workspace back with its members and tokens.
479 * Services undo what they did on `workspace.deleting`, and only that.
480 */
481 "workspace.restored": { workspaceId: string; slug: string };
482 /**
483 * A memory was added, changed, reviewed or forgotten. No text: ask the
484 * work service for it by id. `repoId` is the project's, or null for the
485 * workspace's memory. `status` is `deleted` once forgotten.
486 */
487 "memory.changed": { memoryId: string; workspace: string; status: "candidate" | "kept" | "dismissed" | "deleted" };
488 /**
489 * A sandbox was stopped because it looked like it was mining: CPU pinned
490 * with little I/O and no progress, or a miner seen by name. For g1t's
491 * staff, in sudo; published with no `repoId` so it never reaches a
492 * repository's timeline or webhooks. `metrics` is what the sandbox
493 * measured (`Verdict` in crates/runner abuse.rs), or null if it could
494 * not say.
495 */
496 "abuse.flagged": {
497 workspace: string;
498 repo: string | null;
499 /** The agent run, when the sandbox had one. */
500 run: string | null;
501 /** What the sandbox was for: agent, checks, queue, actions, deploy... */
502 kind: string;
503 sandbox: string;
504 metrics: Record<string, unknown> | null;
505 };
506 /**
507 * Docs (services/artifacts): a page was made. Published with no `repoId`, so
508 * a page (which may be in a private space) never reaches a repository's
509 * timeline or webhooks; `actor` is the user's or agent's id. Readers
510 * check access with the artifacts service before showing anything of it.
511 */
512 "doc.page.created": DocPageEventData;
513 /**
514 * A page's content changed: at most once per page every ten minutes of
515 * editing (when its history records a version), and for every agent
516 * edit, accepted suggestion and restore. `authors` are member keys
517 * (`user:<id>`, `agent:<id>`) of everyone whose changes are in it.
518 */
519 "doc.page.updated": DocPageEventData & { versionId: string; kind: "edit" | "agent" | "suggestion" | "restore"; authors: string[] };
520 /** A page went to the trash (with every page under it; one event for the page asked about). */
521 "doc.page.archived": DocPageEventData;
522 /**
523 * A page became possibly out of date: a merged pull request or a push to
524 * a repository's default branch changed code it cites. `repoId` is in
525 * `data`, not on the event, for the same reason as above. `owners` are
526 * member keys; an agent that owns the page can update it
527 * (`stalePagesForAgent` in docs.ts).
528 */
529 "doc.page.stale": DocPageEventData & { repoId: string; repo: string; commit: string; pull: number | null; paths: string[]; owners: string[] };
530 /**
531 * Artifacts (folios, services/artifacts): a folio was made. Like `doc.page.*`,
532 * published with no `repoId`, never offered to webhooks, and readers check
533 * access with the artifacts service before showing anything of it.
534 */
535 "folio.created": FolioEventData;
536 /** A folio's content changed: a version (`versionKind`) with everyone whose changes are in it. */
537 "folio.updated": FolioEventData & { versionId: string; versionKind: "edit" | "agent" | "suggestion" | "proposal" | "restore"; authors: string[] };
538 /** A folio went to the trash (with everything under it; one event for the folio asked about). */
539 "folio.trashed": FolioEventData;
540 "folio.restored": FolioEventData;
541 /**
542 * A folio was deleted for good from the trash (with everything under it;
543 * one event for each top that went): by someone with full access, by
544 * emptying the trash, or by the daily purge (`actor` null then).
545 */
546 "folio.deleted": FolioEventData;
547 /** Someone was given access: who (member keys) and the role. Never content. */
548 "folio.shared": FolioEventData & { principals: string[]; role: "view" | "comment" | "edit" | "manage" };
549 /** Code a folio cites changed. The repository is in `data` as `owner/name` only. */
550 "folio.stale": FolioEventData & { repo: string; commit: string; pull: number | null; paths: string[]; owners: string[] };
551 /**
552 * A space was deleted (services/artifacts): everything in it went to the
553 * trash (`trashed` counts the artifacts; this one event stands for them
554 * all). Like `folio.*`, published with no `repoId` and never offered to
555 * webhooks; `name` is null for a members-only space.
556 */
557 "doc.space.deleted": { workspace: string; workspaceId: string; spaceId: string; name: string | null; kind: "workspace" | "team" | "private"; trashed: number };
558};
559
560/**
561 * What every `folio.*` event carries. `title` is null unless every member
562 * of the workspace can read the folio, so a private folio's name never
563 * travels.
564 */
565export type FolioEventData = {
566 workspace: string;
567 workspaceId: string;
568 folioId: string;
569 kind: "doc" | "slides" | "design" | "dashboard";
570 spaceId: string | null;
571 title: string | null;
572};
573
574/** What every `doc.page.*` event carries. */
575export type DocPageEventData = {
576 workspace: string;
577 workspaceId: string;
578 pageId: string;
579 spaceId: string;
580 title: string;
581 /** The page's address on the site. */
582 path: string;
583};
584
585export type EventType = keyof EventPayloads;
586
587export type G1tEvent<T extends EventType = EventType> = {
588 [K in T]: {
589 id: string;
590 type: K;
591 /** The service that published it. */
592 source: string;
593 /** RFC 3339. */
594 time: string;
595 /** The repo the event concerns, used to scope timelines and deliveries. */
596 repoId: string | null;
597 /** The user or agent that caused it, if any. */
598 actor: string | null;
599 data: EventPayloads[K];
600 };
601}[T];
602
603/** What a publisher supplies; the bus fills in `id` and `time`. */
604export type NewEvent<T extends EventType = EventType> = {
605 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
606}[T];
607
608export type EventQuery = {
609 repoId?: string;
610 types?: EventType[];
611 /** Return events older than this event id. */
612 before?: string;
613 /** Only events by this account id. */
614 actor?: string;
615 /** Only events about these issues or pull requests (`number`, or the `issue` a comment or review is on). */
616 numbers?: number[];
617 /** Only events at or after this RFC 3339 time. */
618 since?: string;
619 limit?: number;
620};
621
622/**
623 * `activity_digest`: what happened in some repositories, and to a
624 * workspace's artifacts, over `[from, until)`, counted by who did it. Home
625 * reads it for what people and agents did since you were last there.
626 * snake_case, as the Rust service reads it
627 * (`g1t_contracts::events::ActivityDigestArgs`).
628 */
629export type ActivityDigestArgs = {
630 /** By id; the caller has checked the viewer may read each. At most `MAX_DIGEST_REPOS` are read. */
631 repo_ids: string[];
632 /** The workspace's slug, for its `folio.*` events (which carry no repository); null leaves artifacts out. */
633 workspace: string | null;
634 /** RFC 3339, inclusive. */
635 from: string;
636 /** RFC 3339, exclusive. */
637 until: string;
638};
639
640/** The most repositories one digest reads. */
641export const MAX_DIGEST_REPOS = 50;
642
643/**
644 * How many times one actor did something. The actor is a member key:
645 * `user:<id>` for a person (or g1t, `user:usr_g1t_agent`), `agent:<id>` for
646 * one of the workspace's agents acting as itself, or `""` when the event
647 * named nobody.
648 */
649export type ActorCount = { actor: string; count: number };
650
651/** Pushes by one actor, with the commits they brought. */
652export type PushesBy = { actor: string; count: number; commits: number };
653
654/** Pushes to a repository's branches (tags are not pushes here). A push whose commits were not counted counts as one commit. */
655export type PushDigest = {
656 count: number;
657 commits: number;
658 /** The branches pushed to, by name, sorted. */
659 branches: string[];
660 /** Most pushes first. */
661 by: PushesBy[];
662 /** Of those, the pushes straight to the default branch: what landed without a pull request. */
663 default_branch: { count: number; commits: number; by: PushesBy[]; last_at: string | null };
664};
665
666export type RepoDigest = {
667 repo_id: string;
668 pushes: PushDigest;
669 /** Pull requests opened, merged and closed without merging, each by who did it. */
670 pulls: { opened: ActorCount[]; merged: ActorCount[]; closed: ActorCount[] };
671 issues: { opened: ActorCount[]; closed: ActorCount[] };
672 /** `review.completed` (g1t's), and a comment with a verdict (a person's). */
673 reviews: ActorCount[];
674 /** Comments without a verdict; one by an agent as itself is the agent's. */
675 comments: ActorCount[];
676 /** Builds that finished, by who set them off; `production` is how many successes were production. */
677 deployments: { succeeded: ActorCount[]; failed: ActorCount[]; production: number };
678 /** Releases published, newest first, at most 50. */
679 releases: { tag: string; name: string | null; actor: string; at: string }[];
680 /** Package versions published, newest first, at most 50. */
681 packages: { ecosystem: string; name: string; version: string; actor: string; at: string }[];
682};
683
684/** A workspace's artifacts over the span. Never a title. */
685export type FolioDigest = {
686 created: ActorCount[];
687 /** Each folio whose content changed, once, with everyone whose changes are in it (member keys); at most 50. */
688 edited: { folio_id: string; kind: "doc" | "slides" | "design" | "dashboard" | string; authors: string[] }[];
689 /** How many folios changed, counting those past the cap. */
690 edited_count: number;
691};
692
693export type ActivityDigest = {
694 from: string;
695 until: string;
696 /** One per repository that had any event counted; none for a quiet one. */
697 repos: RepoDigest[];
698 /** When a workspace was named. */
699 folios: FolioDigest | null;
700 /** False when more events fell in the span than were read, or more repositories were named than are read, so counts are low. */
701 complete: boolean;
702};
703
704/** The event bus and its durable log. */
705export interface EventsApi {
706 publish(events: NewEvent[]): Promise<void>;
707 /** Newest first. */
708 list(query: EventQuery): Promise<G1tEvent[]>;
709 /** A span of some repositories' and a workspace's artifacts' events, counted by who did it. */
710 activityDigest(args: ActivityDigestArgs): Promise<ActivityDigest>;
711}