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/services/runner/src/hub.ts

33 lines1,228 bytesCodeBlame
1/**
2 * The context hub's section of an agent's prompt: the project's catalog
3 * entry, the memories closest to its task and recent decisions, from the
4 * context service. Never holds up a run: on any trouble, nothing.
5 */
6
7import { contextClient, reposClient, type RepoPath, type ServiceBinding } from "@g1t/contracts";
8
9/** How much of a prompt the hub's section may take, in characters. */
10const BUDGET = 4000;
11
12export async function hubContext(
13 env: { CONTEXT?: ServiceBinding; REPOS: ServiceBinding },
14 repo: RepoPath,
15 task: string,
16): Promise<string | null> {
17 if (!env.CONTEXT) return null;
18 try {
19 // g1t itself, as a member of the repository's workspace, so a private one is found.
20 const viewer = {
21 id: "g1t_runner",
22 username: "g1t",
23 workspaces: [{ slug: repo.namespace.toLowerCase(), role: "member" as const }],
24 };
25 const found = await reposClient(env.REPOS).get(repo, viewer);
26 if (!found.ok) return null;
27 const context = await contextClient(env.CONTEXT).runContext(found.value.id, task.slice(0, 2000), BUDGET);
28 return context.text;
29 } catch (error) {
30 console.log("no context hub section", `${repo.namespace}/${repo.name}`, String(error));
31 return null;
32 }
33}