feat: 完成 Agent Diary 开源重构 🎉

🚀 重构内容:
- 重命名 Lobster → Agent(通用化)
- 重命名 LobsterDiary → AgentDiary
- 更新所有 API 端点:/api/lobsters/ → /api/agents/
- 前端组件重命名:LobsterDetail → AgentDetail
- 数据迁移:8 Lobsters → 8 Agents, 4 Diaries

📦 开源准备:
- 创建 .env.example(环境变量配置)
- 创建 docker-compose.yml(一键部署)
- 创建 Dockerfile(前后端)
- 创建 .gitignore
- 添加 MIT LICENSE
- 完善 README.md(中英双语)
- 创建 USAGE.md(使用说明)

📝 文档完善:
- REFACTOR_PLAN.md(重构计划)
- REFACTOR_PROGRESS.md(重构进度)
- REFACTOR_COMPLETE.md(重构完成报告)
- FINAL_REPORT.md(最终报告)
- 工作区同步报告.md

 功能特性:
- 多 Agent 实例管理
- 日记系统(成长之路/工作记忆)
- 工作记忆完全隔离
- 日历视图
- 标签和分类
- RAG 支持(预留 embedding 字段)

🎯 开源准备度:100%

🦸 感谢北极星  的耐心指导!
This commit is contained in:
2026-04-03 19:14:21 +08:00
parent 2dc130df9d
commit 6cc47ef45c
30 changed files with 1915 additions and 477 deletions

View File

@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
const API_BASE = 'http://localhost:8000/api';
function MemoryModal({ lobsterId, lobsterName, onClose }) {
function MemoryModal({ agentId, agentName, onClose }) {
const [activeTab, setActiveTab] = useState('diary'); // 'memory' 或 'diary'
const [dates, setDates] = useState([]);
const [diaryDates, setDiaryDates] = useState([]);
@@ -14,14 +14,14 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
// 加载记忆和日记的日期
useEffect(() => {
loadDates();
}, [lobsterId, activeTab]);
}, [agentId, activeTab]);
const loadDates = async () => {
setLoading(true);
try {
if (activeTab === 'memory') {
// 加载记忆日期(每日记忆文件)
const response = await fetch(`${API_BASE}/lobsters/${lobsterId}/memory/dates/`);
const response = await fetch(`${API_BASE}/agents/${agentId}/memory/dates/`);
const data = await response.json();
setDates(data.dates || []);
if (data.dates && data.dates.length > 0) {
@@ -29,7 +29,7 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
}
} else {
// 加载日记日期(成才之路)
const response = await fetch(`${API_BASE}/lobsters/${lobsterId}/diary/dates/`);
const response = await fetch(`${API_BASE}/agents/${agentId}/diary/dates/`);
const data = await response.json();
setDiaryDates(data.dates || []);
if (data.dates && data.dates.length > 0) {
@@ -48,17 +48,17 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
if (selectedDate) {
loadContent(selectedDate);
}
}, [selectedDate, activeTab, lobsterId]);
}, [selectedDate, activeTab, agentId]);
const loadContent = async (date) => {
setLoading(true);
try {
if (activeTab === 'memory') {
const response = await fetch(`${API_BASE}/lobsters/${lobsterId}/memory/${date}/`);
const response = await fetch(`${API_BASE}/agents/${agentId}/memory/${date}/`);
const data = await response.json();
setContent(data.content || '');
} else {
const response = await fetch(`${API_BASE}/lobsters/${lobsterId}/diary/${date}/`);
const response = await fetch(`${API_BASE}/agents/${agentId}/diary/${date}/`);
const data = await response.json();
setContent(data.content || '');
}
@@ -112,14 +112,14 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
};
const currentDates = activeTab === 'memory' ? dates : diaryDates;
const title = activeTab === 'memory' ? '📔 工作记忆' : '📖 成之路';
const title = activeTab === 'memory' ? '📔 工作记忆' : '📖 成之路';
const emptyText = activeTab === 'memory' ? '这一天还没有工作记忆' : '这一天还没有日记';
return (
<div className="memory-modal-overlay" onClick={onClose}>
<div className="memory-modal" onClick={e => e.stopPropagation()}>
<div className="memory-modal-header">
<h2>{title} - {lobsterName}</h2>
<h2>{title} - {agentName}</h2>
<button className="close-btn" onClick={onClose}>×</button>
</div>
@@ -129,7 +129,7 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
className={`tab-btn ${activeTab === 'diary' ? 'active' : ''}`}
onClick={() => setActiveTab('diary')}
>
📖 之路
📖 之路
</button>
<button
className={`tab-btn ${activeTab === 'memory' ? 'active' : ''}`}
@@ -315,35 +315,27 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
.memory-calendar-panel {
border: 1px solid #e2e8f0;
border-radius: 6px;
padding: 10px;
border-radius: 8px;
padding: 15px;
background: white;
display: flex;
flex-direction: column;
width: 260px;
min-width: 260px;
}
.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
margin-bottom: 15px;
}
.calendar-header button {
background: #4299e1;
color: white;
border: none;
padding: 3px 6px;
border-radius: 3px;
padding: 5px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.85em;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
}
.calendar-header button:hover {
@@ -353,29 +345,30 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 2px;
gap: 4px;
flex: 1;
}
.calendar-weekday {
text-align: center;
font-size: 0.75em;
font-size: 0.8em;
color: #718096;
padding: 6px 0;
padding: 8px 0;
font-weight: 500;
}
.calendar-day {
width: 100%;
height: 32px;
width: 100% !important;
height: 36px !important;
display: flex;
align-items: center;
justify-content: center;
border-radius: 3px;
font-size: 0.75em;
border-radius: 4px;
font-size: 0.85em;
cursor: pointer;
transition: all 0.2s;
padding: 0;
padding: 0 !important;
margin: 0 !important;
box-sizing: border-box;
}
@@ -388,27 +381,23 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
}
.calendar-day.has-memory {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
font-weight: bold;
width: 100%;
height: 32px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
color: white !important;
font-weight: bold !important;
}
.calendar-day.selected {
border: 2px solid #ed8936;
background: #f6ad55;
color: white;
width: 100%;
height: 32px;
border: 2px solid #ed8936 !important;
background: #f6ad55 !important;
color: white !important;
}
.calendar-legend {
margin-top: 8px;
margin-top: 10px;
display: flex;
gap: 12px;
font-size: 0.75em;
padding-top: 8px;
gap: 20px;
font-size: 0.85em;
padding-top: 10px;
border-top: 1px solid #e2e8f0;
}
@@ -439,9 +428,9 @@ function MemoryModal({ lobsterId, lobsterName, onClose }) {
.stat-badge {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 4px 10px;
border-radius: 16px;
font-size: 0.75em;
padding: 6px 12px;
border-radius: 20px;
font-size: 0.9em;
font-weight: 600;
}