feat:增强需求澄清与任务管理功能

更新了 .env.example,新增聊天模型配置,以提升对话处理能力。
增强了 README.md,反映了包括需求澄清、代码复用和自动重试在内的新功能。
重构了 agent.py,以支持多模型交互,并为无法在本地执行的任务新增了引导处理逻辑。
改进了 SandboxRunner,增加了任务执行成功校验,并加入了工作区清理功能。

扩展了 HistoryManager,支持任务摘要生成以及记录的批量删除。
优化了 chat_view.py 和 history_view.py 中的 UI 组件,提升用户体验,包括 Markdown 渲染和任务管理选项。
This commit is contained in:
Mimikko-zeus
2026-01-07 12:35:27 +08:00
parent 0a92355bfb
commit 68f4f01cd7
12 changed files with 3158 additions and 160 deletions

View File

@@ -25,6 +25,7 @@ class TaskRecord:
stdout: str
stderr: str
log_path: str
task_summary: str = "" # 任务摘要(由小模型生成)
class HistoryManager:
@@ -83,7 +84,8 @@ class HistoryManager:
duration_ms: int,
stdout: str = "",
stderr: str = "",
log_path: str = ""
log_path: str = "",
task_summary: str = ""
) -> TaskRecord:
"""
添加一条任务记录
@@ -100,6 +102,7 @@ class HistoryManager:
stdout: 标准输出
stderr: 标准错误
log_path: 日志文件路径
task_summary: 任务摘要
Returns:
TaskRecord: 创建的记录
@@ -116,7 +119,8 @@ class HistoryManager:
duration_ms=duration_ms,
stdout=stdout,
stderr=stderr,
log_path=log_path
log_path=log_path,
task_summary=task_summary
)
# 添加到列表开头(最新的在前)
@@ -146,6 +150,43 @@ class HistoryManager:
return record
return None
def delete_by_id(self, task_id: str) -> bool:
"""
根据任务 ID 删除记录
Args:
task_id: 任务 ID
Returns:
是否删除成功
"""
for i, record in enumerate(self._history):
if record.task_id == task_id:
self._history.pop(i)
self._save()
return True
return False
def delete_multiple(self, task_ids: List[str]) -> int:
"""
批量删除记录
Args:
task_ids: 任务 ID 列表
Returns:
删除的记录数量
"""
task_id_set = set(task_ids)
original_count = len(self._history)
self._history = [r for r in self._history if r.task_id not in task_id_set]
deleted_count = original_count - len(self._history)
if deleted_count > 0:
self._save()
return deleted_count
def clear(self):
"""清空历史记录"""
self._history = []
@@ -174,6 +215,57 @@ class HistoryManager:
'success_rate': success / total if total > 0 else 0.0,
'avg_duration_ms': int(avg_duration)
}
def find_similar_success(self, user_input: str, threshold: float = 0.6) -> Optional[TaskRecord]:
"""
查找相似的成功任务
使用简单的关键词匹配来判断相似度
Args:
user_input: 用户输入
threshold: 相似度阈值
Returns:
最相似的成功任务记录,如果没有则返回 None
"""
# 提取关键词
def extract_keywords(text: str) -> set:
# 简单分词:按空格和标点分割
import re
words = re.findall(r'[\u4e00-\u9fa5]+|[a-zA-Z]+', text.lower())
# 过滤掉太短的词
return set(w for w in words if len(w) >= 2)
input_keywords = extract_keywords(user_input)
if not input_keywords:
return None
best_match = None
best_score = 0.0
for record in self._history:
if not record.success:
continue
record_keywords = extract_keywords(record.user_input)
if not record_keywords:
continue
# 计算 Jaccard 相似度
intersection = len(input_keywords & record_keywords)
union = len(input_keywords | record_keywords)
score = intersection / union if union > 0 else 0
if score > best_score and score >= threshold:
best_score = score
best_match = record
return best_match
def get_successful_records(self) -> List[TaskRecord]:
"""获取所有成功的任务记录"""
return [r for r in self._history if r.success]
# 全局单例