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
357 linesCodeBlameRaw

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.

Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails1//! Which events each subscribing service's queue is sent.
2//!
3//! The events service passes each batch on to one queue per subscriber
4//! (`SUBSCRIBER_*` bindings). Each is sent only the types its consumer acts
5//! on, so an event costs a queue write for the services that read it, not
6//! for all of them. A consumer that starts acting on a new type adds it
7//! here in the same change, or it never hears of it; the tests below and
8//! beside each consumer check what they can.
9//!
10//! A pattern is an exact type (`git.push`), a family (`pull.*`, every type
11//! that starts `pull.`), or `*`, every type. A binding not named here is
12//! sent everything, so a new subscriber is never left out.
13
14/// What the shared helpers in `g1t_kit` act on (`rename`, `transfer`,
15/// `lifecycle`, `deleted`, `user_deleted`): rows that follow a workspace
16/// or repository, or go with it. Rare, so every subscriber is sent them.
17const LIFECYCLE: [&str; 8] = [
18 "workspace.renamed",
19 "workspace.deleted",
20 "repo.renamed",
21 "repo.transferred",
22 "repo.deleted",
23 "repo.restored",
24 "repo.purged",
25 "user.deleted",
26];
27
28/// Each subscriber's binding and the types it is sent beside [`LIFECYCLE`].
29pub const ROUTES: &[(&str, &[&str])] = &[
30 // Memory captured from merges and comments, mentions, pull request
31 // bases, runs stopped in archived repositories (work/src/lib.rs queue).
32 (
33 "SUBSCRIBER_WORK",
34 &[
35 "git.push",
36 "branch.renamed",
37 "repo.created",
38 "repo.archived",
39 "repo.default_branch_changed",
40 "pull.merged",
41 "comment.created",
42 ],
43 ),
44 // Pull requests g1t is seeing through, mentions, queued issues and the
45 // merge queue (runner/src/index.ts queue).
46 (
47 "SUBSCRIBER_RUNNER",
48 &[
49 "pull.opened",
50 "pull.ready",
51 "pull.updated",
52 "pull.mergeability",
53 "pull.mergecheck",
54 "pull.merge_requested",
55 "pull.merged",
56 "pull.closed",
57 "checks.completed",
58 "review.completed",
59 "queue.changed",
60 "comment.created",
61 "issue.opened",
62 "issue.updated",
63 "issue.closed",
64 "agent.asked",
65 "repo.archived",
66 ],
67 ),
Merge branch 'rm-mirroring'68 // Write-back to linked trackers (integrations/src lib.rs).
69 ("SUBSCRIBER_INTEGRATIONS", &["issue.closed", "pull.opened"]),
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails70 // A hook may ask for any type, or for every one.
71 ("SUBSCRIBER_WEBHOOKS", &["*"]),
72 // Every event a workflow can run on (g1t_actions::events::github_events),
73 // and runs stopped in archived repositories.
74 (
75 "SUBSCRIBER_ACTIONS",
76 &[
77 "git.push",
Merge branch 'worktree-agent-a8b78c62188153aa3' into claude/cool-newton-7nm8r978 "git.deleted",
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails79 "pull.*",
80 "issue.*",
81 "comment.*",
82 "release.*",
83 "deployment.created",
84 "deployment_status.created",
85 "review.completed",
86 "workflow.completed",
87 "repo.archived",
88 ],
89 ),
90 // Previews and production deploys (deployments/src/index.ts queue).
91 (
92 "SUBSCRIBER_DEPLOYMENTS",
93 &[
94 "git.push",
95 "branch.renamed",
96 "repo.default_branch_changed",
97 "pull.opened",
98 "pull.ready",
99 "pull.updated",
100 "pull.reopened",
101 "pull.closed",
102 "pull.merged",
103 "workspace.deleting",
104 "workspace.restored",
105 ],
106 ),
107 // Projects follow their repositories, and wake on activity
Merge branch 'worktree-agent-a5b0d9e2733e9e382'108 // (projects/src/index.ts, activity.ts). A production deployment
109 // reported from elsewhere asks for its screenshot.
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails110 (
111 "SUBSCRIBER_PROJECTS",
112 &[
113 "git.push",
114 "repo.*",
115 "issue.opened",
116 "issue.closed",
117 "issue.reopened",
118 "pull.opened",
119 "pull.updated",
120 "pull.merged",
121 "pull.closed",
122 "review.completed",
123 "comment.created",
124 "deployment.succeeded",
125 "deployment.failed",
Merge branch 'worktree-agent-a5b0d9e2733e9e382'126 "deployment_status.created",
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails127 "package.published",
128 "package.deleted",
129 "package.version_deleted",
130 "workspace.deleting",
131 "workspace.restored",
132 ],
133 ),
134 // Pull request working copies, workspaces' repositories, contributors
135 // shown as ghost (repos/src/lib.rs handle_event).
136 (
137 "SUBSCRIBER_REPOS",
138 &[
139 "pull.merged",
140 "pull.closed",
141 "pull.reopened",
142 "workspace.deleting",
143 "workspace.restored",
144 "user.deleting",
145 "user.restored",
146 ],
147 ),
148 // Usage rows that follow a renamed workspace or repository.
149 ("SUBSCRIBER_BILLING", &[]),
150 // Secret and dependency scans, and version update pull requests
151 // (security/src/lib.rs on_event).
152 (
153 "SUBSCRIBER_SECURITY",
154 &[
155 "git.push",
156 "pull.opened",
157 "pull.updated",
158 "pull.ready",
159 "pull.merged",
160 "pull.closed",
161 "comment.created",
162 "repo.created",
163 "repo.visibility_changed",
164 ],
165 ),
166 // What agents are told about a repository (context/src/index.ts).
167 (
168 "SUBSCRIBER_CONTEXT",
169 &[
170 "git.push",
171 "issue.opened",
172 "issue.updated",
173 "issue.closed",
174 "pull.ready",
175 "pull.merged",
176 "memory.changed",
177 ],
178 ),
179 // The site-wide search index (search/src/index.rs).
180 ("SUBSCRIBER_SEARCH", &["git.push", "repo.*", "issue.*", "pull.*", "user.*", "workspace.*"]),
181 // Composer packages read from repositories, and packages that follow
182 // their workspace, team or repository (packages/src/lib.rs on_event).
183 (
184 "SUBSCRIBER_PACKAGES",
185 &[
186 "git.push",
187 "repo.visibility_changed",
188 "workspace.deleting",
189 "workspace.restored",
190 "team.edited",
191 "team.deleted",
192 ],
193 ),
Docs know what code they describe; a project's docs folder in Docs; Docs events; files on any S3 store194 // Pages that cite code a merge or a push to the default branch
195 // changed become possibly out of date, and projects' docs folders shown
196 // in Docs are read again (docs/src/staleness.ts, repo-spaces.ts).
197 ("SUBSCRIBER_DOCS", &["git.push", "pull.merged"]),
Routines run when something happens: a pull request ready for review or merged, checks or a deploy failing, an issue opened198 // Agents' routines that run on events: a pull request ready for
199 // review or merged, checks or a deploy failing, an issue opened
@g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so.200 // (agents/src/triggers.ts); pushes, which skill libraries that
201 // follow a repository read again (agents/src/skill-library.ts); and
202 // a person joining a workspace, whom its @g1t welcomes
203 // (agents/src/welcome.ts).
Routines run when something happens: a pull request ready for review or merged, checks or a deploy failing, an issue opened204 (
205 "SUBSCRIBER_AGENTS",
206 &[
Agents → Skills is the workspace's skill library in the open SKILL.md format: write a skill in g1t, import a SKILL.md or zip, link a repository whose .g1t/skills folders publish on every push, or save a finished session as a skill once a person reviews it; attach a skill to an agent, a team or the whole workspace, each attachment pinned to a version. Agents see each skill's name and when to use it, and read the rest with use_skill when a request needs it; a skill never adds a permission, and scripts wait for an agent's own computer. The agent skills guide says how.207 "git.push",
Routines run when something happens: a pull request ready for review or merged, checks or a deploy failing, an issue opened208 "pull.opened",
209 "pull.ready",
210 "pull.merged",
211 "checks.completed",
212 "issue.opened",
213 "deployment.failed",
@g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so.214 "workspace.member_joined",
Routines run when something happens: a pull request ready for review or merged, checks or a deploy failing, an issue opened215 ],
216 ),
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails217];
218
219/// Whether `pattern` (see the module's notes) matches the type `kind`.
220fn matches(pattern: &str, kind: &str) -> bool {
221 match pattern.strip_suffix('*') {
222 Some(prefix) => kind.starts_with(prefix),
223 None => pattern == kind,
224 }
225}
226
227/// Whether the subscriber behind `binding` is sent events of type `kind`.
228pub fn routed(binding: &str, kind: &str) -> bool {
229 match ROUTES.iter().find(|(name, _)| *name == binding) {
230 Some((_, patterns)) => {
231 LIFECYCLE.contains(&kind) || patterns.iter().any(|pattern| matches(pattern, kind))
232 }
233 None => true,
234 }
235}
236
237#[cfg(test)]
238mod tests {
239 use super::*;
240
241 /// Types published on the bus that hooks are not offered.
Merge branch 'open-signups'242 const UNOFFERED: [&str; 29] = [
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails243 "pull.mergecheck",
244 "pull.mergeability",
245 "deployment.review_requested",
246 "memory.changed",
247 "abuse.flagged",
248 "invite.created",
249 "invite.redeemed",
250 "user.updated",
251 "user.deleting",
252 "user.restored",
253 "user.deleted",
254 "user.email_added",
255 "workspace.updated",
256 "workspace.renamed",
257 "workspace.deleting",
258 "workspace.restored",
259 "workspace.deleted",
Docs know what code they describe; a project's docs folder in Docs; Docs events; files on any S3 store260 // Docs pages: no repository, so no repository's hooks.
261 "doc.page.created",
262 "doc.page.updated",
263 "doc.page.archived",
264 "doc.page.stale",
Merge remote-tracking branch 'origin/claude/cool-newton-7nm8r9' into claude/cool-newton-7nm8r9265 "doc.space.deleted",
The artifacts plan records what Phase 1 decided, self-hosting and the deploy list name the g1t-folios index and the trash cron, and folio events are listed as published but never offered to webhooks.266 // Artifacts (folios): no repository either, and a folio may be private.
267 "folio.created",
268 "folio.updated",
269 "folio.trashed",
270 "folio.restored",
Merge remote-tracking branch 'origin/claude/cool-newton-7nm8r9' into claude/cool-newton-7nm8r9271 "folio.deleted",
The artifacts plan records what Phase 1 decided, self-hosting and the deploy list name the g1t-folios index and the trash cron, and folio events are listed as published but never offered to webhooks.272 "folio.shared",
273 "folio.stale",
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails274 ];
275
276 fn published(kind: &str) -> bool {
277 crate::webhooks::EVENT_TYPES.contains(&kind) || UNOFFERED.contains(&kind)
278 }
279
280 #[test]
281 fn every_exact_route_names_a_type_that_is_published() {
282 for (binding, patterns) in ROUTES {
283 for pattern in patterns.iter().chain(LIFECYCLE.iter()) {
284 if pattern.ends_with('*') {
285 let prefix = pattern.trim_end_matches('*');
286 assert!(
287 prefix.is_empty()
288 || crate::webhooks::EVENT_TYPES.iter().chain(UNOFFERED.iter()).any(|kind| kind.starts_with(prefix)),
289 "{binding}: {pattern} matches nothing"
290 );
291 } else {
292 assert!(published(pattern), "{binding}: {pattern} is not a type anything publishes");
293 }
294 }
295 }
296 }
297
298 #[test]
299 fn every_route_is_a_subscriber_binding_named_once() {
300 let mut names: Vec<&str> = ROUTES.iter().map(|(name, _)| *name).collect();
301 assert!(names.iter().all(|name| name.starts_with("SUBSCRIBER_")));
302 let count = names.len();
303 names.sort_unstable();
304 names.dedup();
305 assert_eq!(names.len(), count);
Docs know what code they describe; a project's docs folder in Docs; Docs events; files on any S3 store306 assert_eq!(count, 15);
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails307 }
308
309 #[test]
310 fn subscribers_hear_what_they_act_on_and_not_the_rest() {
311 assert!(routed("SUBSCRIBER_WEBHOOKS", "secret_scanning_alert.created"));
312 assert!(routed("SUBSCRIBER_WEBHOOKS", "anything.new"));
313 assert!(routed("SUBSCRIBER_ACTIONS", "pull.labeled"));
314 assert!(routed("SUBSCRIBER_ACTIONS", "release.published"));
315 assert!(!routed("SUBSCRIBER_ACTIONS", "check_run.completed"));
316 assert!(routed("SUBSCRIBER_RUNNER", "comment.created"));
317 assert!(!routed("SUBSCRIBER_RUNNER", "status.created"));
Merge branch 'rm-mirroring'318 assert!(routed("SUBSCRIBER_INTEGRATIONS", "issue.closed"));
319 assert!(!routed("SUBSCRIBER_INTEGRATIONS", "git.push"));
Merge branch 'worktree-agent-a049c374e6f1c6be4' into claude/cool-newton-7nm8r9320 assert!(!routed("SUBSCRIBER_INTEGRATIONS", "check_run.completed"));
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails321 assert!(routed("SUBSCRIBER_BILLING", "workspace.renamed"));
322 assert!(!routed("SUBSCRIBER_BILLING", "git.push"));
323 assert!(routed("SUBSCRIBER_SEARCH", "user.updated"));
324 assert!(routed("SUBSCRIBER_REPOS", "user.deleting"));
325 assert!(!routed("SUBSCRIBER_REPOS", "git.push"));
Docs know what code they describe; a project's docs folder in Docs; Docs events; files on any S3 store326 assert!(routed("SUBSCRIBER_DOCS", "pull.merged"));
327 assert!(!routed("SUBSCRIBER_DOCS", "pull.opened"));
Agents → Skills is the workspace's skill library in the open SKILL.md format: write a skill in g1t, import a SKILL.md or zip, link a repository whose .g1t/skills folders publish on every push, or save a finished session as a skill once a person reviews it; attach a skill to an agent, a team or the whole workspace, each attachment pinned to a version. Agents see each skill's name and when to use it, and read the rest with use_skill when a request needs it; a skill never adds a permission, and scripts wait for an agent's own computer. The agent skills guide says how.328 assert!(routed("SUBSCRIBER_AGENTS", "git.push"));
@g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so.329 assert!(routed("SUBSCRIBER_AGENTS", "workspace.member_joined"));
Agents → Skills is the workspace's skill library in the open SKILL.md format: write a skill in g1t, import a SKILL.md or zip, link a repository whose .g1t/skills folders publish on every push, or save a finished session as a skill once a person reviews it; attach a skill to an agent, a team or the whole workspace, each attachment pinned to a version. Agents see each skill's name and when to use it, and read the rest with use_skill when a request needs it; a skill never adds a permission, and scripts wait for an agent's own computer. The agent skills guide says how.330 assert!(!routed("SUBSCRIBER_AGENTS", "comment.created"));
@g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so.331 assert!(!routed("SUBSCRIBER_AGENTS", "workspace.updated"));
Merge branch 'worktree-agent-a5b0d9e2733e9e382'332 assert!(routed("SUBSCRIBER_PROJECTS", "deployment_status.created"));
333 assert!(!routed("SUBSCRIBER_PROJECTS", "deployment.created"));
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails334 // Every subscriber follows what moves or removes a repository.
335 for (binding, _) in ROUTES {
336 for kind in LIFECYCLE {
337 assert!(routed(binding, kind), "{binding} misses {kind}");
338 }
339 }
340 }
341
342 #[test]
343 fn a_subscriber_not_in_the_table_hears_everything() {
344 assert!(routed("SUBSCRIBER_NEW", "git.push"));
345 assert!(routed("SUBSCRIBER_NEW", "status.created"));
346 }
347
348 #[test]
349 fn a_family_matches_only_its_own_types() {
350 assert!(matches("pull.*", "pull.opened"));
351 assert!(!matches("pull.*", "pulls.opened"));
352 assert!(!matches("pull.*", "pull"));
353 assert!(matches("*", "x"));
354 assert!(matches("git.push", "git.push"));
355 assert!(!matches("git.push", "git.pushed"));
356 }
357}

This file's history is long; its oldest lines are credited to the oldest commit read.