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
37 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.

g1t coordinates the work and the person's own sessions do it: Ask g1t reads g1t with the same tools any agent gets, answers in one conversation shared with the @g1t direct message in Chat, and hands work to sessions in the person's own harness, whose subagents g1t records, ties to issues and pull requests, and lets see each other.1/**
2 * The methods only g1t's own services call (`chatInternalClient` in
3 * @g1t/contracts), at `POST /internal/<method>`: they act as @g1t and take
4 * no viewer. The site never reaches them: it calls `/rpc/<method>` by name,
5 * on a person's behalf, and nothing it sends goes to `/internal/`. And
6 * anything that came in from the internet is refused, should a route ever
7 * be pointed at this Worker by mistake.
8 */
9
10/** What the service does for these methods (src/index.ts). */
11export type InternalChat = {
12 internalG1tPost(a: { workspace: string; channel_id: string; body: string }): Promise<unknown>;
13 internalG1tEdit(a: { workspace: string; channel_id: string; id: string; body: string }): Promise<unknown>;
14};
15
16/**
17 * Whether a request came from the internet. Cloudflare names the client of
18 * every request that reached it from outside; a service binding's request
19 * carries none of these unless a caller copied them over, which g1t's
20 * services never do.
21 */
22export function fromInternet(request: Request): boolean {
23 return request.headers.has("cf-connecting-ip") || request.headers.has("x-real-ip") || request.headers.has("x-forwarded-for");
24}
25
26export async function internalAnswer(service: InternalChat, request: Request, method: string): Promise<Response> {
27 if (fromInternet(request)) return new Response("Forbidden\n", { status: 403 });
28 const args = (await request.json().catch(() => ({}))) as any;
29 switch (method) {
30 case "g1t_post":
31 return Response.json(await service.internalG1tPost(args));
32 case "g1t_edit":
33 return Response.json(await service.internalG1tEdit(args));
34 default:
35 return new Response("Unknown method\n", { status: 404 });
36 }
37}