g1t/apps/web/app/routes/repo/settings-guardrails.tsx
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.
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 1 | import { Link, data, useNavigation } from "react-router"; |
| 2 | ||
| 3 | import { RUN_KINDS } from "@g1t/contracts"; | |
| 4 | ||
| 5 | import type { Route } from "./+types/settings-guardrails"; | |
| 6 | import { GuardrailsForm } from "../../components/guardrails"; | |
| Project settings move into the sidebar, grouped, with a heading per page | 7 | import { RepoSettingsHeading } from "../../components/repo-settings-heading"; |
| 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}/${params.repo} · g1t` }); | |
| 15 | } | |
| 16 | ||
| 17 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 18 | const viewer = getViewer(context); | |
| 19 | // Members only; to anyone else the page does not exist. | |
| 20 | if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 }); | |
| 21 | const view = await guardrails.getGuardrails(viewer, params.owner, { namespace: params.owner, name: params.repo }); | |
| 22 | return { view: unwrap(view) }; | |
| 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, { namespace: params.owner, name: params.repo }, settings); | |
| 37 | return saved.ok ? { saved: true, error: null } : { saved: false, error: saved.error.message }; | |
| 38 | } | |
| 39 | ||
| 40 | export default function RepoGuardrails({ loaderData, actionData, params }: Route.ComponentProps) { | |
| 41 | const saving = useNavigation().state === "submitting"; | |
| 42 | const base = `/${params.owner}/${params.repo}`; | |
| 43 | return ( | |
| 44 | <> | |
| Project settings move into the sidebar, grouped, with a heading per page | 45 | <RepoSettingsHeading base={base} /> |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 46 | <p className="mb-8 max-w-3xl text-sm text-muted"> |
| 47 | What g1t's agents, checks and merge queue may do in this project's sandboxes. Anything left as the | |
| 48 | workspace's follows the{" "} | |
| 49 | <Link to={`/${params.owner}/-/guardrails`} className="text-fg underline-offset-2 hover:underline"> | |
| 50 | workspace's defaults | |
| 51 | </Link> | |
| 52 | . Changes apply to runs that start after you save. | |
| 53 | </p> | |
| 54 | <GuardrailsForm | |
| 55 | view={loaderData.view} | |
| 56 | level="project" | |
| 57 | editable | |
| 58 | saving={saving} | |
| 59 | saved={actionData?.saved ?? false} | |
| 60 | error={actionData?.error} | |
| 61 | /> | |
| 62 | </> | |
| 63 | ); | |
| 64 | } |