Skip to content
248 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.

Chat and workspace agents: channels, DMs and named agents you talk to1/**
2 * The agent form (components/agents-mode.tsx) as the agents service takes
3 * it: what each field means, and the checks made before it is sent. Pure,
4 * so it is tested on its own.
5 */
Pricing says it plainly: models at the provider's price, the agent rate for what g1t runs around every model call (the gateway, secrets, routing, context and pass-through to your own provider, so your own keys too), everything else at cost plus 20%, your own runners free, no seats; Security and quality comes with the plan with no separate fee, and live activations end. Each agent has an effort setting, Auto to Max, with what a typical task has cost at each level, and Spend's Spend less, keep quality suggests a lower level only when the agent's own past work shows quality held, to apply or dismiss. The pricing, spend and agents guides say how.6import type { AgentEffort, ModelTier, NewWorkspaceAgent, PersonalityPreset, SubagentDef, WorkspaceAgent } from "@g1t/contracts";
Chat and workspace agents: channels, DMs and named agents you talk to7
Money is written one way. A single formatter turns millionths of a dollar into dollars, rounding half up on whole micros rather than on a float, so the same sum reads the same on every page: under a cent reads <$0.01 on a total and exactly nothing is $0.00, while the statement's lines, a session's receipt, the price book and an agent's effort costs carry up to four places where the fraction of a cent is the point; the six formatters that each rounded their own way are gone. This month is the calendar month in UTC from its first day to today everywhere, and billing counts the month's not-yet-closed usage in any range that reaches into the current month, so the top bar's pill, Spend, Home and Usage ask for the same days and get the same figure; Home now reads the usage report the others read instead of adding up statements. Usage's pending sentence says what of that usage the close will charge after the discount and included usage, which the billing API returns as pending_charged_micros. A reconciliation test holds the pill, Spend, Home and Usage to one number for one month. The usage and billing guide says how amounts are written and what this month means.8import { plainDollars } from "./money.ts";
9
Pricing says it plainly: models at the provider's price, the agent rate for what g1t runs around every model call (the gateway, secrets, routing, context and pass-through to your own provider, so your own keys too), everything else at cost plus 20%, your own runners free, no seats; Security and quality comes with the plan with no separate fee, and live activations end. Each agent has an effort setting, Auto to Max, with what a typical task has cost at each level, and Spend's Spend less, keep quality suggests a lower level only when the agent's own past work shows quality held, to apply or dismiss. The pricing, spend and agents guides say how.10/** An effort setting from a form: one of the five, or null. */
11export function readEffort(value: FormDataEntryValue | null): AgentEffort | null {
12 const text = String(value ?? "");
13 return text === "auto" || text === "low" || text === "medium" || text === "high" || text === "max" ? text : null;
14}
15
Chat and workspace agents: channels, DMs and named agents you talk to16/** The tiers, cheapest first: `MODEL_TIERS` in the contracts. */
17const MODEL_TIERS: ModelTier[] = ["small", "large", "frontier"];
18
19export const PRESETS: { value: PersonalityPreset; label: string; about: string }[] = [
20 { value: "crisp", label: "Crisp", about: "Clear and to the point, with enough context to act on." },
21 { value: "friendly", label: "Friendly", about: "Warm and encouraging; explains as it goes." },
22 { value: "socratic", label: "Socratic", about: "Asks before it assumes; draws out what you mean." },
23 { value: "terse", label: "Terse operator", about: "As few words as will do. Status, then done." },
24];
25
26export const TIER_LABELS: Record<ModelTier, string> = {
27 small: "Fast: replies and triage",
28 large: "Standard: making changes, most reviews",
29 frontier: "Most capable: planning and hard work",
30};
31
32export const AUTONOMY = {
33 open_pull_requests: { label: "Open pull requests", options: [["alone", "On its own"], ["approval", "After approval"]] },
34 merge: { label: "Merge", options: [["alone", "On its own"], ["approval", "After approval"], ["never", "Never"]] },
35 deploy_production: { label: "Deploy to production", options: [["approval", "After approval"], ["never", "Never"]] },
36 edit_docs: { label: "Edit docs", options: [["alone", "Directly"], ["suggest", "As suggestions"]] },
37} as const;
38
39/** The handle as people type it: lowercase letters, digits and dashes. */
40export function cleanHandle(typed: string): string {
41 return typed
42 .trim()
43 .toLowerCase()
44 .replace(/^@/, "")
45 .replace(/[\s_]+/g, "-")
46 .replace(/[^a-z0-9-]/g, "")
47 .replace(/-{2,}/g, "-")
48 .replace(/^-|-$/g, "")
49 .slice(0, 39);
50}
51
52/** Handles the site's own addresses use, and g1t's: never an agent's. */
53const RESERVED_HANDLES = new Set(["g1t", "new", "runs", "fleet"]);
54
55function tier(value: FormDataEntryValue | null): ModelTier | null {
56 const text = String(value ?? "");
57 return (MODEL_TIERS as string[]).includes(text) ? (text as ModelTier) : null;
58}
59
60function pick<T extends string>(value: FormDataEntryValue | null, allowed: readonly (readonly [T, string])[], fallback: T): T {
61 const text = String(value ?? "");
62 return (allowed.find(([key]) => key === text)?.[0] ?? fallback) as T;
63}
64
65export type AgentFormResult = { ok: true; input: NewWorkspaceAgent } | { ok: false; errors: Record<string, string> };
66
67/** The form, checked: the agent to make or the changes to save, or what to fix, by field. */
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)68export function readAgentForm(form: FormData, options: { orchestrator?: boolean } = {}): AgentFormResult {
Chat and workspace agents: channels, DMs and named agents you talk to69 const errors: Record<string, string> = {};
70 const display_name = String(form.get("display_name") ?? "").trim();
71 const handle = cleanHandle(String(form.get("handle") ?? "") || display_name);
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)72 const title = String(form.get("title") ?? "").trim();
73 const responsibilities = form
74 .getAll("responsibility")
75 .map((value) => String(value).trim())
76 .filter(Boolean)
77 .slice(0, MAX_RESPONSIBILITIES);
78 const subagents = readSubagents(form.get("subagents"));
Agents recall what Docs say before they answer or work, and each has required reading79 // Docs spaces it reads first; the agents service checks them.
80 const reading = [...new Set(form.getAll("reading").map((value) => String(value).trim()).filter(Boolean))].slice(0, 10);
Chat and workspace agents: channels, DMs and named agents you talk to81 const instructions = String(form.get("instructions") ?? "").trim();
82 if (!display_name) errors.display_name = "Give it a name.";
83 if (!handle) errors.handle = "Give it a handle, like @ship.";
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)84 else if (RESERVED_HANDLES.has(handle) && !(options.orchestrator && handle === "g1t")) errors.handle = `@${handle} is taken by g1t.`;
85 if (!title && !options.orchestrator) errors.title = "Give it a title, like QA Engineer.";
86 if (subagents == null) errors.subagents = "The subagents couldn't be read. Edit one and save again.";
87 // g1t's job is fixed; what is written here is added to it, and may be nothing.
88 if (!instructions && !options.orchestrator) errors.instructions = "Tell it what it's responsible for.";
Chat and workspace agents: channels, DMs and named agents you talk to89 const floor = tier(form.get("floor"));
90 const ceiling = tier(form.get("ceiling"));
91 if (floor && ceiling && MODEL_TIERS.indexOf(floor) > MODEL_TIERS.indexOf(ceiling)) errors.ceiling = "The ceiling can't be below the floor.";
92 const budget = {
93 monthly_micros: microsFromDollars(form.get("monthly")),
94 daily_micros: microsFromDollars(form.get("daily")),
95 task_micros: microsFromDollars(form.get("task")),
96 };
97 for (const [field, value] of [["monthly", budget.monthly_micros], ["daily", budget.daily_micros], ["task", budget.task_micros]] as const) {
98 if (value != null && Number.isNaN(value)) errors[field] = "A sum in dollars, like 25.";
99 }
100 const capacity = Number(form.get("capacity") ?? 3);
101 if (!Number.isInteger(capacity) || capacity < 1 || capacity > 20) errors.capacity = "Between 1 and 20.";
102 const providers = String(form.get("providers") ?? "any");
103 const pinned = String(form.get("pinned") ?? "").trim();
Pricing says it plainly: models at the provider's price, the agent rate for what g1t runs around every model call (the gateway, secrets, routing, context and pass-through to your own provider, so your own keys too), everything else at cost plus 20%, your own runners free, no seats; Security and quality comes with the plan with no separate fee, and live activations end. Each agent has an effort setting, Auto to Max, with what a typical task has cost at each level, and Spend's Spend less, keep quality suggests a lower level only when the agent's own past work shows quality held, to apply or dismiss. The pricing, spend and agents guides say how.104 // How hard it works; a form without the control leaves it as it is.
105 const effort = readEffort(form.get("effort"));
Chat and workspace agents: channels, DMs and named agents you talk to106 if (pinned && !/^[\w.-]+\/[\w.:@-]+$/.test(pinned)) errors.pinned = "As provider/model.";
107 if (Object.keys(errors).length > 0) return { ok: false, errors };
108 return {
109 ok: true,
110 input: {
111 handle,
112 display_name,
An agent is on teams the way a person is: through team membership, with no team or department of its own. Add it to teams when you create it, from its profile or from the team's page; the Agents sidebar groups agents by the teams they're on, with those on none last; what an agent is told about its teammates, team budgets, skills reach, Spend's By team and the People pages all read memberships. Agents with an old team name matching a team are moved onto it once; the rest are left off a team. Templates name a role only. The agents, teams and people guides say how.113 // Its title, made by the agents service.
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)114 role: "",
115 title,
116 responsibilities,
117 subagents: subagents ?? [],
Agents recall what Docs say before they answer or work, and each has required reading118 reading,
Chat and workspace agents: channels, DMs and named agents you talk to119 instructions,
120 personality_preset: pick(form.get("personality_preset"), PRESETS.map((p) => [p.value, p.label] as const), "crisp"),
121 personality: String(form.get("personality") ?? "").trim(),
122 routing: {
123 floor,
124 ceiling,
125 providers: providers === "any" ? [] : [providers],
126 pinned: pinned || null,
Pricing says it plainly: models at the provider's price, the agent rate for what g1t runs around every model call (the gateway, secrets, routing, context and pass-through to your own provider, so your own keys too), everything else at cost plus 20%, your own runners free, no seats; Security and quality comes with the plan with no separate fee, and live activations end. Each agent has an effort setting, Auto to Max, with what a typical task has cost at each level, and Spend's Spend less, keep quality suggests a lower level only when the agent's own past work shows quality held, to apply or dismiss. The pricing, spend and agents guides say how.127 ...(effort ? { effort } : {}),
Chat and workspace agents: channels, DMs and named agents you talk to128 },
129 budget,
130 autonomy: {
131 open_pull_requests: pick(form.get("open_pull_requests"), AUTONOMY.open_pull_requests.options, "alone"),
132 merge: pick(form.get("merge"), AUTONOMY.merge.options, "approval"),
133 deploy_production: pick(form.get("deploy_production"), AUTONOMY.deploy_production.options, "approval"),
134 edit_docs: pick(form.get("edit_docs"), AUTONOMY.edit_docs.options, "suggest"),
135 },
136 capacity,
137 template: String(form.get("template") ?? "") || null,
Anyone makes an agent by describing it: one box drafts the whole agent (name, job, responsibilities, voice, skills to keep, integrations it needs, model limits and budget) as a card to change and try in a chat beside it before creating it, and an agent changes later by saying what to change, shown as a diff before it's saved. Members can make personal agents, which only they talk to and which spend from their own budget, unless owners turn that off; owners promote one to a workspace agent. The agents guide says how.138 // A drafted agent carries its scope, the skills it keeps off and its face.
139 ...(form.get("scope") === "personal" || form.get("scope") === "workspace" ? { scope: form.get("scope") as "personal" | "workspace" } : {}),
140 ...(form.has("skills_off") ? { skills_off: String(form.get("skills_off") ?? "").split(",").map((id) => id.trim()).filter(Boolean) } : {}),
141 ...(String(form.get("avatar_seed") ?? "").trim() ? { avatar_seed: String(form.get("avatar_seed")).trim().slice(0, 64) } : {}),
Chat and workspace agents: channels, DMs and named agents you talk to142 },
143 };
144}
145
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)146/** Most responsibilities an agent lists. */
147export const MAX_RESPONSIBILITIES = 8;
148
149/** The subagents, as the form sends them (JSON); null when they are not valid. */
150function readSubagents(value: FormDataEntryValue | null): SubagentDef[] | null {
151 const text = String(value ?? "").trim();
152 if (!text) return [];
153 try {
154 const parsed = JSON.parse(text) as unknown;
155 if (!Array.isArray(parsed)) return null;
156 return parsed.filter(
157 (item): item is SubagentDef =>
158 item != null && typeof item === "object" && typeof (item as SubagentDef).name === "string" && typeof (item as SubagentDef).description === "string",
159 );
160 } catch {
161 return null;
162 }
163}
164
165/** A subagent's name: lowercase letters, digits and hyphens. */
166export function cleanSubagentName(typed: string): string {
167 return cleanHandle(typed).slice(0, 40);
168}
169
170/**
171 * A subagent's routing limits, kept within its agent's: a floor below the
172 * agent's is raised to it, a ceiling above the agent's is lowered to it,
173 * and a floor above the ceiling comes down to it.
174 */
175export function clampRouting(
176 sub: { floor: ModelTier | null; ceiling: ModelTier | null },
177 agent: { floor: ModelTier | null; ceiling: ModelTier | null },
178): { floor: ModelTier | null; ceiling: ModelTier | null } {
179 const rank = (tier: ModelTier) => MODEL_TIERS.indexOf(tier);
180 let floor = sub.floor;
181 let ceiling = sub.ceiling;
182 if (agent.floor && (!floor || rank(floor) < rank(agent.floor))) floor = agent.floor;
183 if (agent.ceiling && (!ceiling || rank(ceiling) > rank(agent.ceiling))) ceiling = agent.ceiling;
184 if (floor && ceiling && rank(floor) > rank(ceiling)) floor = ceiling;
185 return { floor, ceiling };
186}
187
An agent is on teams the way a person is: through team membership, with no team or department of its own. Add it to teams when you create it, from its profile or from the team's page; the Agents sidebar groups agents by the teams they're on, with those on none last; what an agent is told about its teammates, team budgets, skills reach, Spend's By team and the People pages all read memberships. Agents with an old team name matching a team are moved onto it once; the rest are left off a team. Templates name a role only. The agents, teams and people guides say how.188/**
189 * The teams a new agent joins as it is made (the form's "Add to teams"),
190 * by slug: membership is the team's, never part of the agent.
191 */
192export function readTeams(form: FormData): string[] {
193 return [...new Set(form.getAll("teams").map((value) => String(value).trim().toLowerCase()).filter((slug) => /^[a-z0-9][a-z0-9-]{0,63}$/.test(slug)))].slice(0, 20);
194}
195
Chat and workspace agents: channels, DMs and named agents you talk to196/** What the form starts from: an agent being edited, a template, or nothing. */
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)197export type AgentDraft = Pick<
198 WorkspaceAgent,
199 | "handle"
200 | "display_name"
201 | "role"
202 | "title"
203 | "responsibilities"
204 | "subagents"
Agents recall what Docs say before they answer or work, and each has required reading205 | "reading"
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)206 | "instructions"
207 | "personality_preset"
208 | "personality"
209 | "routing"
210 | "budget"
211 | "autonomy"
212 | "capacity"
213 | "template"
214>;
Chat and workspace agents: channels, DMs and named agents you talk to215
216export const BLANK_DRAFT: AgentDraft = {
217 handle: "",
218 display_name: "",
219 role: "",
Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002)220 title: "",
221 responsibilities: [],
222 subagents: [],
Agents recall what Docs say before they answer or work, and each has required reading223 reading: [],
Chat and workspace agents: channels, DMs and named agents you talk to224 instructions: "",
225 personality_preset: "crisp",
226 personality: "",
Pricing says it plainly: models at the provider's price, the agent rate for what g1t runs around every model call (the gateway, secrets, routing, context and pass-through to your own provider, so your own keys too), everything else at cost plus 20%, your own runners free, no seats; Security and quality comes with the plan with no separate fee, and live activations end. Each agent has an effort setting, Auto to Max, with what a typical task has cost at each level, and Spend's Spend less, keep quality suggests a lower level only when the agent's own past work shows quality held, to apply or dismiss. The pricing, spend and agents guides say how.227 routing: { floor: null, ceiling: null, providers: [], pinned: null, effort: "auto" },
Chat and workspace agents: channels, DMs and named agents you talk to228 budget: { monthly_micros: 50_000_000, daily_micros: null, task_micros: 5_000_000 },
229 autonomy: { open_pull_requests: "alone", merge: "approval", deploy_production: "approval", edit_docs: "suggest" },
230 capacity: 3,
231 template: null,
232};
233
Money is written one way. A single formatter turns millionths of a dollar into dollars, rounding half up on whole micros rather than on a float, so the same sum reads the same on every page: under a cent reads <$0.01 on a total and exactly nothing is $0.00, while the statement's lines, a session's receipt, the price book and an agent's effort costs carry up to four places where the fraction of a cent is the point; the six formatters that each rounded their own way are gone. This month is the calendar month in UTC from its first day to today everywhere, and billing counts the month's not-yet-closed usage in any range that reaches into the current month, so the top bar's pill, Spend, Home and Usage ask for the same days and get the same figure; Home now reads the usage report the others read instead of adding up statements. Usage's pending sentence says what of that usage the close will charge after the discount and included usage, which the billing API returns as pending_charged_micros. A reconciliation test holds the pill, Spend, Home and Usage to one number for one month. The usage and billing guide says how amounts are written and what this month means.234/** Dollars from micro-dollars, for a form field: empty for none, `20` for a whole sum, else to the cent. */
Chat and workspace agents: channels, DMs and named agents you talk to235export function dollarsField(micros: number | null | undefined): string {
236 if (micros == null) return "";
Money is written one way. A single formatter turns millionths of a dollar into dollars, rounding half up on whole micros rather than on a float, so the same sum reads the same on every page: under a cent reads <$0.01 on a total and exactly nothing is $0.00, while the statement's lines, a session's receipt, the price book and an agent's effort costs carry up to four places where the fraction of a cent is the point; the six formatters that each rounded their own way are gone. This month is the calendar month in UTC from its first day to today everywhere, and billing counts the month's not-yet-closed usage in any range that reaches into the current month, so the top bar's pill, Spend, Home and Usage ask for the same days and get the same figure; Home now reads the usage report the others read instead of adding up statements. Usage's pending sentence says what of that usage the close will charge after the discount and included usage, which the billing API returns as pending_charged_micros. A reconciliation test holds the pill, Spend, Home and Usage to one number for one month. The usage and billing guide says how amounts are written and what this month means.237 return plainDollars(micros, { whole: true });
Chat and workspace agents: channels, DMs and named agents you talk to238}
239
240/** Micro-dollars from a form field in dollars: null when empty, NaN when not a sum. */
241export function microsFromDollars(value: FormDataEntryValue | null): number | null {
242 const text = String(value ?? "").trim().replace(/^\$/, "").replaceAll(",", "");
243 if (!text) return null;
244 const dollars = Number(text);
245 if (!Number.isFinite(dollars) || dollars < 0) return Number.NaN;
246 return Math.round(dollars * 1_000_000);
247}
248

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