pr_01m47d15m3e54sn21z27rpy5n9/packages/contracts/src/events.ts

107 lines4,209 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
4 * feeds timelines, webhooks and automations.
5 *
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
10import type { Verdict } from "./work";
Initial g1t: services, event bus, intents and attempts11export type EventPayloads = {
12 "repo.created": { repoId: string; namespace: string; name: string; isPrivate: boolean };
Issues and pull requests replace intents and attempts13 "repo.forked": { repoId: string; sourceRepoId: string; pullId: string };
Events service in Rust, with RFC 3339 times and accurate push events14 /**
15 * One branch moved by a push. `ref` is the full ref, `after` the commit it
16 * points to now, and `defaultBranch` whether it is the default branch.
17 */
18 "git.push": { repoId: string; ref: string; after: string; defaultBranch: boolean };
Issues and pull requests replace intents and attempts19 "issue.opened": { issueId: string; repoId: string; number: number; title: string };
20 "issue.updated": { issueId: string; repoId: string; number: number };
Agents as a team: lifecycle, merge queue, billing and a new shell21 /** The people an issue is assigned to changed; `assignees` is the new set. */
22 "issue.assigned": { issueId: string; repoId: string; number: number; assignees: string[] };
Issues and pull requests replace intents and attempts23 /** `resolvedBy` is the number of the pull request whose merge closed it. */
24 "issue.closed": {
25 issueId: string;
26 repoId: string;
27 number: number;
28 reason: "completed" | "not_planned";
29 resolvedBy?: number;
30 };
31 "issue.reopened": { issueId: string; repoId: string; number: number };
32 /** `issue` is the number of the issue the pull request is for. */
33 "pull.opened": { pullId: string; repoId: string; number: number; issue?: number; agent: string };
34 "pull.ready": { pullId: string; repoId: string; number: number; issue?: number };
Acceptance checks in sandboxes, line comments and review verdicts35 /** A push moved the head of a pull request that is ready for review. */
36 "pull.updated": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
Agents as a team: lifecycle, merge queue, billing and a new shell37 /** A merge was asked for while the pull request was behind; it has to catch up first. */
38 "pull.merge_requested": { pullId: string; repoId: string; number: number; issue?: number };
Issues and pull requests replace intents and attempts39 "pull.closed": { pullId: string; repoId: string; number: number; issue?: number };
40 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
Acceptance checks in sandboxes, line comments and review verdicts41 /** A run of the acceptance checks finished. `commit` is what was checked. */
42 "checks.completed": {
43 pullId: string;
44 repoId: string;
45 number: number;
46 status: "passed" | "failed" | "errored";
47 commit: string;
48 };
Agents as a team: lifecycle, merge queue, billing and a new shell49 /** A g1t agent finished reviewing a pull request; no verdict if it could not. */
50 "review.completed": {
51 pullId: string;
52 repoId: string;
53 number: number;
54 verdict?: "approve" | "request_changes";
55 };
56 /** A repository's merge queue gained, lost or settled an entry. */
57 "queue.changed": { repoId: string };
What happened across an outcome, as a feed beside its graph58 /** `number` is the issue or pull request commented on. */
Agents as a team: lifecycle, merge queue, billing and a new shell59 "comment.created": {
60 commentId: string;
61 repoId: string;
62 number: number;
63 /** Set when the comment is on a pull request. */
64 pullId?: string;
65 /** Set when the comment is a review. */
66 verdict?: Verdict;
67 };
Issues and pull requests replace intents and attempts68 "session.appended": { pullId: string; repoId: string; number: number; count: number };
Initial g1t: services, event bus, intents and attempts69};
70
71export type EventType = keyof EventPayloads;
72
73export type G1tEvent<T extends EventType = EventType> = {
74 [K in T]: {
75 id: string;
76 type: K;
77 /** The service that published it. */
78 source: string;
Events service in Rust, with RFC 3339 times and accurate push events79 /** RFC 3339. */
80 time: string;
Initial g1t: services, event bus, intents and attempts81 /** The repo the event concerns, used to scope timelines and deliveries. */
82 repoId: string | null;
83 /** The user or agent that caused it, if any. */
84 actor: string | null;
85 data: EventPayloads[K];
86 };
87}[T];
88
89/** What a publisher supplies; the bus fills in `id` and `time`. */
90export type NewEvent<T extends EventType = EventType> = {
91 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
92}[T];
93
94export type EventQuery = {
95 repoId?: string;
96 types?: EventType[];
97 /** Return events older than this event id. */
98 before?: string;
99 limit?: number;
100};
101
102/** The event bus and its durable log. */
103export interface EventsApi {
104 publish(events: NewEvent[]): Promise<void>;
105 /** Newest first. */
106 list(query: EventQuery): Promise<G1tEvent[]>;
107}