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

35 lines1,350 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, type User } 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 /** The person the run acts for: the section holds only what they may read. */
17 requester: User,
18): Promise<string | null> {
19 if (!env.CONTEXT) return null;
20 try {
21 // g1t itself, as a member of the repository's workspace, so a private one is found.
22 const viewer = {
23 id: "g1t_runner",
24 username: "g1t",
25 workspaces: [{ slug: repo.namespace.toLowerCase(), role: "member" as const }],
26 };
27 const found = await reposClient(env.REPOS).get(repo, viewer);
28 if (!found.ok) return null;
29 const context = await contextClient(env.CONTEXT).runContext(found.value.id, task.slice(0, 2000), BUDGET, requester);
30 return context.text;
31 } catch (error) {
32 console.log("no context hub section", `${repo.namespace}/${repo.name}`, String(error));
33 return null;
34 }
35}