346 lines
17 KiB
Vue
346 lines
17 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import { computed, onMounted, ref, watch } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
import { Plus } from "@lucide/vue";
|
|
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { api } from "@/lib/api";
|
|
import { useOrgStore, type Identity } from "@/stores/org";
|
|
import {
|
|
NumberField,
|
|
NumberFieldContent,
|
|
NumberFieldDecrement,
|
|
NumberFieldIncrement,
|
|
NumberFieldInput,
|
|
} from "@/components/ui/number-field";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import {
|
|
TagsInput,
|
|
TagsInputInput,
|
|
TagsInputItem,
|
|
TagsInputItemDelete,
|
|
TagsInputItemText,
|
|
} from "@/components/ui/tags-input";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import CardAccordion from "./CardAccordion.vue";
|
|
import CommandListEditor from "./CommandListEditor.vue";
|
|
import DraftHint from "./DraftHint.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
|
|
const KIND = "repository-policies";
|
|
const DANGER_ROW =
|
|
"relative isolate before:pointer-events-none before:absolute before:inset-y-0 before:-inset-x-3 before:-z-10 before:rounded-md before:border before:border-danger/40 before:bg-danger-soft";
|
|
|
|
interface Repo {
|
|
connection: string;
|
|
owner: string;
|
|
name: string;
|
|
base: string;
|
|
ecosystem: string;
|
|
gate: string[][] | null;
|
|
tooling: string[][] | null;
|
|
preflight: string[][] | null;
|
|
protect: string[] | null;
|
|
test_glob: string;
|
|
persistent_storage: boolean;
|
|
instructions?: string;
|
|
max_retries: number;
|
|
allow_concurrent: boolean;
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
const organisation = useOrgStore();
|
|
const agents=ref<Identity[]>([]);
|
|
const agentError=ref("");
|
|
onMounted(async()=>{
|
|
void store.load();
|
|
try {
|
|
await organisation.loadOrg();
|
|
const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg);
|
|
agents.value=response.agents.filter((agent)=>agent.lifecycle==="active");
|
|
} catch(cause) {agentError.value=String((cause as Error).message || cause)}
|
|
});
|
|
|
|
const resources = computed(() => resourcesForPage(catalog.value, "repositories"));
|
|
const form = computed(() => store.formFor(KIND));
|
|
const repos = computed(() => (store.draftValue(KIND) ?? []) as Repo[]);
|
|
const connections = computed(() => (store.draftValue("forge-connections") ?? []) as { id: string; name: string }[]);
|
|
const error = computed(() => store.pageErrorFor(KIND));
|
|
|
|
const ecosystems = ["go", "python", "node", "rust", "custom"];
|
|
const newRepo = ref("");
|
|
const open = ref("0");
|
|
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
|
|
|
// The repository list is the whole document, so adding and removing rebuild it.
|
|
function addRepo() {
|
|
if (unsaved.value) return;
|
|
const [owner, name] = newRepo.value.trim().split("/");
|
|
if (!form.value || !owner || !name) return;
|
|
const next: Repo[] = [
|
|
...repos.value,
|
|
{
|
|
owner, name, connection: "", base: "main", ecosystem: "go", gate: [], tooling: null, preflight: null, protect: null,
|
|
test_glob: "", persistent_storage: false, max_retries: 0, allow_concurrent: false,
|
|
},
|
|
];
|
|
store.setDraftValue(KIND, next);
|
|
newRepo.value = "";
|
|
open.value = String(next.length - 1);
|
|
}
|
|
function removeRepo(index: number) {
|
|
store.setDraftValue(KIND, repos.value.filter((_, i) => i !== index));
|
|
}
|
|
interface AccessCheck { verified?: boolean; account?: string; base_branch?: string; operations?: string[]; message?: string }
|
|
const checkAgent=ref("");
|
|
const checking=ref("");
|
|
const results=ref<Record<string,AccessCheck>>({});
|
|
watch([checkAgent,()=>JSON.stringify(repos.value)],()=>{results.value={}});
|
|
// Where a repository stands: a missing connection is known from the draft, the
|
|
// rest only after an access check.
|
|
function readiness(repo: Repo): { variant: "ok" | "warn" | "danger"; label: string } | null {
|
|
if (!repo.connection || !connections.value.some((connection) => connection.id === repo.connection)) return { variant: "warn", label: "No connection" };
|
|
const result = results.value[`${repo.owner}/${repo.name}`];
|
|
if (!result) return null;
|
|
return result.verified ? { variant: "ok", label: "Verified" } : { variant: "danger", label: "Check failed" };
|
|
}
|
|
async function checkAccess(repo:Repo):Promise<void>{
|
|
if(unsaved.value || !checkAgent.value || checking.value)return;
|
|
const key=`${repo.owner}/${repo.name}`;
|
|
const input=JSON.stringify([repo,checkAgent.value]);
|
|
checking.value=key;
|
|
delete results.value[key];
|
|
try {
|
|
const result=await api.checkRepository<AccessCheck>({owner:repo.owner,repository:repo.name,identity_id:checkAgent.value});
|
|
if(input===JSON.stringify([repo,checkAgent.value]))results.value[key]=result;
|
|
}catch(cause){
|
|
if(input===JSON.stringify([repo,checkAgent.value]))results.value[key]={message:String((cause as Error).message || cause)};
|
|
}finally{checking.value=""}
|
|
}
|
|
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Repositories">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
|
|
|
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>{{ catalogError || error }}</AlertDescription></Alert>
|
|
|
|
<template v-if="form">
|
|
<CardAccordion v-model:open="open" :items="repos" :title="(r) => `${r.owner}/${r.name}`" remove-label="Remove" mono @remove="removeRepo">
|
|
<template #aside="{ item }">
|
|
<Badge v-if="readiness(item as Repo)" :variant="readiness(item as Repo)!.variant">{{ readiness(item as Repo)!.label }}</Badge>
|
|
</template>
|
|
<template #default="{ item: repo, index: i }">
|
|
<FieldGroup class="@container/field-group">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel>Connection</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<form.Field v-slot="{ field }" :name="`${i}.connection`">
|
|
<Select :model-value="field.state.value" @update:model-value="field.handleChange">
|
|
<SelectTrigger class="w-64" :aria-label="`Connection for ${repo.name}`"><SelectValue placeholder="Choose a connection" /></SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem v-for="connection in connections" :key="connection.id" :value="connection.id">{{ connection.name || connection.id }}</SelectItem>
|
|
<SelectItem v-if="repo.connection && !connections.some((connection) => connection.id === repo.connection)" :value="repo.connection" disabled>Unavailable connection</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</form.Field>
|
|
</div>
|
|
</Field>
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel>Check access</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<div class="grid gap-2">
|
|
<Select v-model="checkAgent">
|
|
<SelectTrigger class="w-64" :aria-label="`Check ${repo.name} access as`"><SelectValue placeholder="Choose an agent" /></SelectTrigger>
|
|
<SelectContent><SelectItem v-for="agent in agents" :key="agent.id" :value="agent.id">{{ agent.display_name }}</SelectItem></SelectContent>
|
|
</Select>
|
|
<Button type="button" variant="outline" class="w-fit" :disabled="!checkAgent || !repo.connection || unsaved || !!checking" @click="checkAccess(repo)">{{checking===`${repo.owner}/${repo.name}` ? "Checking…" : "Check access"}}</Button>
|
|
<p v-if="unsaved" class="text-xs text-fg-muted">Save changes before checking access.</p>
|
|
<Alert v-if="agentError" variant="destructive"><AlertDescription>{{agentError}}</AlertDescription></Alert>
|
|
<p v-if="results[`${repo.owner}/${repo.name}`]" role="status" class="text-xs" :class="results[`${repo.owner}/${repo.name}`].verified ? 'text-ok' : 'text-danger'">
|
|
<template v-if="results[`${repo.owner}/${repo.name}`].verified">{{ results[`${repo.owner}/${repo.name}`].operations?.join(" · ") }} as {{ results[`${repo.owner}/${repo.name}`].account }}</template>
|
|
<template v-else>{{ results[`${repo.owner}/${repo.name}`].message }}</template>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.base`">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel :for="`repo-${i}-base`">Base branch</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Input :id="`repo-${i}-base`" :model-value="field.state.value" class="max-w-56 font-mono" @blur="field.handleBlur" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.base`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.ecosystem`">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel>Ecosystem</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Select :model-value="field.state.value" @update:model-value="field.handleChange">
|
|
<SelectTrigger class="w-40 font-mono" :aria-label="`Ecosystem for ${repo.name}`"><SelectValue /></SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem v-for="e in ecosystems" :key="e" :value="e">{{ e }}</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<DraftHint :kind="KIND" :path="`${i}.ecosystem`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.gate`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Quality gate</FieldLabel>
|
|
<FieldDescription>Last command runs the tests.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<CommandListEditor :model-value="field.state.value" label="Gate" empty-text="No gate." @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.gate`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.tooling`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Tooling</FieldLabel>
|
|
<FieldDescription>Installs the gate needs; runs before it.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<CommandListEditor :model-value="field.state.value" label="Tooling" empty-text="Nothing to install." @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.tooling`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.preflight`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Preflight</FieldLabel>
|
|
<FieldDescription>Empty: ecosystem default.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<CommandListEditor :model-value="field.state.value" label="Preflight" empty-text="Ecosystem default." @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.preflight`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.test_glob`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel :for="`repo-${i}-glob`">Test files</FieldLabel>
|
|
<FieldDescription>Empty: ecosystem default.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Input :id="`repo-${i}-glob`" :model-value="field.state.value" class="max-w-56 font-mono" placeholder="*_test.go" @blur="field.handleBlur" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.test_glob`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.instructions`">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel :for="`repo-${i}-instructions`">Instructions</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<div class="grid w-full gap-1">
|
|
<Textarea :id="`repo-${i}-instructions`" :model-value="field.state.value" :rows="5" class="font-mono text-label" @blur="field.handleBlur" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.instructions`" />
|
|
</div>
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.protect`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Protected paths</FieldLabel>
|
|
<FieldDescription>Suffixes agents never write.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<TagsInput
|
|
:model-value="field.state.value ?? []"
|
|
class="font-mono"
|
|
:aria-label="`Protected paths for ${repo.name}`"
|
|
@update:model-value="(v) => field.handleChange(v as string[])"
|
|
>
|
|
<TagsInputItem v-for="p in field.state.value ?? []" :key="p" :value="p">
|
|
<TagsInputItemText />
|
|
<TagsInputItemDelete />
|
|
</TagsInputItem>
|
|
<TagsInputInput placeholder="_templ.go" />
|
|
</TagsInput>
|
|
<DraftHint :kind="KIND" :path="`${i}.protect`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.max_retries`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Max retries</FieldLabel>
|
|
<FieldDescription>0 = scheduling policy value.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
|
|
<NumberFieldContent>
|
|
<NumberFieldDecrement />
|
|
<NumberFieldInput class="font-mono" :aria-label="`Max retries for ${repo.name}`" />
|
|
<NumberFieldIncrement />
|
|
</NumberFieldContent>
|
|
</NumberField>
|
|
<DraftHint :kind="KIND" :path="`${i}.max_retries`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.persistent_storage`">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Persistent storage</FieldLabel>
|
|
<FieldDescription>Kept across tasks.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Switch :model-value="field.state.value" :aria-label="`Persistent storage for ${repo.name}`" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.persistent_storage`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`${i}.allow_concurrent`">
|
|
<Field orientation="responsive" :class="repo.allow_concurrent ? DANGER_ROW : undefined">
|
|
<FieldContent>
|
|
<FieldLabel>Concurrent tasks</FieldLabel>
|
|
<FieldDescription>Only if worktrees cannot collide.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Switch :model-value="field.state.value" :aria-label="`Concurrent tasks for ${repo.name}`" @update:model-value="field.handleChange" />
|
|
<DraftHint :kind="KIND" :path="`${i}.allow_concurrent`" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
</FieldGroup>
|
|
</template>
|
|
</CardAccordion>
|
|
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
<Input v-model="newRepo" class="max-w-72 font-mono" placeholder="owner/repository" aria-label="New repository" :disabled="unsaved" @keydown.enter="addRepo" />
|
|
<Button variant="outline" size="sm" :disabled="unsaved || !/^[^/\s]+\/[^/\s]+$/.test(newRepo.trim())" @click="addRepo">
|
|
<Plus data-icon="inline-start" /> Add repository</Button>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|