import { useState } from "react"; import { Check, FolderOpen, Loader2, Plus, X } from "lucide-react"; import { Button } from "./ui/button"; import { Checkbox } from "./ui/checkbox"; import { Input } from "./ui/input"; import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; export interface AllowedProjectsEditorProps { projects: Array<{ id: string; name: string }>; projectIds: string[]; canManage: boolean; agentName: string; onSave: (projectIds: string[]) => Promise; } export function AllowedProjectsEditor({ projects, projectIds, canManage, agentName, onSave }: AllowedProjectsEditorProps) { const [added, setAdded] = useState([]); const [open, setOpen] = useState(false); const [query, setQuery] = useState(""); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); const pending = added.filter(id => !projectIds.includes(id)); const visibleIds = [...new Set([...projectIds, ...pending])]; const name = (id: string) => projects.find(project => project.id === id)?.name ?? "Unavailable project"; const matches = projects.filter(project => project.name.toLowerCase().includes(query.toLowerCase())); async function save() { if (!canManage || saving || !pending.length) return; setSaving(true); setError(null); setSaved(false); try { await onSave(pending); setAdded([]); setSaved(true); } catch (failure) { setError(failure instanceof Error ? failure.message : "Couldn’t save project access."); } finally { setSaving(false); } } return

Allowed projects

Projects whose tasks and repositories this agent may access.

{canManage && setQuery(event.target.value)} />
{matches.map(project => )}
{!matches.length &&

No projects found.

}
}
{visibleIds.length ?
    {visibleIds.map(id =>
  • {name(id)} {projectIds.includes(id) ? Allowed : <>To add}
  • )}
:

No projects allowed yet.

} {!canManage &&

A person with agent-management permission can add projects here.

} {pending.length > 0 &&

Add access to {pending.map(name).join(", ")}

{agentName} will be able to access work and repositories in {pending.length === 1 ? "this project" : "these projects"}. Existing project access and low-trust restrictions stay in place.

} {error &&

Couldn’t save project access. Your selection is kept. {error}

} {saved &&

Project access saved. Return to your task to retry.

} {canManage &&
}
; }