Merge main and preserve task navigation with severity filtering

This commit is contained in:
ji ruo committed 2026-10-26 09:39:58 +08:00
commit 19a3dc65d8
53 files changed
+3973 -304

No files matched your search

@@ -58,6 +58,7 @@ function FindingDetailInner() {
const searchParams = useSearchParams();
const id = searchParams.get("id") ?? "";
const contextTaskId = searchParams.get("context_task") ?? "";
const backHref = contextTaskId ? `/function/tasks/detail?id=${contextTaskId}&tab=findings` : "/function/findings";
const [finding, setFinding] = React.useState<Finding | null>(null);
const [loaded, setLoaded] = React.useState(false);
const [tab, setTab] = React.useState("overview");
@@ -117,7 +118,7 @@ function FindingDetailInner() {
<p className="text-muted-foreground">{loaded ? `未找到发现 ${id}` : "加载中…"}</p>
{loaded && (
<Button asChild variant="outline">
<Link href="/function/findings">
<Link href={backHref}>
<ArrowLeftIcon /> 返回发现列表
</Link>
</Button>
@@ -135,7 +136,7 @@ function FindingDetailInner() {
<div className="flex flex-wrap items-center gap-2">
<SidebarTrigger className="-ml-1" />
<Button asChild variant="ghost" size="icon" className="size-7">
<Link href="/function/findings">
<Link href={backHref}>
<ArrowLeftIcon />
</Link>
</Button>
@@ -115,11 +115,7 @@ function Row({
</span>
{f.finding_id && (
<Link
href={
f.inherited
? `/function/findings/detail?id=${f.finding_id}&context_task=${contextTaskId}`
: `/function/findings/detail?id=${f.finding_id}`
}
href={`/function/findings/detail?id=${f.finding_id}&context_task=${contextTaskId}`}
className="text-muted-foreground hover:text-primary inline-flex shrink-0 items-center gap-0.5 text-xs"
title="查看漏洞详情"
>
@@ -205,6 +201,7 @@ export function FindingsTab({ taskId }: { taskId: string }) {
</ToggleGroup>
<FindingCaseList
query={{ task: taskId, severity: severity === "all" ? undefined : severity, sort: "severity" }}
contextTask={taskId}
/>
{[
...new Set(
@@ -354,7 +354,17 @@ function TaskDetailInner() {
);
return (
<Tabs value={tab} onValueChange={setTab} className="flex flex-1 flex-col gap-0">
<Tabs
value={tab}
onValueChange={(value) => {
setTab(value);
const params = new URLSearchParams(searchParams.toString());
params.set("tab", value);
params.delete("session");
router.replace(`/function/tasks/detail?${params.toString()}`, { scroll: false });
}}
className="flex flex-1 flex-col gap-0"
>
{/* Top fixed area */}
<header className="sticky top-0 z-10 flex flex-col gap-2 border-b bg-background/95 px-4 py-2.5 backdrop-blur lg:px-6">
<div className="flex items-center gap-2">
@@ -404,6 +414,11 @@ function TaskDetailInner() {
</Button>
</div>
<p className="truncate text-xs text-muted-foreground">{task.goal}</p>
{task.remark ? (
<p className="truncate text-xs text-muted-foreground" title={task.remark}>
备注:{task.remark}
</p>
) : null}
{/* Tabs */}
<div className="no-scrollbar min-w-0 overflow-x-auto">
<TabsList variant="default" className="min-w-max">
+45 -1
View File
@@ -137,6 +137,7 @@ import type {
TaskCategory,
TaskStatus,
} from "@/lib/types";
import { MAX_TASK_REMARK_RUNES, MAX_TASK_WORKER_COUNT, parseWorkerCountInput } from "@/lib/types";
import { cn } from "@/lib/utils";
// fmtBytes renders a human file size for the upload manifest.
@@ -3104,6 +3105,7 @@ function CreateTaskSheet({
}) {
const [open, setOpen] = React.useState(false);
const [name, setName] = React.useState("");
const [remark, setRemark] = React.useState("");
const [categoryID, setCategoryID] = React.useState<number | undefined>(undefined);
const [description, setDescription] = React.useState("");
const [goal, setGoal] = React.useState("");
@@ -3118,6 +3120,7 @@ function CreateTaskSheet({
const [heartbeatMin, setHeartbeatMin] = React.useState("10"); // planner 心跳(分钟);默认10,下限10(与后端一致)
const [seedFirstIntent, setSeedFirstIntent] = React.useState(false); // 创建时下发种子意图,worker 免等首轮 planner 直接开跑;默认关闭,走标准先规划再执行
const [coverageEnabled, setCoverageEnabled] = React.useState(true); // 资产覆盖度功能;默认开。关闭=不计算/展示覆盖度、不累积范围、隐藏范围类工具(company 关联不受影响)
const [workerCount, setWorkerCount] = React.useState(""); // 本任务 Worker 数;空/0=用全局默认
const [interceptRules, setInterceptRules] = React.useState<AssetInterceptRuleInput[]>([]); // 任务级资产拦截规则(仅本任务生效,不进全局表)
const [scheduleEnabled, setScheduleEnabled] = React.useState(false);
const [schedule, setSchedule] = React.useState<ScheduleInput>({
@@ -3181,12 +3184,18 @@ function CreateTaskSheet({
toast.error(`最多关联 ${MAX_SOURCE_TASKS} 个来源任务`);
return;
}
const workerCountNum = parseWorkerCountInput(workerCount);
if (workerCountNum == null) {
toast.error(`Worker 运行数量必须是 0-${MAX_TASK_WORKER_COUNT} 的整数`);
return;
}
setCreating(true);
try {
const timeoutSec = Math.max(0, Math.floor(Number(timeoutMin) || 0)) * 60;
const heartbeatSec = Math.max(10, Math.floor(Number(heartbeatMin) || 10)) * 60; // 下限 10min,与后端归一一致
await api.createTask({
name: name.trim(),
remark: remark.trim(),
categoryId: categoryID,
description: description.trim(),
goal: goal.trim(),
@@ -3197,6 +3206,7 @@ function CreateTaskSheet({
seedFirstIntent,
planHeartbeatSeconds: heartbeatSec,
coverageEnabled,
workerCount: workerCountNum,
schedule: scheduleEnabled ? { ...schedule, task_ids: [] } : undefined,
interceptRules: interceptRules
.map((r) => ({ ...r, pattern: r.pattern.trim() }))
@@ -3204,6 +3214,7 @@ function CreateTaskSheet({
});
toast.success("任务已创建");
setName("");
setRemark("");
setCategoryID(undefined);
setDescription("");
setGoal("");
@@ -3215,6 +3226,7 @@ function CreateTaskSheet({
setHeartbeatMin("10");
setSeedFirstIntent(false);
setCoverageEnabled(true);
setWorkerCount("");
setInterceptRules([]);
setScheduleEnabled(false);
setSchedule({
@@ -3263,15 +3275,19 @@ function CreateTaskSheet({
<TaskTemplateControls
description={description}
goal={goal}
remark={remark}
categoryID={categoryID}
interceptRules={interceptRules}
workerCount={workerCount}
selectedTemplateID={selectedTemplateID}
onSelectedTemplateIDChange={setSelectedTemplateID}
onApply={(template) => {
setDescription(template.description);
setGoal(template.goal);
setRemark(template.remark ?? "");
setCategoryID(template.category_id ?? undefined);
setInterceptRules(template.intercept_rules ?? []);
setWorkerCount(template.worker_count ? String(template.worker_count) : "");
setUploadCount(0);
}}
portalContainer={sheetContentRef}
@@ -3285,6 +3301,17 @@ function CreateTaskSheet({
onChange={(e) => setName(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="remark">备注(可选)</Label>
<Textarea
id="remark"
className="min-h-20"
maxLength={MAX_TASK_REMARK_RUNES}
placeholder="补充说明、环境信息等,便于在任务列表识别"
value={remark}
onChange={(e) => setRemark(e.target.value)}
/>
</div>
<Field>
<FieldLabel htmlFor="task-category">任务分类</FieldLabel>
<CategoryPicker
@@ -3507,7 +3534,7 @@ function CreateTaskSheet({
<CollapsibleTrigger className="group flex w-full items-center gap-2 border-t pt-4 text-sm font-medium">
<ChevronRightIcon className="text-muted-foreground size-4 transition-transform group-data-[state=open]:rotate-90" />
高级设置
<span className="text-muted-foreground ml-auto text-xs font-normal">超时 · 心跳 · 首个意图</span>
<span className="text-muted-foreground ml-auto text-xs font-normal">超时 · 心跳 · Worker · 首个意图</span>
</CollapsibleTrigger>
<CollapsibleContent className="grid gap-5 pt-5">
<div className="grid gap-2">
@@ -3541,6 +3568,23 @@ function CreateTaskSheet({
worker)。下限 10 分钟。
</p>
</div>
<div className="grid gap-2">
<Label htmlFor="worker-count">Worker 运行数量(可选)</Label>
<Input
id="worker-count"
type="number"
min={0}
max={MAX_TASK_WORKER_COUNT}
className="w-40"
placeholder="留空 = 全局默认"
value={workerCount}
onChange={(e) => setWorkerCount(e.target.value)}
/>
<p className="text-muted-foreground text-xs">
单独设置本任务并发运行的工作 Agent 数量;留空或 0 = 用全局默认(系统设置里的工作并发,默认
3)。上限 50。
</p>
</div>
<div className="grid gap-2">
<label htmlFor="seed-first-intent" className="flex items-center gap-2 text-sm">
<Checkbox
+143 -6
View File
@@ -14,7 +14,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { Switch } from "@/components/ui/switch";
import { api } from "@/lib/api";
import { CHAT_SEND_MODE_OPTIONS, type ChatSendMode, setChatSendMode, useChatSendMode } from "@/lib/chat-send-mode";
import type { Settings } from "@/lib/types";
import type { LLMProfile, Settings, WorkerPool } from "@/lib/types";
import { BasicAuthCard } from "./_components/basic-auth-card";
import { UpdateCard } from "./_components/update-card";
@@ -40,11 +40,14 @@ export default function SystemSettingsPage() {
const [savingGlobalProxy, setSavingGlobalProxy] = React.useState(false);
const [testing, setTesting] = React.useState(false);
const [loaded, setLoaded] = React.useState(false);
const [settingsLoaded, setSettingsLoaded] = React.useState(false);
const [saving, setSaving] = React.useState(false);
const [savingKey, setSavingKey] = React.useState(false);
const [pyInterp, setPyInterp] = React.useState("");
const [workers, setWorkers] = React.useState("3");
const [savingWorkers, setSavingWorkers] = React.useState(false);
const [workerPools, setWorkerPools] = React.useState<WorkerPool[]>([]);
const [llmProfiles, setLlmProfiles] = React.useState<LLMProfile[]>([]);
// 操作约束注入范围(默认都开)。
const [injectPlanner, setInjectPlanner] = React.useState(true);
const [injectWorker, setInjectWorker] = React.useState(true);
@@ -67,20 +70,58 @@ export default function SystemSettingsPage() {
setGlobalProxyInput(s.global_proxy ?? "");
setPyInterp(s.python_interpreter ?? "");
setWorkers(String(s.workers ?? 3));
setWorkerPools(s.worker_pools ?? []);
setInjectPlanner(s.constraints_inject_planner !== false);
setInjectWorker(s.constraints_inject_worker !== false);
setNoaCompaction(!!s.noa_compaction);
}, []);
const saveWorkers = () => {
if (!settingsLoaded) {
toast.error("设置加载失败,请刷新后再保存 Worker 配置");
return;
}
const n = Number(workers);
if (workerPools.length > 0) {
const total = workerPools.reduce((sum, pool) => sum + Number(pool.workers), 0);
if (workerPools.some((pool) => !pool.profile_id)) {
toast.error("请选择每个模型池的 LLM 配置");
return;
}
if (workerPools.some((pool) => !Number.isInteger(Number(pool.workers)) || Number(pool.workers) <= 0)) {
toast.error("每个模型池的 Worker 数必须是大于 0 的整数");
return;
}
if (total > 50) {
toast.error("Worker 总数不能超过 50");
return;
}
const ids = workerPools.map((pool) => pool.profile_id);
if (new Set(ids).size !== ids.length) {
toast.error("不能重复选择同一个 LLM 配置");
return;
}
setSavingWorkers(true);
api
.setSettings({
workers: total,
worker_pools: workerPools.map((pool) => ({ ...pool, workers: Number(pool.workers) })),
})
.then((s) => {
apply(s);
toast.success("已保存多模型 Worker 池(对之后启动的任务生效)");
})
.catch((e) => toast.error(`保存失败:${(e as Error).message}`))
.finally(() => setSavingWorkers(false));
return;
}
if (!Number.isInteger(n) || n <= 0) {
toast.error("并发数必须是大于 0 的整数");
return;
}
setSavingWorkers(true);
api
.setSettings({ workers: n })
.setSettings({ workers: n, worker_pools: [] })
.then((s) => {
apply(s);
toast.success("已保存并发工作 agent 数(对之后启动的任务生效)");
@@ -89,6 +130,8 @@ export default function SystemSettingsPage() {
.finally(() => setSavingWorkers(false));
};
const addWorkerPool = () => setWorkerPools((pools) => [...pools, { profile_id: "", workers: 1 }]);
const savePython = () => {
setSaving(true);
api
@@ -112,11 +155,24 @@ export default function SystemSettingsPage() {
React.useEffect(() => {
api
.settings()
.then(apply)
.catch(() => undefined)
.then((s) => {
apply(s);
setSettingsLoaded(true);
})
.catch(() => {
setSettingsLoaded(false);
toast.error("设置加载失败,Worker 配置已锁定,避免覆盖服务器上的模型池");
})
.finally(() => setLoaded(true));
}, [apply]);
React.useEffect(() => {
api
.llmProfiles()
.then(setLlmProfiles)
.catch(() => setLlmProfiles([]));
}, []);
const toggleTraffic = (v: boolean) => {
setTrafficCapture(v); // optimistic
setSaving(true);
@@ -756,6 +812,81 @@ export default function SystemSettingsPage() {
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-3">
<div className="flex flex-col gap-2 rounded-md border p-3">
<div className="flex items-center justify-between">
<Label className="text-sm">多模型 Worker 池</Label>
<Button
variant="outline"
size="sm"
onClick={addWorkerPool}
disabled={!loaded || !settingsLoaded || savingWorkers}
>
添加模型池
</Button>
</div>
{workerPools.map((pool, index) => {
const selected = llmProfiles.find((profile) => profile.id === pool.profile_id);
const placeholder =
selected?.name || (pool.profile_id ? `配置 #${pool.profile_id} 已删除/不可用` : "选择 LLM 配置");
return (
// biome-ignore lint/suspicious/noArrayIndexKey: pool rows are edited in place and only deleted.
<div className="flex items-center gap-2" key={`${pool.profile_id}-${index}`}>
<Select
value={pool.profile_id || undefined}
disabled={!settingsLoaded || savingWorkers}
onValueChange={(value) =>
setWorkerPools((current) =>
current.map((item, itemIndex) =>
itemIndex === index ? { ...item, profile_id: value } : item,
),
)
}
>
<SelectTrigger className="min-w-0 flex-1">
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent>
{!selected && pool.profile_id ? (
<SelectItem value={pool.profile_id}>配置 #{pool.profile_id} 已删除/不可用</SelectItem>
) : null}
{llmProfiles.map((profile) => (
<SelectItem key={profile.id} value={profile.id}>
{profile.name} · {profile.model}
</SelectItem>
))}
</SelectContent>
</Select>
<Input
type="number"
min={1}
className="w-24 font-mono text-sm"
value={pool.workers}
disabled={!settingsLoaded || savingWorkers}
onChange={(event) =>
setWorkerPools((current) =>
current.map((item, itemIndex) =>
itemIndex === index ? { ...item, workers: Number(event.target.value) } : item,
),
)
}
/>
<Button
variant="ghost"
size="sm"
disabled={!settingsLoaded || savingWorkers}
onClick={() => setWorkerPools((current) => current.filter((_, itemIndex) => itemIndex !== index))}
>
删除
</Button>
</div>
);
})}
{workerPools.length > 0 ? (
<div className="text-muted-foreground text-sm">
当前合计:{workerPools.reduce((sum, pool) => sum + (Number(pool.workers) || 0), 0)} 个 Worker 会话
</div>
) : null}
</div>
<div className="flex items-center gap-2">
<Input
type="number"
@@ -763,13 +894,19 @@ export default function SystemSettingsPage() {
className="w-32 font-mono text-sm"
placeholder="3"
value={workers}
disabled={!loaded || savingWorkers}
disabled={!loaded || !settingsLoaded || savingWorkers || workerPools.length > 0}
onChange={(e) => setWorkers(e.target.value)}
/>
<Button onClick={saveWorkers} disabled={!loaded || savingWorkers}>
{workerPools.length > 0 ? (
<span className="text-muted-foreground text-xs">已配置模型池时由各池数量决定并发。</span>
) : null}
<Button onClick={saveWorkers} disabled={!loaded || !settingsLoaded || savingWorkers}>
保存
</Button>
</div>
{!settingsLoaded && loaded ? (
<p className="text-destructive text-xs">设置加载失败,Worker 配置已锁定;刷新成功后才能编辑或保存。</p>
) : null}
</CardContent>
</Card>