Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

Merge upstream/main into codex/btw-side-question

ji ruo7604c763f515
diff --cc agent/mainagent.go
index ae20a4a,674f437..a2d5336
--- a/agent/mainagent.go
+++ b/agent/mainagent.go
@@@ -153,11 -153,15 +153,16 @@@ func (m *MainAgent) Chat(ctx context.Co
NonStreaming: m.nonStreaming(), // 该 profile 选非流式时走 Provider.Complete
MaxTokens: m.maxTokens(), // 0 = 不发上限,由服务端默认值决定
}
- if m.tx != nil { // persist raw human↔AI conversation; one accumulating file per task
+ if m.tx != nil { // persist raw human↔AI conversation; one accumulating file per segment
opts.Transcript = m.tx
+ // Segment 0 keeps the legacy "exp%d-main" name so existing transcripts still
+ // load; each new session (seg>=1) gets its own file for a clean context.
opts.SessionID = fmt.Sprintf("exp%d-main", ts.ID())
+ if mainSeg > 0 {
+ opts.SessionID = fmt.Sprintf("exp%d-main-s%d", ts.ID(), mainSeg)
+ }
}
+ ctx = attachSideCapture(ctx, &opts)
s := agentcore.NewSession(opts)
defer s.Close()
// reload the prior conversation from the transcript so the agent has context
diff --cc db/exploration_tokens_test.go
index a0bbf16,a0bbf16..9dbbc00
--- a/db/exploration_tokens_test.go
+++ b/db/exploration_tokens_test.go
@@@ -88,7 -88,7 +88,7 @@@ func TestTokenStatsBySessionUsesComplet
if len(got) != 3 {
t.Fatalf("sessions = %+v, want only main, plan, and the local intent", sessions)
}
-- assertSessionTokens(t, got["main"], "main", 11, 12, 13, 14)
++ assertSessionTokens(t, got["main:0"], "main:0", 11, 12, 13, 14)
assertSessionTokens(t, got["plan"], "plan", 21, 22, 23, 24)
assertSessionTokens(t, got[fmt.Sprintf("intent:%d", intentID)], fmt.Sprintf("intent:%d", intentID),
completedRuns, completedRuns*2, completedRuns*3, completedRuns*4)
diff --cc web/src/app/(main)/function/tasks/detail/_tabs/sessions-tab.tsx
index eddf142,789892a..eb3148b
--- a/web/src/app/(main)/function/tasks/detail/_tabs/sessions-tab.tsx
+++ b/web/src/app/(main)/function/tasks/detail/_tabs/sessions-tab.tsx
@@@ -1320,8 -1409,7 +1419,8 @@@ export function SessionsTab({ taskId }
function send() {
const text = input.trim();
const atts = attachments;
- if ((!text && atts.length === 0) || sending) return;
+ if (side.handleCommand(text, () => setInput(""))) return;
- if ((!text && atts.length === 0) || sending || mainLive) return;
++ if ((!text && atts.length === 0) || sending || mainBusy) return;
// No optimistic echo: the backend persists+broadcasts the human turn before it
// returns, so it streams back over SSE (worker="mainagent") with its real DB
// seq — the transcript renders it from server data like every other step. Clear
@@@ -1665,122 -1764,192 +1781,122 @@@
to block so wide/unbreakable steps (long commands, code, URLs) can't blow
out the width and defeat the truncation below — the transcript wraps to
the panel instead of overflowing horizontally. */}
- <ScrollArea type="auto" className="min-h-0 min-w-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:block!">
- <div className="min-w-0 max-w-full p-4" ref={contentRef}>
- {activeState?.loadingMore && (
- <div className="flex items-center justify-center gap-2 pb-2 text-xs text-muted-foreground">
- <Loader2Icon className="size-3.5 animate-spin" />
- 加载更早历史…
- </div>
- )}
- {showLoader ? (
- <div className="flex items-center gap-2 pl-9 text-xs text-muted-foreground">
- <Loader2Icon className="size-3.5 animate-spin" />
- 加载活动流…
- </div>
- ) : activeState?.error ? (
- <div className="flex items-center gap-2 pl-9 text-xs text-red-500">
- <CircleXIcon className="size-3.5" />
- 加载失败:{activeState.error}
- <Button size="sm" variant="ghost" className="h-6 px-2 text-xs" onClick={() => loadSession(activeKey)}>
- 重试
- </Button>
- </div>
- ) : activity.length ? (
- <Transcript activity={activity} live={active.live} taskId={taskId} chat={isMain} />
- ) : (
- <div className="pl-9 text-xs text-muted-foreground">
- {isMain ? "还没有对话。在下方给主 Agent 发消息,引导探索方向或介入流程。" : "暂无活动记录。"}
- </div>
- )}
- </div>
- </ScrollArea>
- {isMain ? (
- <div className="border-t p-3">
- {attachments.length > 0 && (
- <div className="mb-2 flex flex-wrap gap-1.5">
- {attachments.map((a) => (
- <div
- key={a.path}
- className="flex items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 text-xs"
- title={a.path}
+ <ScrollArea type="auto" className="min-h-0 min-w-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:block!">
+ <div className="min-w-0 max-w-full p-4" ref={contentRef}>
+ {activeState?.loadingMore && (
+ <div className="flex items-center justify-center gap-2 pb-2 text-xs text-muted-foreground">
+ <Loader2Icon className="size-3.5 animate-spin" />
+ 加载更早历史…
+ </div>
+ )}
+ {showLoader ? (
+ <div className="flex items-center gap-2 pl-9 text-xs text-muted-foreground">
+ <Loader2Icon className="size-3.5 animate-spin" />
+ 加载活动流…
+ </div>
+ ) : activeState?.error ? (
+ <div className="flex items-center gap-2 pl-9 text-xs text-red-500">
+ <CircleXIcon className="size-3.5" />
+ 加载失败:{activeState.error}
+ <Button
+ size="sm"
+ variant="ghost"
+ className="h-6 px-2 text-xs"
+ onClick={() => loadSession(activeKey)}
>
- <PaperclipIcon className="size-3 shrink-0 text-primary" />
- <span className="max-w-[160px] truncate">{a.name}</span>
- <span className="text-muted-foreground">{fmtBytes(a.size)}</span>
- <button
- type="button"
- className="ml-0.5 text-muted-foreground hover:text-foreground"
- onClick={() => setAttachments((p) => p.filter((x) => x.path !== a.path))}
- title="移除"
+ 重试
+ </Button>
+ </div>
+ ) : activity.length ? (
+ <Transcript activity={activity} live={active.live} taskId={taskId} chat={isMain} />
+ ) : (
+ <div className="pl-9 text-xs text-muted-foreground">
+ {isMain ? "还没有对话。在下方给主 Agent 发消息,引导探索方向或介入流程。" : "暂无活动记录。"}
+ </div>
+ )}
+ </div>
+ </ScrollArea>
+ {isMain ? (
+ <div className="border-t p-3">
+ {attachments.length > 0 && (
+ <div className="mb-2 flex flex-wrap gap-1.5">
+ {attachments.map((a) => (
+ <div
+ key={a.path}
+ className="flex items-center gap-1.5 rounded-md border bg-muted/50 px-2 py-1 text-xs"
+ title={a.path}
>
- <XIcon className="size-3" />
- </button>
- </div>
- ))}
- </div>
- )}
- <input
- ref={fileInputRef}
- type="file"
- multiple
- className="hidden"
- onChange={(e) => void pickFiles(e.target.files)}
- />
- <InputGroup className="min-h-9 has-disabled:opacity-100">
- <InputGroupTextarea
- rows={1}
- aria-label="给主 Agent 发消息"
- placeholder="给主 Agent 发消息,引导探索方向…"
- value={input}
- onChange={(e) => setInput(e.target.value)}
- onKeyDown={(e) => {
- if (!shouldSubmitOnKey(e, sendMode)) return;
- e.preventDefault();
- if (!mainBusy) send();
- }}
- disabled={mainBusy}
- className="max-h-36 min-h-9 overflow-y-auto"
+ <PaperclipIcon className="size-3 shrink-0 text-primary" />
+ <span className="max-w-[160px] truncate">{a.name}</span>
+ <span className="text-muted-foreground">{fmtBytes(a.size)}</span>
+ <button
+ type="button"
+ className="ml-0.5 text-muted-foreground hover:text-foreground"
+ onClick={() => setAttachments((p) => p.filter((x) => x.path !== a.path))}
+ title="移除"
+ >
+ <XIcon className="size-3" />
+ </button>
+ </div>
+ ))}
+ </div>
+ )}
+ <input
+ ref={fileInputRef}
+ type="file"
+ multiple
+ className="hidden"
+ onChange={(e) => void pickFiles(e.target.files)}
/>
- <InputGroupAddon align="block-end">
- <InputGroupButton
- size="icon-xs"
- variant="ghost"
- onClick={() => fileInputRef.current?.click()}
- disabled={mainBusy || uploading}
- title="上传文件"
- aria-label="上传文件"
- >
- {uploading ? <Loader2Icon className="animate-spin" /> : <PaperclipIcon />}
- </InputGroupButton>
- {mainBusy ? (
- <InputGroupButton
- className="ml-auto"
- size="icon-xs"
- variant="destructive"
- onClick={stop}
- disabled={stopping}
- title="停止当前执行"
- aria-label="停止当前执行"
- >
- {stopping ? <Loader2Icon className="animate-spin" /> : <SquareIcon />}
- </InputGroupButton>
- ) : (
+ <InputGroup className="min-h-9 has-disabled:opacity-100">
+ <InputGroupTextarea
+ rows={1}
+ aria-label="给主 Agent 发消息"
- placeholder={mainLive ? "主 Agent 正在运行,可输入 /btw 提问…" : "给主 Agent 发消息,引导探索方向…"}
++ placeholder={mainBusy ? "主 Agent 正在运行,可输入 /btw 提问…" : "给主 Agent 发消息,引导探索方向…"}
+ value={input}
+ onChange={(e) => setInput(e.target.value)}
+ onKeyDown={(e) => {
+ if (!shouldSubmitOnKey(e, sendMode)) return;
+ e.preventDefault();
+ send();
+ }}
+ className="max-h-36 min-h-9 overflow-y-auto"
+ />
+ <InputGroupAddon align="block-end">
<InputGroupButton
- className="ml-auto"
size="icon-xs"
- variant="default"
- onClick={send}
- disabled={(!input.trim() && attachments.length === 0) || sending}
- title="发送消息"
- aria-label="发送消息"
+ variant="ghost"
+ onClick={() => fileInputRef.current?.click()}
- disabled={mainLive || uploading}
++ disabled={mainBusy || uploading}
+ title="上传文件"
+ aria-label="上传文件"
>
- {sending ? <Loader2Icon className="animate-spin" /> : <ArrowUpIcon />}
+ {uploading ? <Loader2Icon className="animate-spin" /> : <PaperclipIcon />}
</InputGroupButton>
- {mainLive && isBtwCommand(input) && (
- )}
- </InputGroupAddon>
- </InputGroup>
- </div>
- ) : active.role === "worker" &&
- !active.inherited &&
- (active.status === "running" || active.status === "paused") ? (
- <div className="border-t p-3">
- <InputGroup className="min-h-9 has-disabled:opacity-100">
- <InputGroupTextarea
- rows={1}
- aria-label={`给 Worker #${active.intent_id} 发消息`}
- placeholder={`给 Worker #${active.intent_id} 发消息,调整执行方向…`}
- value={workerMessage}
- onChange={(event) => {
- setWorkerMessage(event.target.value);
- setWorkerMessageRequestId("");
- }}
- onKeyDown={(event) => {
- if (!shouldSubmitOnKey(event, sendMode)) return;
- event.preventDefault();
- sendWorkerChat();
- }}
- disabled={active.status === "running" || workerMessageSending}
- aria-invalid={workerMessageCharCount(workerMessage) > MAX_WORKER_MESSAGE_CHARS}
- className="max-h-36 min-h-9 overflow-y-auto"
- />
- <InputGroupAddon align="block-end">
- <span
- className={cn(
- "px-1 text-[10px] tabular-nums text-muted-foreground",
- workerMessageCharCount(workerMessage) > MAX_WORKER_MESSAGE_CHARS && "text-destructive",
++ {mainBusy && isBtwCommand(input) && (
+ <InputGroupButton size="icon-xs" onClick={send} aria-label="发送旁路问题">
+ <ArrowUpIcon />
+ </InputGroupButton>
)}
- {mainLive ? (
- >
- {workerMessageCharCount(workerMessage)}/{MAX_WORKER_MESSAGE_CHARS}
- </span>
- {active.status === "running" ? (
- <InputGroupButton
- className="ml-auto"
- size="icon-xs"
- variant="destructive"
- onClick={() => void controlWorker(active, "pause")}
- disabled={controllingIntent === active.intent_id}
- title="暂停当前 Worker"
- aria-label="暂停当前 Worker"
- >
- {controllingIntent === active.intent_id ? (
- <Loader2Icon className="animate-spin" />
- ) : (
- <SquareIcon />
- )}
- </InputGroupButton>
- ) : (
- <>
++ {mainBusy ? (
<InputGroupButton
className="ml-auto"
- size="xs"
- variant="ghost"
- onClick={() => void controlWorker(active, "resume")}
- disabled={controllingIntent === active.intent_id || workerMessageSending}
- title="不发消息,直接继续执行"
- aria-label="直接继续执行"
+ size="icon-xs"
+ variant="destructive"
+ onClick={stop}
+ disabled={stopping}
+ title="停止当前执行"
+ aria-label="停止当前执行"
>
- {controllingIntent === active.intent_id ? <Loader2Icon className="animate-spin" /> : "直接继续"}
+ {stopping ? <Loader2Icon className="animate-spin" /> : <SquareIcon />}
</InputGroupButton>
+ ) : (
<InputGroupButton
+ className="ml-auto"
size="icon-xs"
variant="default"
- onClick={sendWorkerChat}
- disabled={
- workerMessageSending ||
- !workerMessage.trim() ||
- workerMessageCharCount(workerMessage) > MAX_WORKER_MESSAGE_CHARS
- }
+ onClick={send}
+ disabled={(!input.trim() && attachments.length === 0) || sending}
title="发送消息"
aria-label="发送消息"
>