Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

feat(frontend): add collapsible InputSearch, wire it to ?qs= on knowledges

Sergey Kozyrenko31a7f34c0f20
diff --git a/frontend/package.json b/frontend/package.json
index b362c891..862af285 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -71,6 +71,7 @@
"lucide-react": "^1.16.0",
"marked": "^18.0.3",
"monaco-editor": "^0.55.1",
+ "motion": "^12.39.0",
"react": "^19.2.6",
"react-day-picker": "^10.0.1",
"react-diff-viewer-continued": "^4.2.2",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 4794ec66..ca0c64af 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -167,6 +167,9 @@ importers:
monaco-editor:
specifier: ^0.55.1
version: 0.55.1
+ motion:
+ specifier: ^12.39.0
react:
specifier: ^19.2.6
version: 19.2.6
@@ -3696,6 +3699,20 @@ packages:
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
engines: {node: '>=12.20.0'}
+ resolution: {integrity: sha512-+vnLfzrv0MzjLzNl+nvNvR7jdg3q4cxxjz/YvzfifHl0TREtL00cs1RoMTxs+1PzLiEqZGV6gYsBY0oEAYZ24w==}
+ peerDependencies:
+ '@emotion/is-prop-valid': '*'
+ react: ^18.0.0 || ^19.0.0
+ react-dom: ^18.0.0 || ^19.0.0
+ peerDependenciesMeta:
+ '@emotion/is-prop-valid':
+ optional: true
+ react:
+ optional: true
+ react-dom:
+ optional: true
+
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
engines: {node: '>=12'}
@@ -4650,6 +4667,26 @@ packages:
resolution: {integrity: sha512-jz4x+TJNFHwHtwuV9vA9rMujcZRb0CEilTEwG2rRSpe/A7Jdkuj8xPKttCgOh+v/lkHy7HsZ64oj+q3xoAFl9A==}
+ resolution: {integrity: sha512-Xn7aAcGDhco/JZTXOub64UmaYn73C6J1Po7Fk+8EvkJsNGTqfhon6UJY53vJKXW5v5Zl8HrYsVxv6oPXeGoGLQ==}
+
+ resolution: {integrity: sha512-8nadJAJjTtqRkmRF36FoJTrywK9nnFmnPwnSMyxaOCU7GDjN9RTMJIxx9De8ErM+vpPhMccr/6fo5WciyQLnMQ==}
+
+ resolution: {integrity: sha512-H4a+Ze+a9j+/NTla5ezfb/g9vmIOxC+viDj++NGDZyTZkdRKjiOz3kSv6TalRWM8ZmD2y/CfC6TkQc97ybyqSA==}
+ peerDependencies:
+ '@emotion/is-prop-valid': '*'
+ react: ^18.0.0 || ^19.0.0
+ react-dom: ^18.0.0 || ^19.0.0
+ peerDependenciesMeta:
+ '@emotion/is-prop-valid':
+ optional: true
+ react:
+ optional: true
+ react-dom:
+ optional: true
+
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
@@ -9645,6 +9682,15 @@ snapshots:
dependencies:
fetch-blob: 3.2.0
+ dependencies:
+ motion-dom: 12.39.0
+ motion-utils: 12.39.0
+ tslib: 2.8.1
+ optionalDependencies:
+ react: 19.2.6
+ react-dom: 19.2.6([email protected])
+
dependencies:
graceful-fs: 4.2.11
@@ -10836,6 +10882,20 @@ snapshots:
dompurify: 3.2.7
marked: 14.0.0
+ dependencies:
+ motion-utils: 12.39.0
+
+
+ dependencies:
+ tslib: 2.8.1
+ optionalDependencies:
+ react: 19.2.6
+ react-dom: 19.2.6([email protected])
+
diff --git a/frontend/src/components/ui/input-search.tsx b/frontend/src/components/ui/input-search.tsx
new file mode 100644
index 00000000..17240e90
--- /dev/null
+++ b/frontend/src/components/ui/input-search.tsx
@@ -0,0 +1,194 @@
+import { Search } from 'lucide-react';
+import { motion } from 'motion/react';
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';
+import { cn } from '@/lib/utils';
+
+interface InputSearchProps {
+ /** Accessible label for the trigger button + the input. */
+ ariaLabel?: string;
+ className?: string;
+ /**
+ * Lowercase character that, combined with the platform modifier (⌘ on
+ * macOS, Ctrl elsewhere), expands and focuses the input from anywhere on
+ * the page. Pass `null` to disable the global hotkey entirely — useful on
+ * pages that should not steal the browser's own bindings. Default `'f'`.
+ */
+ hotkey?: null | string;
+ /**
+ * Width (px or any CSS length) the input grows to once expanded. The
+ * collapsed state is always just the icon. Default `140`.
+ */
+ maxWidth?: number | string;
+ onSearchChange: (value: string) => void;
+ placeholder?: string;
+ searchQuery: string;
+}
+
+/**
+ * Collapsible search input. Idle state shows only a `<Search>` icon button;
+ * clicking it (or pressing the configured hotkey) expands a controlled text
+ * input with a smooth width animation. Blurring an empty input collapses it
+ * back. Escape clears the value, a second Escape collapses + blurs.
+ *
+ * The trigger is a real `<button>` (via `InputGroupButton`) — never a `<div>`
+ * with `onClick` — so the control is reachable with Tab and announced by
+ * screen readers. The input lives outside that button, so we don't nest
+ * interactive elements (an `<input>` inside a `<button>` is invalid HTML).
+ *
+ * The component is controlled — parent owns `searchQuery` and reacts to
+ * `onSearchChange`. The only local state is the expand/collapse presentation
+ * flag; the initial value mirrors whether the controlled query is non-empty,
+ * so deep-linking to `?qs=foo` lands directly in the expanded state.
+ */
+export function InputSearch({
+ ariaLabel = 'Search',
+ className,
+ hotkey = 'f',
+ maxWidth = 140,
+ onSearchChange,
+ placeholder = 'Search...',
+ searchQuery,
+}: InputSearchProps) {
+ // Initialise expanded if the parent already has a non-empty query: a
+ // shared link with `?qs=foo` should land expanded, not behind the icon.
+ const [isExpanded, setIsExpanded] = useState(() => searchQuery.trim().length > 0);
+ const inputRef = useRef<HTMLInputElement>(null);
+
+ const expand = useCallback(() => setIsExpanded(true), []);
+
+ // Focus the input the frame after it appears. `rAF` defers past the same
+ // commit so motion's transform has started, otherwise focus can land on
+ // a still-zero-width box and the user's caret blinks invisibly until the
+ // animation completes.
+ useEffect(() => {
+ if (!isExpanded) {
+ return;
+ }
+
+ const id = requestAnimationFrame(() => inputRef.current?.focus());
+
+ return () => cancelAnimationFrame(id);
+ }, [isExpanded]);
+
+ // Global hotkey: Mod+<hotkey> from anywhere on the page. We hijack the
+ // browser default (e.g. Ctrl+F's "find in page") only for the exact
+ // configured key — pass `null` to opt out entirely.
+ useEffect(() => {
+ if (!hotkey) {
+ return;
+ }
+
+ const normalized = hotkey.toLowerCase();
+
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (!(event.metaKey || event.ctrlKey)) {
+ return;
+ }
+
+ if (event.key.toLowerCase() !== normalized) {
+ return;
+ }
+
+ event.preventDefault();
+ expand();
+ };
+
+ document.addEventListener('keydown', handleKeyDown);
+
+ return () => document.removeEventListener('keydown', handleKeyDown);
+ }, [expand, hotkey]);
+
+ // Collapse the moment the query becomes empty and the input has lost
+ // focus — covers both user-driven blur and programmatic clears (e.g. the
+ // URL `?qs=` dropping out from under us). One effect, no duplication.
+ useEffect(() => {
+ if (searchQuery.trim().length > 0) {
+ return;
+ }
+
+ if (document.activeElement !== inputRef.current) {
+ setIsExpanded(false);
+ }
+ }, [searchQuery]);
+
+ // Escape: first press clears the value, second press collapses + blurs.
+ // This matches the muscle memory of native search controls and keeps the
+ // keyboard a viable exit path for users who never reach for the mouse.
+ const handleInputKeyDown = useCallback(
+ (event: React.KeyboardEvent<HTMLInputElement>) => {
+ if (event.key !== 'Escape') {
+ return;
+ }
+
+ event.preventDefault();
+
+ if (searchQuery.length > 0) {
+ onSearchChange('');
+
+ return;
+ }
+
+ inputRef.current?.blur();
+ setIsExpanded(false);
+ },
+ [onSearchChange, searchQuery],
+ );
+
+ return (
+ <InputGroup
+ className={cn(
+ 'h-7 w-auto shrink-0 py-1 transition-[background-color,border-color,box-shadow] duration-100',
+ isExpanded
+ ? 'border-input dark:bg-input/30 shadow-xs'
+ : 'border-transparent shadow-none dark:bg-transparent',
+ className,
+ )}
+ >
+ <InputGroupAddon
+ align="inline-start"
+ className={cn(!isExpanded && 'mr-1.5 -ml-1.5')}
+ >
+ {isExpanded ? (
+ <Search
+ aria-hidden="true"
+ className="text-muted-foreground"
+ />
+ ) : (
+ <InputGroupButton
+ aria-label={ariaLabel}
+ className="text-foreground -mx-1.5 size-7"
+ onClick={expand}
+ size="icon-xs"
+ type="button"
+ variant="ghost"
+ >
+ <Search aria-hidden="true" />
+ </InputGroupButton>
+ )}
+ </InputGroupAddon>
+ <motion.div
+ animate={{
+ opacity: isExpanded ? 1 : 0,
+ width: isExpanded ? maxWidth : 0,
+ }}
+ className="overflow-hidden"
+ initial={false}
+ transition={{ duration: 0.1, ease: 'easeOut' }}
+ >
+ <InputGroupInput
+ aria-label={ariaLabel}
+ className="min-w-0 py-0 pl-2"
+ onChange={(event) => onSearchChange(event.target.value)}
+ onKeyDown={handleInputKeyDown}
+ placeholder={placeholder}
+ ref={inputRef}
+ style={{ width: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth }}
+ type="text"
+ value={searchQuery}
+ />
+ </motion.div>
+ </InputGroup>
+ );
+}
diff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsx
index 308707ac..969b3224 100644
--- a/frontend/src/pages/knowledges/knowledges.tsx
+++ b/frontend/src/pages/knowledges/knowledges.tsx
@@ -22,6 +22,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
+import { InputSearch } from '@/components/ui/input-search';
import { Separator } from '@/components/ui/separator';
import { SidebarTrigger } from '@/components/ui/sidebar';
import { StatusCard } from '@/components/ui/status-card';
@@ -69,11 +70,43 @@ function Knowledges() {
// silently narrow the result set behind the user's back.
// `useTableState` reads `skipRestore` once at mount via a ref, so a
// later toggle (user clears `?qs=`) won't replay the restore.
- const [initialParams] = useSearchParams();
+ const [searchParams, setSearchParams] = useSearchParams();
const { filter, setFilter } = useTableState({
- skipRestore: initialParams.has(URL_PARAMS.SEARCH),
+ skipRestore: searchParams.has(URL_PARAMS.SEARCH),
});
+ // Source-of-truth for the semantic-search input is the URL. The
+ // `KnowledgesProvider` reads the same `?qs=` and debounces it before
+ // hitting `searchKnowledge`, so we keep the input's `value` un-debounced
+ // here — the user gets instant feedback in the box, the network only
+ // fires after 400 ms of inactivity.
+ const semanticQuery = searchParams.get(URL_PARAMS.SEARCH) ?? '';
+ const handleSemanticQueryChange = useCallback(
+ (value: string) => {
+ setSearchParams(
+ (prev) => {
+ const next = new URLSearchParams(prev);
+
+ if (value.trim().length === 0) {
+ // Drop the param entirely so the URL stays canonical
+ // (`/knowledges`, not `/knowledges?qs=`) — list-mode
+ // and the cache key both prefer the absent form.
+ next.delete(URL_PARAMS.SEARCH);
+ } else {
+ next.set(URL_PARAMS.SEARCH, value);
+ }
+
+ return next;
+ },
+ // Replace so typing keystrokes don't pile up in the history
+ // stack — each char would otherwise be its own back-button
+ // stop. Same convention as `useTableState` uses for `?q=`.
+ { replace: true },
+ );
+ },
+ [setSearchParams],
+ );
+
const handleOpen = useCallback(
(id: string) => {
navigate(mergeHrefWithSearchParams(`/knowledges/${id}`, new URLSearchParams(location.search)));
@@ -390,6 +423,18 @@ function Knowledges() {
</Breadcrumb>
</div>
<div className="flex shrink-0 items-center gap-2 px-4">
+ <InputSearch
+ ariaLabel="Search knowledge documents"
+ // Use Mod+K — Mod+F is reserved as the page-wide default
+ // because we don't want to conflict with the browser's
+ // own find-in-page on every screen, but this list is one
+ // of the few that benefits from a dedicated shortcut.
+ hotkey="k"
+ maxWidth={220}
+ onSearchChange={handleSemanticQueryChange}
+ placeholder="Semantic search..."
+ searchQuery={semanticQuery}
+ />
<HeaderButton
icon={<Plus />}
label="New Knowledge"