Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat(knowledges): inline rename and delete actions in knowledge header and list
Sergey Kozyrenkofff79b397941
diff --git a/frontend/src/features/knowledges/knowledge-form.tsx b/frontend/src/features/knowledges/knowledge-form.tsxindex a367cd03..16e4f03d 100644--- a/frontend/src/features/knowledges/knowledge-form.tsx+++ b/frontend/src/features/knowledges/knowledge-form.tsx@@ -191,11 +191,10 @@ interface KnowledgeFormProps {initialValues: FormValues;isNew: boolean;knowledge?: KnowledgeDocumentFragmentFragment | null;- knowledgeName: null | string;onSubmit: (values: FormValues, dirtyFields: DirtyFlags) => Promise<SubmitResult>;}-export const KnowledgeForm = ({ initialValues, isNew, knowledge, knowledgeName, onSubmit }: KnowledgeFormProps) => {+export const KnowledgeForm = ({ initialValues, isNew, knowledge, onSubmit }: KnowledgeFormProps) => {const navigate = useNavigate();const { isDesktop } = useBreakpoint();const [isSaving, setIsSaving] = useState(false);@@ -208,7 +207,20 @@ export const KnowledgeForm = ({ initialValues, isNew, knowledge, knowledgeName,// markdown editor) — same UX after the first interaction, no waste// on initial mount or untouched fields.mode: 'onTouched',+ resetOptions: {+ // When `values` changes (e.g. a GraphQL subscription pushes an+ // updated document after an inline rename from the header),+ // refresh the form's defaults but keep any unsaved edits the+ // user is still working on. Without this, an external update+ // would silently wipe their in-flight changes.+ keepDirtyValues: true,+ },resolver: zodResolver(formSchema),+ // `values` reactively syncs the form with `initialValues`. The page+ // recomputes `initialValues` from `knowledge` whenever the cache+ // refreshes (rename, refetch, etc.), and RHF reapplies the new+ // values on top of the form respecting `resetOptions` above.+ values: initialValues,});const { control, formState, handleSubmit, reset } = form;@@ -338,7 +350,8 @@ export const KnowledgeForm = ({ initialValues, isNew, knowledge, knowledgeName,><KnowledgeHeaderisNew={isNew}- knowledgeName={knowledgeName}+ knowledge={knowledge}+ onBeforeNavigateAway={() => skipNextBlockRef.current()}saveButton={saveButton}/>{isDesktop ? (diff --git a/frontend/src/features/knowledges/knowledge-header.tsx b/frontend/src/features/knowledges/knowledge-header.tsxindex c90b8651..c1e5d7c6 100644--- a/frontend/src/features/knowledges/knowledge-header.tsx+++ b/frontend/src/features/knowledges/knowledge-header.tsx@@ -1,34 +1,282 @@import type { ReactNode } from 'react';-import { LibraryBig } from 'lucide-react';+import { Check, Ellipsis, LibraryBig, Loader2, Pencil, Trash, X } from 'lucide-react';+import { useCallback, useEffect, useRef, useState } from 'react';+import { useNavigate } from 'react-router-dom';+import { toast } from 'sonner';+import type { KnowledgeDocumentFragmentFragment } from '@/graphql/types';++import ConfirmationDialog from '@/components/shared/confirmation-dialog';import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from '@/components/ui/breadcrumb';+import { Button } from '@/components/ui/button';+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from '@/components/ui/dropdown-menu';+import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';import { Separator } from '@/components/ui/separator';import { SidebarTrigger } from '@/components/ui/sidebar';+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';+import { useKnowledges } from '@/providers/knowledges-provider';interface KnowledgeHeaderProps {isNew: boolean;- knowledgeName: null | string;+ knowledge?: KnowledgeDocumentFragmentFragment | null;+ /**+ * Optional hook called right before the header navigates away after a+ * successful delete. The form mounts this header inside an unsaved-changes+ * guard, so it passes `skipNextBlock` here to suppress the "Save before+ * leaving?" dialog — there is nothing to save once the document is gone.+ */+ onBeforeNavigateAway?: () => void;saveButton?: ReactNode;}-export const KnowledgeHeader = ({ isNew, knowledgeName, saveButton }: KnowledgeHeaderProps) => (- <header className="bg-background sticky top-0 z-10 flex h-12 shrink-0 items-center gap-2 border-b px-4">- <SidebarTrigger className="-ml-1" />- <Separator- className="mr-2 h-4"- orientation="vertical"- />- <Breadcrumb>- <BreadcrumbList>- <BreadcrumbItem>- <LibraryBig className="size-4 shrink-0" />- <BreadcrumbPage className="max-w-[240px] truncate">- {isNew ? 'New knowledge' : (knowledgeName ?? 'Knowledge')}- </BreadcrumbPage>- </BreadcrumbItem>- </BreadcrumbList>- </Breadcrumb>- {saveButton ? <div className="ml-auto flex items-center gap-2">{saveButton}</div> : null}- </header>-);+export const KnowledgeHeader = ({ isNew, knowledge, onBeforeNavigateAway, saveButton }: KnowledgeHeaderProps) => {+ const navigate = useNavigate();+ const { deleteKnowledge, updateKnowledge } = useKnowledges();+ const [isEditingTitle, setIsEditingTitle] = useState(false);+ const [isRenaming, setIsRenaming] = useState(false);+ const [isDeleting, setIsDeleting] = useState(false);+ const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);+ const editingInputRef = useRef<HTMLInputElement>(null);++ const knowledgeId = knowledge?.id ?? null;+ // Title source-of-truth is the server-side `question`. We intentionally do+ // not read it from the form draft below — the inline rename flow in this+ // header writes through `updateKnowledge`, which refreshes `knowledge` via+ // the cache, and the form picks up the new value separately.+ const knowledgeName = knowledge?.question ?? null;+ const canShowActions = !isNew && !!knowledge;++ // Reset inline-edit state when navigating between documents so the input+ // doesn't carry over a stale draft from a previous document.+ useEffect(() => {+ setIsEditingTitle(false);+ }, [knowledgeId]);++ // Focus and select the rename input when the inline editor opens. We can't+ // rely on `autoFocus` here: the input mounts inside the same render cycle+ // that closes the Radix DropdownMenu, and the dropdown's own focus restore+ // (scheduled via `requestAnimationFrame`) wins the race against React's+ // autoFocus effect. Defer our focus to the next frame so it lands *after*+ // Radix has finished its restore.+ useEffect(() => {+ if (!isEditingTitle) {+ return;+ }++ const id = requestAnimationFrame(() => {+ const input = editingInputRef.current;++ if (!input) {+ return;+ }++ input.focus();+ input.select();+ });++ return () => cancelAnimationFrame(id);+ }, [isEditingTitle]);++ const handleRenameStart = useCallback(() => {+ setIsEditingTitle(true);+ }, []);++ const handleRenameCancel = useCallback(() => {+ setIsEditingTitle(false);+ }, []);++ const handleRenameSave = useCallback(async () => {+ const newQuestion = editingInputRef.current?.value.trim();++ if (!knowledge || !newQuestion) {+ return;+ }++ if (newQuestion === knowledge.question) {+ setIsEditingTitle(false);++ return;+ }++ setIsRenaming(true);++ try {+ // Backend requires `content` on update (always re-embeds). We pass+ // the server's current `content` so an inline rename never+ // accidentally overwrites unsaved edits made in the form below.+ // The sibling form picks up the new `question` automatically via+ // `useForm({ values })` — no manual sync needed here.+ await updateKnowledge(knowledge.id, {+ content: knowledge.content,+ question: newQuestion,+ });+ toast.success('Knowledge renamed successfully');+ setIsEditingTitle(false);+ } catch {+ // Error already handled in provider with toast+ } finally {+ setIsRenaming(false);+ }+ }, [knowledge, updateKnowledge]);++ const handleDelete = useCallback(async () => {+ if (!knowledgeId) {+ return;+ }++ setIsDeleting(true);++ try {+ await deleteKnowledge(knowledgeId);+ onBeforeNavigateAway?.();+ navigate('/knowledges', { replace: true });+ } catch {+ // Error already handled in provider with toast+ } finally {+ setIsDeleting(false);+ }+ }, [knowledgeId, deleteKnowledge, navigate, onBeforeNavigateAway]);++ return (+ <>+ <header className="bg-background sticky top-0 z-10 flex h-12 shrink-0 items-center gap-2 border-b px-4">+ <SidebarTrigger className="-ml-1" />+ <Separator+ className="mr-2 h-4"+ orientation="vertical"+ />+ <Breadcrumb>+ <BreadcrumbList>+ <BreadcrumbItem className="gap-2">+ <LibraryBig className="size-4 shrink-0" />+ {isEditingTitle && canShowActions ? (+ <InputGroup className="h-8 w-64 max-w-full">+ <InputGroupInput+ className="text-foreground"+ defaultValue={knowledgeName ?? ''}+ onKeyDown={(event) => {+ if (event.key === 'Enter') {+ event.preventDefault();+ handleRenameSave();++ return;+ }++ if (event.key === 'Escape') {+ event.preventDefault();+ handleRenameCancel();+ }+ }}+ placeholder="Knowledge question"+ ref={editingInputRef}+ />+ <InputGroupAddon+ align="inline-end"+ className="gap-0 pr-2"+ >+ <InputGroupButton+ aria-label="Save"+ disabled={isRenaming}+ onClick={() => handleRenameSave()}+ >+ {isRenaming ? <Loader2 className="animate-spin" /> : <Check />}+ </InputGroupButton>+ <InputGroupButton+ aria-label="Cancel"+ onClick={() => handleRenameCancel()}+ >+ <X />+ </InputGroupButton>+ </InputGroupAddon>+ </InputGroup>+ ) : canShowActions ? (+ <Tooltip>+ <TooltipTrigger asChild>+ <BreadcrumbPage+ className="max-w-[240px] cursor-text truncate select-none"+ onDoubleClick={handleRenameStart}+ >+ {knowledgeName ?? 'Knowledge'}+ </BreadcrumbPage>+ </TooltipTrigger>+ <TooltipContent>Double-click to rename</TooltipContent>+ </Tooltip>+ ) : (+ <BreadcrumbPage className="max-w-[240px] truncate">+ {isNew ? 'New knowledge' : (knowledgeName ?? 'Knowledge')}+ </BreadcrumbPage>+ )}+ </BreadcrumbItem>+ </BreadcrumbList>+ </Breadcrumb>+ <div className="ml-auto flex items-center gap-2">+ {saveButton}+ {canShowActions && (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ aria-label="Knowledge actions"+ className="size-8 p-0"+ type="button"+ variant="ghost"+ >+ <Ellipsis />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent+ align="end"+ className="min-w-24"+ onCloseAutoFocus={(event) => {+ // Radix returns focus to the trigger on close. When the+ // selected action mounts the rename input, prevent that+ // restore so our deferred focus actually wins.+ if (isEditingTitle) {+ event.preventDefault();+ }+ }}+ >+ <DropdownMenuItem onClick={handleRenameStart}>+ <Pencil className="size-3" />+ Rename+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ disabled={isDeleting}+ onClick={() => setIsDeleteDialogOpen(true)}+ >+ {isDeleting ? (+ <>+ <Loader2 className="size-4 animate-spin" />+ Deleting...+ </>+ ) : (+ <>+ <Trash className="size-4" />+ Delete+ </>+ )}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ </div>+ </header>+ <ConfirmationDialog+ cancelText="Cancel"+ confirmText="Delete"+ handleConfirm={handleDelete}+ handleOpenChange={setIsDeleteDialogOpen}+ isOpen={isDeleteDialogOpen}+ itemName={knowledgeName ?? undefined}+ itemType="knowledge document"+ />+ </>+ );+};diff --git a/frontend/src/features/knowledges/knowledge-layout.tsx b/frontend/src/features/knowledges/knowledge-layout.tsxindex 0782aab4..7dca602a 100644--- a/frontend/src/features/knowledges/knowledge-layout.tsx+++ b/frontend/src/features/knowledges/knowledge-layout.tsx@@ -1,5 +1,7 @@import type { ReactNode } from 'react';+import type { KnowledgeDocumentFragmentFragment } from '@/graphql/types';+import { cn } from '@/lib/utils';import { KnowledgeHeader } from './knowledge-header';@@ -8,7 +10,7 @@ interface KnowledgeLayoutProps {children: ReactNode;className?: string;isNew: boolean;- knowledgeName: null | string;+ knowledge?: KnowledgeDocumentFragmentFragment | null;saveButton?: ReactNode;}@@ -18,11 +20,11 @@ interface KnowledgeLayoutProps {* renders the header inline because the form must be the parent of every* input.*/-export const KnowledgeLayout = ({ children, className, isNew, knowledgeName, saveButton }: KnowledgeLayoutProps) => (+export const KnowledgeLayout = ({ children, className, isNew, knowledge, saveButton }: KnowledgeLayoutProps) => (<div className={cn('flex min-h-[100dvh] flex-col', className)}><KnowledgeHeaderisNew={isNew}- knowledgeName={knowledgeName}+ knowledge={knowledge}saveButton={saveButton}/>{children}diff --git a/frontend/src/pages/knowledges/knowledge.tsx b/frontend/src/pages/knowledges/knowledge.tsxindex 6d68fce9..897f2c7b 100644--- a/frontend/src/pages/knowledges/knowledge.tsx+++ b/frontend/src/pages/knowledges/knowledge.tsx@@ -32,7 +32,6 @@ const Knowledge = () => {});const knowledge = data?.knowledgeDocument ?? null;- const knowledgeName = knowledge?.question ?? null;const initialValues = useMemo<FormValues>(() => (knowledge ? documentToFormValues(knowledge) : newDocumentDefaults),@@ -70,7 +69,7 @@ const Knowledge = () => {return (<KnowledgeLayoutisNew={false}- knowledgeName={knowledgeName}+ knowledge={knowledge}><div className="flex flex-1 items-center justify-center"><Spinner variant="circle" />@@ -83,7 +82,7 @@ const Knowledge = () => {return (<KnowledgeLayoutisNew={false}- knowledgeName={knowledgeName}+ knowledge={knowledge}><div className="flex flex-1 items-center justify-center p-4"><Card className="w-full max-w-2xl">@@ -106,7 +105,6 @@ const Knowledge = () => {isNew={isNew}key={knowledgeId ?? 'new'}knowledge={knowledge}- knowledgeName={knowledgeName}onSubmit={handleSubmit}/>);diff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsxindex 0730fd31..a6bcdace 100644--- a/frontend/src/pages/knowledges/knowledges.tsx+++ b/frontend/src/pages/knowledges/knowledges.tsx@@ -1,8 +1,21 @@import type { ColumnDef } from '@tanstack/react-table';-import { ArrowDown, ArrowUp, Ellipsis, LibraryBig, Loader2, Pencil, Plus, Trash } from 'lucide-react';-import { useState } from 'react';+import {+ ArrowDown,+ ArrowUp,+ Check,+ Ellipsis,+ LibraryBig,+ Loader2,+ Pencil,+ PencilLine,+ Plus,+ Trash,+ X,+} from 'lucide-react';+import { useCallback, useRef, useState } from 'react';import { useNavigate } from 'react-router-dom';+import { toast } from 'sonner';import type { BadgeVariant } from '@/components/ui/badge';@@ -17,8 +30,10 @@ import {DropdownMenu,DropdownMenuContent,DropdownMenuItem,+ DropdownMenuSeparator,DropdownMenuTrigger,} from '@/components/ui/dropdown-menu';+import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';import { Separator } from '@/components/ui/separator';import { SidebarTrigger } from '@/components/ui/sidebar';import { StatusCard } from '@/components/ui/status-card';@@ -50,19 +65,70 @@ const docTypeSubtype = (k: Knowledge): null | string => {const Knowledges = () => {const navigate = useNavigate();- const { deleteKnowledge, isLoading, knowledges } = useKnowledges();+ const { deleteKnowledge, isLoading, knowledges, updateKnowledge } = useKnowledges();const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);const [deletingKnowledge, setDeletingKnowledge] = useState<Knowledge | null>(null);const [deletingIds, setDeletingIds] = useState<Set<string>>(new Set());+ const [editingKnowledgeId, setEditingKnowledgeId] = useState<null | string>(null);+ const [isRenameLoading, setIsRenameLoading] = useState(false);+ const editingInputRef = useRef<HTMLInputElement>(null);- const handleOpen = (id: string) => {- navigate(`/knowledges/${id}`);- };+ const handleOpen = useCallback(+ (id: string) => {+ navigate(`/knowledges/${id}`);+ },+ [navigate],+ );- const handleDeleteDialogOpen = (knowledge: Knowledge) => {+ const handleDeleteDialogOpen = useCallback((knowledge: Knowledge) => {setDeletingKnowledge(knowledge);setIsDeleteDialogOpen(true);- };+ }, []);++ const handleKnowledgeRenameStart = useCallback((knowledge: Knowledge) => {+ setEditingKnowledgeId(knowledge.id);+ }, []);++ const handleKnowledgeRenameCancel = useCallback(() => {+ setEditingKnowledgeId(null);+ }, []);++ const handleKnowledgeRenameSave = useCallback(async () => {+ const newQuestion = editingInputRef.current?.value.trim();++ if (!editingKnowledgeId || !newQuestion) {+ return;+ }++ const knowledge = knowledges.find((k) => k.id === editingKnowledgeId);++ if (!knowledge) {+ return;+ }++ if (newQuestion === knowledge.question) {+ setEditingKnowledgeId(null);++ return;+ }++ setIsRenameLoading(true);++ try {+ // Backend requires `content` on update (it always re-embeds), so we+ // pass it through unchanged from the cached document.+ await updateKnowledge(editingKnowledgeId, {+ content: knowledge.content,+ question: newQuestion,+ });+ toast.success('Knowledge renamed successfully');+ setEditingKnowledgeId(null);+ } catch {+ // Error already handled in provider with toast+ } finally {+ setIsRenameLoading(false);+ }+ }, [editingKnowledgeId, knowledges, updateKnowledge]);const handleDelete = async () => {if (!deletingKnowledge) {@@ -137,8 +203,57 @@ const Knowledges = () => {{accessorKey: 'question',cell: ({ row }) => {+ const knowledge = row.original;+ const isEditing = editingKnowledgeId === knowledge.id;const question = row.getValue('question') as string;+ if (isEditing) {+ return (+ <InputGroup+ className="h-8"+ onClick={(e) => e.stopPropagation()}+ >+ <InputGroupInput+ autoFocus+ defaultValue={question}+ onKeyDown={(e) => {+ if (e.key === 'Enter') {+ e.preventDefault();+ handleKnowledgeRenameSave();++ return;+ }++ if (e.key === 'Escape') {+ e.preventDefault();+ handleKnowledgeRenameCancel();+ }+ }}+ placeholder="Knowledge question"+ ref={editingInputRef}+ />+ <InputGroupAddon+ align="inline-end"+ className="gap-0 pr-2"+ >+ <InputGroupButton+ aria-label="Save"+ disabled={isRenameLoading}+ onClick={() => handleKnowledgeRenameSave()}+ >+ {isRenameLoading ? <Loader2 className="animate-spin" /> : <Check />}+ </InputGroupButton>+ <InputGroupButton+ aria-label="Cancel"+ onClick={() => handleKnowledgeRenameCancel()}+ >+ <X />+ </InputGroupButton>+ </InputGroupAddon>+ </InputGroup>+ );+ }+return (<divclassName="truncate font-medium"@@ -246,6 +361,11 @@ const Knowledges = () => {<Pencil />Edit</DropdownMenuItem>+ <DropdownMenuItem onClick={() => handleKnowledgeRenameStart(k)}>+ <PencilLine />+ Rename+ </DropdownMenuItem>+ <DropdownMenuSeparator /><DropdownMenuItemdisabled={deletingIds.has(k.id)}onClick={() => handleDeleteDialogOpen(k)}@@ -283,6 +403,10 @@ const Knowledges = () => {<Pencil />Edit</ContextMenuItem>+ <ContextMenuItem onClick={() => handleKnowledgeRenameStart(k)}>+ <PencilLine />+ Rename+ </ContextMenuItem><ContextMenuSeparator /><ContextMenuItemdisabled={deletingIds.has(k.id)}@@ -370,7 +494,11 @@ const Knowledges = () => {data={knowledges}filterColumn="question"filterPlaceholder="Filter knowledge documents..."- onRowClick={(k) => handleOpen(k.id)}+ onRowClick={(k) => {+ if (editingKnowledgeId !== k.id) {+ handleOpen(k.id);+ }+ }}renderRowContextMenu={renderRowContextMenu}/>