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' | 1 | import { data } from "react-router"; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 2 | |
| 3 | import { RUN_KINDS } from "@g1t/contracts"; | |
| 4 | ||
| 5 | import type { Route } from "./+types/guardrails"; | |
| 6 | import { GuardrailsForm } from "../../components/guardrails"; | |
| Merge branch 'worktree-agent-a985c01f43538af01' | 7 | import { usePending } from "../../components/ui"; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 8 | import { settingsFromForm } from "../../lib/guardrails"; |
| 9 | import { page } from "../../lib/meta"; | |
| 10 | import { guardrails } from "../../lib/services.server"; | |
| 11 | import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server"; | |
| 12 | ||
| 13 | export function meta({ params, ...args }: Route.MetaArgs) { | |
| 14 | return page(args, { title: `Guardrails · ${params.owner} · g1t` }); | |
| 15 | } | |
| 16 | ||
| 17 | export 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 | ||
| 25 | export 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 | ||
| 40 | export 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 API | 43 | 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.