flagon-io/g1t

public

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/packages/contracts/src/events.ts

130 lines5,536 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
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 };
Agents and memory, checks and conflicts, profiles, slug renames, custom domains40 /**
41 * The pull request's head or its target moved and the files both changed
42 * overlap: a sandbox should find out whether it still merges cleanly.
43 * `commit` is its head.
44 */
45 "pull.mergecheck": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
46 /** Whether the pull request merges cleanly was settled. */
47 "pull.mergeability": { pullId: string; repoId: string; number: number; issue?: number };
Agents asked while not at work are woken to answer48 /** Another agent asked the agent on a pull request, which was not at work, a question or handed it work. */
49 "agent.asked": { pullId: string; repoId: string; number: number; issue?: number };
Issues and pull requests replace intents and attempts50 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
Acceptance checks in sandboxes, line comments and review verdicts51 /** A run of the acceptance checks finished. `commit` is what was checked. */
52 "checks.completed": {
53 pullId: string;
54 repoId: string;
55 number: number;
56 status: "passed" | "failed" | "errored";
57 commit: string;
58 };
Agents as a team: lifecycle, merge queue, billing and a new shell59 /** A g1t agent finished reviewing a pull request; no verdict if it could not. */
60 "review.completed": {
61 pullId: string;
62 repoId: string;
63 number: number;
64 verdict?: "approve" | "request_changes";
65 };
66 /** A repository's merge queue gained, lost or settled an entry. */
67 "queue.changed": { repoId: string };
What happened across an outcome, as a feed beside its graph68 /** `number` is the issue or pull request commented on. */
Agents as a team: lifecycle, merge queue, billing and a new shell69 "comment.created": {
70 commentId: string;
71 repoId: string;
72 number: number;
73 /** Set when the comment is on a pull request. */
74 pullId?: string;
75 /** Set when the comment is a review. */
76 verdict?: Verdict;
77 };
Issues and pull requests replace intents and attempts78 "session.appended": { pullId: string; repoId: string; number: number; count: number };
Agents and memory, checks and conflicts, profiles, slug renames, custom domains79 /**
80 * A workspace's slug changed from `from` to `to`. Services that store a
81 * slug move their rows to the workspace's *current* slug (see
82 * `currentWorkspaceSlug`), so a repeated or late delivery after a second
83 * rename still lands in the right place.
84 */
85 "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 API86 /**
87 * A memory was added, changed, reviewed or forgotten. No text: ask the
88 * work service for it by id. `repoId` is the project's, or null for the
89 * workspace's memory. `status` is `deleted` once forgotten.
90 */
91 "memory.changed": { memoryId: string; workspace: string; status: "candidate" | "kept" | "dismissed" | "deleted" };
Initial g1t: services, event bus, intents and attempts92};
93
94export type EventType = keyof EventPayloads;
95
96export type G1tEvent<T extends EventType = EventType> = {
97 [K in T]: {
98 id: string;
99 type: K;
100 /** The service that published it. */
101 source: string;
Events service in Rust, with RFC 3339 times and accurate push events102 /** RFC 3339. */
103 time: string;
Initial g1t: services, event bus, intents and attempts104 /** The repo the event concerns, used to scope timelines and deliveries. */
105 repoId: string | null;
106 /** The user or agent that caused it, if any. */
107 actor: string | null;
108 data: EventPayloads[K];
109 };
110}[T];
111
112/** What a publisher supplies; the bus fills in `id` and `time`. */
113export type NewEvent<T extends EventType = EventType> = {
114 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
115}[T];
116
117export type EventQuery = {
118 repoId?: string;
119 types?: EventType[];
120 /** Return events older than this event id. */
121 before?: string;
122 limit?: number;
123};
124
125/** The event bus and its durable log. */
126export interface EventsApi {
127 publish(events: NewEvent[]): Promise<void>;
128 /** Newest first. */
129 list(query: EventQuery): Promise<G1tEvent[]>;
130}