feat: AI 助手工作流时间线——思考分段与工具调用按序记录,流式滚动智能跟随
4 个文件变更
+334
-52
fqh@example.com
| •internal/server/assistant.go | +46 -23 |
| •internal/server/assistant_test.go | +103 -0 |
| •webroot/static/assistant.js | +141 -27 |
| •webroot/static/style.css | +44 -2 |
变更内容
diff --git a/internal/server/assistant.go b/internal/server/assistant.go
index 4f324b5..4c70cc3 100644
--- a/internal/server/assistant.go
+++ b/internal/server/assistant.go
@@ -42,6 +42,9 @@ const (
maxAnswerRunes = 4000
// maxReasoningRunes 是思维链展示的字符上限。
maxReasoningRunes = 6000
+ // maxToolEventRunes 是 tool 事件里结果摘要的字符上限;完整结果只送给
+ // 模型,浏览器里仅展示摘要,避免撑爆前端面板。
+ maxToolEventRunes = 800
// assistantTimeout 是一次提问的总时限(含模型调用与工具执行)。
assistantTimeout = 100 * time.Second
@@ -201,12 +204,12 @@ func (s *Server) handleAssistantChat(w http.ResponseWriter, r *http.Request) {
}
// 前置校验已通过,切换为 SSE 流式响应:
- // status → 工具执行进度
- // reasoning → 思维链增量
- // delta → 回答正文增量
- // clear → 本轮流出的内容作废(模型转而调用工具时)
- // error → 失败(客户端按 JSON/流两种形态都能识别错误)
- // done → 最终结果(服务端渲染的 Markdown + 配额信息)
+ // reasoning → 思维链增量(带 round 标记所在工具轮次,前端按轮分段展示)
+ // clear → 本轮流出的正文作废(模型转而调用工具时)
+ // tool → 工具调用记录(start/end 两段,含工具名、参数与结果摘要)
+ // delta → 回答正文增量
+ // error → 失败(客户端按 JSON/流两种形态都能识别错误)
+ // done → 最终结果(服务端渲染的 Markdown + 配额信息)
// X-Accel-Buffering 禁用 nginx 缓冲,保证增量即时到达浏览器。
w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
w.Header().Set("Cache-Control", "no-store")
@@ -370,21 +373,24 @@ func clipList(in []string, max int) []string {
// streamAssistant 跑完一轮带工具的流式问答,返回(正式回答, 思维链, 错误)。
//
// 每一轮都以流式调用模型:内容增量经 ThinkFilter 剥离内联 <think> 后实时
-// 透出;思维链增量同样实时透出。若模型转而调用工具(工具轮通常没有内容
-// 增量),先发 clear 作废可能已流出的正文,执行只读工具后继续下一轮。
-// 轮次/次数预算用尽时要求模型基于已有信息直接作答,而不是把错误抛给访客。
+// 透出;思维链增量同样实时透出(带 round 轮次标记,前端据此把「思考 →
+// 查仓库 → 再思考 → 作答」的完整过程分段记录展示)。若模型转而调用工具
+// (工具轮通常没有内容增量),先发 clear 作废可能已流出的正文,随后以
+// tool 事件逐个记录工具的调用与结果摘要。轮次/次数预算用尽时要求模型
+// 基于已有信息直接作答,而不是把错误抛给访客。
func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Config, msgs []ai.Message, emit func(event string, data any)) (string, string, error) {
tools := assistantToolSpecs()
budget := maxToolCalls
var reasoningBuf strings.Builder
// emitReasoning 统一收集思维链:进缓冲(最终结果用)并实时透出。
- emitReasoning := func(text string) {
+ // round 标记当前工具轮次,前端据此把不同轮次的思考分段展示。
+ emitReasoning := func(round int, text string) {
if text == "" {
return
}
reasoningBuf.WriteString(text)
- emit("reasoning", map[string]string{"delta": text})
+ emit("reasoning", map[string]any{"delta": text, "round": round})
}
for round := 0; round < maxToolRounds; round++ {
@@ -392,13 +398,13 @@ func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Co
filter := ai.NewThinkFilter(func(s string) {
streamed = true
emit("delta", map[string]string{"text": s})
- }, emitReasoning)
+ }, func(text string) { emitReasoning(round, text) })
res, err := ai.ChatStream(ctx, cfg, msgs, tools, func(kind, text string) {
if kind == ai.DeltaContent {
filter.Write(text)
} else {
- emitReasoning(text)
+ emitReasoning(round, text)
}
})
filter.Close()
@@ -411,7 +417,7 @@ func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Co
if thinking == "" {
thinking = plain.Reasoning
}
- emitReasoning(thinking)
+ emitReasoning(0, thinking)
if answer != "" {
emit("delta", map[string]string{"text": answer})
}
@@ -445,15 +451,20 @@ func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Co
// 留在历史里会误导模型,也白白消耗上下文。
msgs = append(msgs, ai.Message{Role: "assistant", Content: ai.StripThinking(res.Content), ToolCalls: res.ToolCalls})
for _, call := range res.ToolCalls {
+ // 工具调用对访客可见:start/end 成对送出,参数与结果摘要用于
+ // 前端按时间顺序记录整个查仓库过程。
+ emit("tool", map[string]any{"phase": "start", "name": call.Name, "args": parseToolArgs(call)})
+ var result string
if budget <= 0 {
- msgs = append(msgs, ai.Message{Role: "tool", ToolCallID: call.ID,
- Content: "本次提问可用的工具调用次数已用完,请基于已有信息作答。"})
- continue
+ result = "本次提问可用的工具调用次数已用完,请基于已有信息作答。"
+ emit("tool", map[string]any{"phase": "end", "name": call.Name, "result": result, "ok": false})
+ } else {
+ budget--
+ result = ai.Redact(s.execAssistantTool(dir, ref, call))
+ emit("tool", map[string]any{"phase": "end", "name": call.Name,
+ "result": clipRunes(result, maxToolEventRunes), "ok": true})
}
- budget--
- emit("status", map[string]string{"message": "正在查阅仓库…"})
- msgs = append(msgs, ai.Message{Role: "tool", ToolCallID: call.ID,
- Content: ai.Redact(s.execAssistantTool(dir, ref, call))})
+ msgs = append(msgs, ai.Message{Role: "tool", ToolCallID: call.ID, Content: result})
}
}
@@ -461,12 +472,12 @@ func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Co
msgs = append(msgs, ai.Message{Role: "user", Content: "请基于上面已经获取到的信息直接回答我的问题,不要再调用工具。"})
filter := ai.NewThinkFilter(func(s string) {
emit("delta", map[string]string{"text": s})
- }, emitReasoning)
+ }, func(text string) { emitReasoning(maxToolRounds, text) })
res, err := ai.ChatStream(ctx, cfg, msgs, nil, func(kind, text string) {
if kind == ai.DeltaContent {
filter.Write(text)
} else {
- emitReasoning(text)
+ emitReasoning(maxToolRounds, text)
}
})
filter.Close()
@@ -484,6 +495,18 @@ func (s *Server) streamAssistant(ctx context.Context, dir, ref string, cfg ai.Co
return answer, reasoning, nil
}
+// parseToolArgs 把模型给出的工具参数 JSON 解析成对象供前端展示;
+// 解析失败时退回原始字符串,不影响主流程。
+func parseToolArgs(call ai.ToolCall) any {
+ var m map[string]any
+ if raw := strings.TrimSpace(call.Args); raw != "" {
+ if err := json.Unmarshal([]byte(raw), &m); err == nil {
+ return m
+ }
+ }
+ return call.Args
+}
+
// assistantToolSpecs 声明助手可用的只读工具。
func assistantToolSpecs() []ai.ToolSpec {
return []ai.ToolSpec{
diff --git a/internal/server/assistant_test.go b/internal/server/assistant_test.go
index a2fb86b..4f6ef3f 100644
--- a/internal/server/assistant_test.go
+++ b/internal/server/assistant_test.go
@@ -193,6 +193,30 @@ func aiToolCall(id, name, args string) string {
return aiToolCalls(toolReq{id: id, name: name, args: args})
}
+// aiReasonedToolCalls 构造一条带思维链(reasoning_content)的工具调用回复,
+// 用于验证前端分轮展示思考段所需的 round 标记。
+func aiReasonedToolCalls(reasoning string, reqs ...toolReq) string {
+ return aiReasonedContentToolCalls("", reasoning, reqs...)
+}
+
+// aiReasonedContentToolCalls 构造一条同时带正文、思维链与工具调用的回复;
+// 正文会先流出再转工具调用,正是服务端发 clear 作废片段的场景。
+func aiReasonedContentToolCalls(content, reasoning string, reqs ...toolReq) string {
+ calls := make([]any, 0, len(reqs))
+ for _, r := range reqs {
+ calls = append(calls, map[string]any{
+ "id": r.id, "type": "function",
+ "function": map[string]any{"name": r.name, "arguments": r.args},
+ })
+ }
+ b, _ := json.Marshal(map[string]any{
+ "choices": []any{map[string]any{"message": map[string]any{
+ "content": content, "reasoning_content": reasoning, "tool_calls": calls,
+ }}},
+ })
+ return string(b)
+}
+
// ---------------------------------------------------------------- 测试辅助
// enableAI 打开全局 AI 并把它指向假端点。
@@ -438,6 +462,85 @@ func TestAssistantUsesReadonlyTools(t *testing.T) {
}
}
+// TestAssistantWorkflowEventsStreamed 覆盖新的事件协议:工具调用以
+// tool start/end 事件成对流式送出(含工具名、解析后的参数与结果摘要),
+// 思维链事件带 round 轮次标记(前端据此把「思考 → 查仓库 → 再思考 →
+// 作答」分段记录展示),正文作废仍走 clear 且不清掉已记录的步骤。
+func TestAssistantWorkflowEventsStreamed(t *testing.T) {
+ srv, st, _, _ := newTestServer(t)
+ dir := makeRepo(t, srv, st, "workflow", nil)
+ commitFiles(t, dir, "first", map[string]string{"hello.txt": "hello world\n"})
+ fake := newFakeAI(t,
+ aiReasonedToolCalls("先看看这个文件", toolReq{"c1", "read_file", `{"path":"hello.txt"}`}),
+ aiReasonedContentToolCalls("让我确认一下目录", "文件里只有一句 hello world",
+ toolReq{"c2", "list_files", `{}`}),
+ aiText("文件内容是 hello world。"),
+ )
+ enableAI(t, st, fake.srv.URL)
+
+ w := postAssistant(srv, "workflow", "10.4.4.4", "hello.txt 里写了什么?", nil, "")
+ if w.Code != http.StatusOK {
+ t.Fatalf("返回 %d,期望 200:%s", w.Code, w.Body.String())
+ }
+
+ var toolStarts, toolEnds []map[string]any
+ var rounds []float64
+ var sawClear bool
+ var deltaText string
+ for _, ev := range parseSSE(t, w.Body.String()) {
+ var m map[string]any
+ if json.Unmarshal([]byte(ev.Data), &m) != nil {
+ continue
+ }
+ switch ev.Event {
+ case "tool":
+ if m["phase"] == "start" {
+ toolStarts = append(toolStarts, m)
+ } else {
+ toolEnds = append(toolEnds, m)
+ }
+ case "reasoning":
+ if r, ok := m["round"].(float64); ok {
+ rounds = append(rounds, r)
+ } else {
+ t.Errorf("reasoning 事件缺少 round 字段:%v", m)
+ }
+ case "clear":
+ sawClear = true
+ deltaText = "" // 与前端一致:clear 作废之前流出的正文片段
+ case "delta":
+ deltaText += m["text"].(string)
+ }
+ }
+
+ if len(toolStarts) != 2 || len(toolEnds) != 2 {
+ t.Fatalf("期望 2 组 tool start/end 事件,实际 start=%d end=%d", len(toolStarts), len(toolEnds))
+ }
+ if toolStarts[0]["name"] != "read_file" || toolStarts[1]["name"] != "list_files" {
+ t.Errorf("工具名 = %v / %v,期望 read_file / list_files", toolStarts[0]["name"], toolStarts[1]["name"])
+ }
+ args, _ := toolStarts[0]["args"].(map[string]any)
+ if args == nil || args["path"] != "hello.txt" {
+ t.Errorf("tool start 应带解析后的参数对象:%v", toolStarts[0]["args"])
+ }
+ if toolEnds[0]["ok"] != true {
+ t.Errorf("工具执行成功应标记 ok=true:%v", toolEnds[0])
+ }
+ if !strings.Contains(fmt.Sprint(toolEnds[0]["result"]), "hello world") {
+ t.Errorf("tool end 应带结果摘要:%v", toolEnds[0]["result"])
+ }
+ // 两轮思考:round 应从 0 递增到 1,前端据此分段
+ if len(rounds) == 0 || rounds[0] != 0 || rounds[len(rounds)-1] != 1 {
+ t.Errorf("reasoning round 应覆盖 0→1 两轮,实际 %v", rounds)
+ }
+ if !sawClear {
+ t.Error("模型转而调用工具时应发出 clear 事件作废正文片段")
+ }
+ if deltaText != "文件内容是 hello world。" {
+ t.Errorf("delta 拼接 = %q,期望只有最终回答", deltaText)
+ }
+}
+
// TestAssistantFallsBackWithoutTools 端点不支持 function calling 时,
// 首次失败应自动降级为不带工具的纯对话,而不是把错误抛给访客。
func TestAssistantFallsBackWithoutTools(t *testing.T) {
diff --git a/webroot/static/assistant.js b/webroot/static/assistant.js
index e2221a6..7b56647 100644
--- a/webroot/static/assistant.js
+++ b/webroot/static/assistant.js
@@ -1,7 +1,9 @@
/* gitcat AI 项目助手:右下角圆形入口 + 对话面板。
对话只保存在当前页面内存里,每次提问带上最近几轮历史,服务端不落库。
- 回答通过 SSE 流式输出:思考过程与正文增量渐进渲染,结束后替换为
- 服务端渲染的 Markdown。 */
+ 回答通过 SSE 流式输出:整个「思考 → 查仓库 → 再思考 → 作答」过程像
+ vibecoding 工作流一样按时间顺序逐步记录(各轮思考分段折叠、工具调用
+ 连同结果摘要依次排列),结束后正文替换为服务端渲染的 Markdown。
+ 滚动采用智能跟随:默认吸底,用户向上翻阅时不再强制拉底。 */
(function () {
'use strict';
@@ -32,7 +34,19 @@
return node;
}
- function scrollDown() {
+ /* -------------------------------------------------------- 智能滚动 */
+
+ // 跟随式滚动:默认吸底;一旦用户向上滚动离开底部,流式期间就不再
+ // 强制拉底,等用户重新滚回底部附近后自动恢复跟随。force 用于用户
+ // 主动行为(发送提问、打开面板)——此时无论如何都回到底部。
+ var stick = true;
+ var STICK_GAP = 48; // 距底部小于该像素视为「在底部」
+ body.addEventListener('scroll', function () {
+ stick = body.scrollHeight - body.scrollTop - body.clientHeight < STICK_GAP;
+ });
+
+ function scrollDown(force) {
+ if (!force && !stick) return;
body.scrollTop = body.scrollHeight;
}
@@ -41,7 +55,7 @@
root.classList.toggle('open', open);
fab.setAttribute('aria-expanded', open ? 'true' : 'false');
if (open) {
- scrollDown();
+ scrollDown(true);
input.focus();
} else {
fab.focus();
@@ -105,30 +119,54 @@
/* ------------------------------------------------ 流式渲染的气泡结构 */
- // streamingUI 持有当前流式回答里的各个动态节点。
+ // streamingUI 持有当前流式回答里的各个动态节点。整体是一张工作流
+ // 时间线(steps):各轮思考段、工具调用记录按时间顺序依次追加,
+ // 互不覆盖;正文单独渲染在 raw 里,结束后替换为 Markdown。
var streamingUI = null;
+ // 工具名到人类可读标签的映射;未知工具直接展示原名。
+ var TOOL_NAMES = {
+ list_files: '列出文件',
+ read_file: '读取文件',
+ search_code: '搜索代码',
+ recent_commits: '最近提交'
+ };
+
+ function toolLabel(name) {
+ return TOOL_NAMES[name] || (name || '工具');
+ }
+
+ // toolSummary 把工具参数提炼成一行人类可读的摘要。
+ function toolSummary(name, args) {
+ var a = (args && typeof args === 'object') ? args : {};
+ switch (name) {
+ case 'list_files': return a.path || '根目录';
+ case 'read_file': {
+ var s = a.path || '';
+ if (+a.start_line > 1) s += ' · 第 ' + a.start_line + ' 行起';
+ return s;
+ }
+ case 'search_code': return a.query ? '「' + a.query + '」' : '';
+ case 'recent_commits': return +a.limit ? a.limit + ' 条' : '';
+ default: return '';
+ }
+ }
+
function newStreamingMsg() {
var wrap = el('div');
- var think = el('details', 'ai-think');
- var sum = el('summary');
- sum.textContent = '思考过程';
- var thinkBody = el('div', 'ai-think-body');
- think.appendChild(sum);
- think.appendChild(thinkBody);
-
+ var steps = el('div', 'ai-steps');
var status = el('div', 'ai-status');
var raw = el('div', 'ai-raw streaming');
-
- wrap.appendChild(think);
+ wrap.appendChild(steps);
wrap.appendChild(status);
wrap.appendChild(raw);
addMsg('bot', wrap);
streamingUI = {
- think: think,
- thinkBody: thinkBody,
- reasoningShown: false,
+ steps: steps,
+ think: null, // 当前轮的思考段(details),round 变化时定稿换新
+ thinkRound: -1,
+ tool: null, // 正在执行的工具行
status: status,
raw: raw,
rawText: '',
@@ -137,13 +175,82 @@
return streamingUI;
}
- function uiReasoning(delta) {
+ // finalizeThink 定稿当前思考段:收起但内容保留(访客可再展开回看),
+ // 空段直接移除避免留下空壳。
+ function finalizeThink() {
+ if (!streamingUI || !streamingUI.think) return;
+ var t = streamingUI.think;
+ streamingUI.think = null;
+ streamingUI.thinkRound = -1;
+ if (t._body.textContent) {
+ t.open = false;
+ } else if (t.parentNode) {
+ t.parentNode.removeChild(t);
+ }
+ }
+
+ function uiReasoning(round, delta) {
+ if (!streamingUI) return;
+ // 新一轮(模型再次思考)时定稿上一段、另起一段,而不是拼进旧段
+ if (!streamingUI.think || round !== streamingUI.thinkRound) {
+ finalizeThink();
+ var think = el('details', 'ai-think');
+ var sum = el('summary');
+ sum.textContent = '思考过程';
+ var thinkBody = el('div', 'ai-think-body');
+ think.appendChild(sum);
+ think.appendChild(thinkBody);
+ think._body = thinkBody;
+ think.open = true; // 思考中展开,让访客看到进展
+ streamingUI.steps.appendChild(think);
+ streamingUI.think = think;
+ streamingUI.thinkRound = round;
+ }
+ var tb = streamingUI.think._body;
+ tb.textContent += delta;
+ // 折叠区内部也采用跟随式滚动:用户在段内上翻时不打扰
+ if (tb.scrollHeight - tb.scrollTop - tb.clientHeight < 32) {
+ tb.scrollTop = tb.scrollHeight;
+ }
+ scrollDown();
+ }
+
+ function uiToolStart(data) {
if (!streamingUI) return;
- if (!streamingUI.reasoningShown) {
- streamingUI.reasoningShown = true;
- streamingUI.think.open = true; // 思考中展开,让访客看到进展
+ finalizeThink(); // 工具开始执行:上一段思考定稿收起
+ var row = el('div', 'ai-tool running');
+ var line = el('div', 'ai-tool-line');
+ var ico = el('span', 'ai-tool-ico');
+ var name = el('span', 'ai-tool-name');
+ name.textContent = toolLabel(data.name);
+ var arg = el('span', 'ai-tool-arg');
+ arg.textContent = toolSummary(data.name, data.args);
+ line.appendChild(ico);
+ line.appendChild(name);
+ line.appendChild(arg);
+ row.appendChild(line);
+ streamingUI.steps.appendChild(row);
+ streamingUI.tool = row;
+ scrollDown();
+ }
+
+ function uiToolEnd(data) {
+ if (!streamingUI || !streamingUI.tool) return;
+ var row = streamingUI.tool;
+ streamingUI.tool = null;
+ row.classList.remove('running');
+ row.classList.add(data.ok === false ? 'skipped' : 'done');
+ var result = (data.result || '').trim();
+ if (result) {
+ var det = el('details', 'ai-tool-result');
+ var sum = el('summary');
+ sum.textContent = '查看结果';
+ var pre = el('pre');
+ pre.textContent = result;
+ det.appendChild(sum);
+ det.appendChild(pre);
+ row.appendChild(det);
}
- streamingUI.thinkBody.textContent += delta;
scrollDown();
}
@@ -156,7 +263,7 @@
function uiDelta(text) {
if (!streamingUI) return;
if (streamingUI.status.textContent) streamingUI.status.style.display = 'none';
- if (streamingUI.reasoningShown) streamingUI.think.open = false; // 开始作答后收起思考
+ finalizeThink(); // 开始作答:思考段收起定稿,内容保留可展开
streamingUI.rawText += text;
streamingUI.raw.textContent = streamingUI.rawText;
scrollDown();
@@ -164,6 +271,7 @@
function uiClear() {
if (!streamingUI) return;
+ // 只作废正文片段;时间线上已记录的思考段与工具调用原样保留
streamingUI.rawText = '';
streamingUI.raw.textContent = '';
}
@@ -171,6 +279,7 @@
function uiDone(data) {
if (!streamingUI) return;
streamingUI.finished = true;
+ finalizeThink();
streamingUI.raw.classList.remove('streaming');
streamingUI.raw.textContent = '';
var markdown = el('div', 'ai-md');
@@ -179,10 +288,10 @@
if (typeof data.answer_text === 'string') {
history.push({ role: 'assistant', content: data.answer_text });
}
- if (data.reasoning && !streamingUI.reasoningShown) {
+ if (data.reasoning && !streamingUI.steps.querySelector('.ai-think')) {
// 兜底:服务端有思维链但流式阶段没送出增量
- streamingUI.reasoningShown = true;
- streamingUI.thinkBody.textContent = data.reasoning;
+ uiReasoning(0, data.reasoning);
+ finalizeThink();
}
if (data.guest && typeof data.remaining === 'number' && data.remaining > 0) {
updateTip('还可问 ' + data.remaining + ' 个');
@@ -219,8 +328,12 @@
var payload;
try { payload = JSON.parse(data); } catch (e) { return; }
switch (event) {
+ case 'reasoning': uiReasoning(payload.round || 0, payload.delta || ''); break;
+ case 'tool':
+ if (payload.phase === 'end') uiToolEnd(payload);
+ else uiToolStart(payload);
+ break;
case 'status': uiStatus(payload.message || ''); break;
- case 'reasoning': uiReasoning(payload.delta || ''); break;
case 'delta': uiDelta(payload.text || ''); break;
case 'clear': uiClear(); break;
case 'error': uiFail(payload.error || 'AI 暂时不可用,请稍后再试。'); failed = true; break;
@@ -258,6 +371,7 @@
if (suggests && suggests.parentNode) suggests.parentNode.removeChild(suggests);
addMsg('me', textBubble(question));
+ scrollDown(true); // 用户刚发出提问,无论如何都回到底部等待回答
var prior = history.slice(-8);
history.push({ role: 'user', content: question });
input.value = '';
diff --git a/webroot/static/style.css b/webroot/static/style.css
index 054db1d..c55592f 100644
--- a/webroot/static/style.css
+++ b/webroot/static/style.css
@@ -966,9 +966,11 @@ a.release-name:hover { color: var(--green-700); }
.ai-msg.err .ai-bubble { background: var(--danger-100); border-color: #f6cfcf; color: #a53232; }
.ai-bubble p { margin: 0; }
-/* 助手回答里的 Markdown(服务端渲染) */
+/* 助手回答里的工作流时间线:各轮思考段与工具调用按时间顺序依次排列 */
+.ai-steps { display: flex; flex-direction: column; gap: 6px; }
+.ai-steps:empty { display: none; }
.ai-think {
- margin: 0 0 .55em; font-size: .8rem; color: var(--ink-3);
+ margin: 0; font-size: .8rem; color: var(--ink-3);
background: rgba(11, 36, 49, .045); border-radius: 9px; overflow: hidden;
}
.ai-think summary {
@@ -987,6 +989,46 @@ a.release-name:hover { color: var(--green-700); }
padding: 2px 10px 9px; white-space: pre-wrap; overflow-wrap: anywhere;
max-height: 200px; overflow-y: auto; line-height: 1.6; opacity: .92;
}
+
+/* 工具调用记录:执行中转圈,结束打勾,被跳过显示感叹号 */
+.ai-tool { font-size: .8rem; color: var(--ink-3); }
+.ai-tool-line {
+ display: flex; align-items: center; gap: 6px; padding: 5px 9px; min-width: 0;
+ background: rgba(11, 36, 49, .045); border-radius: 9px;
+}
+.ai-tool-ico { position: relative; flex: none; width: 13px; height: 13px; border-radius: 50%; }
+.ai-tool.running .ai-tool-ico {
+ border: 2px solid rgba(18, 184, 134, .25); border-top-color: var(--green-600);
+ animation: ai-spin .8s linear infinite;
+}
+@keyframes ai-spin { to { transform: rotate(360deg); } }
+.ai-tool.done .ai-tool-ico::before {
+ content: ""; position: absolute; left: 3.5px; top: 1.5px; width: 3px; height: 6px;
+ border-right: 2px solid var(--green-600); border-bottom: 2px solid var(--green-600);
+ transform: rotate(40deg);
+}
+.ai-tool.skipped .ai-tool-ico::before {
+ content: "!"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
+ font-size: 10px; font-weight: 700; font-style: normal; color: #b7791f;
+}
+.ai-tool-name { flex: none; font-weight: 650; color: var(--ink-2); }
+.ai-tool-arg {
+ min-width: 0; font-family: var(--mono); font-size: .92em;
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
+}
+.ai-tool-result { margin: 3px 0 0 10px; font-size: .92em; }
+.ai-tool-result summary { cursor: pointer; user-select: none; list-style: none; opacity: .85; }
+.ai-tool-result summary::-webkit-details-marker { display: none; }
+.ai-tool-result summary::before { content: "▸ "; }
+.ai-tool-result[open] summary::before { content: "▾ "; }
+.ai-tool-result summary:hover { color: var(--ink-2); }
+.ai-tool-result pre {
+ margin: 4px 0 0; padding: 7px 9px; border-radius: 8px; overflow: auto; max-height: 160px;
+ background: rgba(11, 36, 49, .05); font-family: var(--mono); font-size: .78rem;
+ line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
+}
+
+/* 助手回答里的 Markdown(服务端渲染) */
.ai-md > *:first-child { margin-top: 0; }
.ai-md > *:last-child { margin-bottom: 0; }
.ai-md p { margin: .45em 0; }