Skip to content

g1t/apps/web/app/routes/workspace/guardrails.tsx

53 lines2,133 bytesCodeBlame

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-a985c01f43538af01'1import { data } from "react-router";
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API2
3import { RUN_KINDS } from "@g1t/contracts";
4
5import type { Route } from "./+types/guardrails";
6import { GuardrailsForm } from "../../components/guardrails";
Merge branch 'worktree-agent-a985c01f43538af01'7import { usePending } from "../../components/ui";
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API8import { settingsFromForm } from "../../lib/guardrails";
9import { page } from "../../lib/meta";
10import { guardrails } from "../../lib/services.server";
11import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server";
12
13export function meta({ params, ...args }: Route.MetaArgs) {
14 return page(args, { title: `Guardrails · ${params.owner} · g1t` });
15}
16
17export async function loader({ params, context }: Route.LoaderArgs) {
18 const viewer = getViewer(context);
19 const role = roleIn(viewer, params.owner);
20 if (!role) throw data(null, { status: 404 });
21 const view = await guardrails.getGuardrails(viewer, params.owner);
22 return { view: unwrap(view), owner: role === "owner" };
23}
24
25export async function action({ request, params, context }: Route.ActionArgs) {
26 assertSameOrigin(request);
27 const user = requireUser(context, request);
28 const form = await request.formData();
29 const current = await guardrails.getGuardrails(user, params.owner);
30 if (!current.ok) return { saved: false, error: current.error.message };
31 const settings = settingsFromForm(form, {
32 registries: current.value.registries.map((registry) => registry.id),
33 rules: current.value.rules.map((rule) => rule.id),
34 kinds: RUN_KINDS,
35 });
36 const saved = await guardrails.updateGuardrails(user, params.owner, null, settings);
37 return saved.ok ? { saved: true, error: null } : { saved: false, error: saved.error.message };
38}
39
40export default function WorkspaceGuardrails({ loaderData, actionData }: Route.ComponentProps) {
Merge branch 'worktree-agent-a985c01f43538af01'41 // Until the saved settings are back on the page, not just until the post is answered.
42 const saving = usePending();
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API43 return (
44 <GuardrailsForm
45 view={loaderData.view}
46 level="workspace"
47 editable={loaderData.owner}
48 saving={saving}
49 saved={actionData?.saved ?? false}
50 error={actionData?.error}
51 />
52 );
53}

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