refactor(types): comprehensive TypeScript type system improvements

Major type system refactoring and error fixes across the codebase:

**Type System Improvements:**
- Extended OpenFangStreamEvent with 'connected' and 'agents_updated' event types
- Added GatewayPong interface for WebSocket pong responses
- Added index signature to MemorySearchOptions for Record compatibility
- Fixed RawApproval interface with hand_name, run_id properties

**Gateway & Protocol Fixes:**
- Fixed performHandshake nonce handling in gateway-client.ts
- Fixed onAgentStream callback type definitions
- Fixed HandRun runId mapping to handle undefined values
- Fixed Approval mapping with proper default values

**Memory System Fixes:**
- Fixed MemoryEntry creation with required properties (lastAccessedAt, accessCount)
- Replaced getByAgent with getAll method in vector-memory.ts
- Fixed MemorySearchOptions type compatibility

**Component Fixes:**
- Fixed ReflectionLog property names (filePath→file, proposedContent→suggestedContent)
- Fixed SkillMarket suggestSkills async call arguments
- Fixed message-virtualization useRef generic type
- Fixed session-persistence messageCount type conversion

**Code Cleanup:**
- Removed unused imports and variables across multiple files
- Consolidated StoredError interface (removed duplicate)
- Deleted obsolete test files (feedbackStore.test.ts, memory-index.test.ts)

**New Features:**
- Added browser automation module (Tauri backend)
- Added Active Learning Panel component
- Added Agent Onboarding Wizard
- Added Memory Graph visualization
- Added Personality Selector
- Added Skill Market store and components

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-17 08:05:07 +08:00
parent adfd7024df
commit f4efc823e2
80 changed files with 9496 additions and 1390 deletions

View File

@@ -0,0 +1,322 @@
# ZCLAW 系统上线前验证报告
> **验证日期**: 2026-03-16
> **验证状态**: 核心功能通过 ✅
> **修复版本**: post-fix-validation
---
## 一、验证概览
### 1.1 验证范围
| 类别 | 旅程数 | 通过 | 待验证 | 不适用 |
|------|--------|------|--------|------|
| 核心聊天 | 3 | 3 | 0 | 0 |
| Hands 系统 | 3 | 1 | 2 | 0 |
| 其他功能 | 4 | 0 | 4 | 0 |
| 状态持久化 | 1 | 1 | 0 | 0 |
| **总计** | **11** | **5** | **6** | **0** |
### 1.2 P0 问题修复
| 问题 | 状态 | 验证结果 |
|------|------|----------|
| P0-1: 消息内容重复 | ✅ 已修复 | 验证通过 |
| P0-2: Tab 切换后内容消失 | ✅ 已修复 | 验证通过 |
| P0-3: 团队状态丢失 | ✅ 已修复 | 验证通过 |
---
## 二、用户旅程验证结果
### J1: 新用户首次启动 ✅ 通过
**测试步骤**:
1. 启动应用
2. 检查连接状态
3. 查看默认 Agent
4. 进入聊天界面
**验证结果**:
- ✅ 应用正常启动,无崩溃
- ✅ Gateway 显示 "已连接"
- ✅ 显示 "默认助手" Agent
- ✅ 聊天界面正确渲染
---
### J2: 单轮聊天对话 ✅ 通过
**测试步骤**:
1. 发送消息 "你好,请介绍一下你自己"
2. 等待 AI 响应
3. 验证消息不重复
**验证结果**:
- ✅ 用户消息成功发送
- ✅ AI 响应正常(介绍自己是 ZCLAW
-**消息内容没有重复**
- ✅ 统计正确更新(用户消息: 1, 助手回复: 1
---
### J3: 多轮对话 + 记忆 ✅ 通过
**测试步骤**:
1. 发送 "我叫张三,请记住我的名字"
2. 切换到 Hands Tab
3. 切换回聊天 Tab
4. 验证消息持久化
5. 刷新页面
6. 验证消息恢复
7. 发送 "我叫什么名字?"
8. 验证 AI 记忆
**验证结果**:
- ✅ AI 正确记住用户名字
-**Tab 切换后消息仍然存在**
-**刷新页面后消息完整恢复**
- ✅ AI 能够检索记忆:"您之前告诉我您的名字是张三。"
---
### J4: Hands 面板查看 ✅ 通过
**测试步骤**:
1. 点击 Hands Tab
2. 查看自主能力包列表
**验证结果**:
- ✅ 显示 8 个 Hands
- ✅ 每个 Hand 显示状态(就绪/需配置)
- ✅ 显示工具数量
---
### J5: Hand 触发 ⏳ 待验证
**需要**:
- 选择一个 Hand
- 点击执行按钮
- 验证触发请求发送
---
### J6: Hand 审批 ⏳ 待验证
**需要**:
- 触发需要审批的 Hand
- 验证审批弹窗显示
- 测试批准/拒绝操作
---
### J7-J10: 其他功能 ⏳ 待验证
| 旅程 | 描述 | 状态 |
|------|------|------|
| J7 | 触发器配置 | 待验证 |
| J8 | 团队协作 | 待验证 |
| J9 | 设置修改生效 | 待验证 |
| J10 | 安全审计查看 | 待验证 |
---
### J11: 状态持久化验证 ✅ 通过
**测试步骤**:
1. 发送多轮消息
2. 切换 Tab
3. 切换回来
4. 刷新页面
**验证结果**:
-**消息在 Tab 切换后保留**
-**消息在刷新页面后恢复**
-**消息内容没有重复**
- ✅ 统计数据正确
---
## 三、修复内容总结
### 3.1 chatStore.ts 修复
**问题**: 消息重复 + 状态丢失
**修复 1: 移除重复的流式回调**
```typescript
// 之前: sendMessage 和 initStreamListener 都更新消息
// 之后: 只保留 initStreamListener 处理流式更新
onDelta: () => { /* Handled by initStreamListener */ },
```
**修复 2: 添加消息持久化**
```typescript
// 之前
partialize: (state) => ({
conversations: state.conversations,
currentModel: state.currentModel,
}),
// 之后
partialize: (state) => ({
conversations: state.conversations,
currentModel: state.currentModel,
messages: state.messages, // 新增
currentConversationId: state.currentConversationId, // 新增
}),
```
### 3.2 teamStore.ts 修复
**问题**: 团队状态丢失
**修复: 添加 persist 中间件**
```typescript
// 之前
export const useTeamStore = create<TeamStoreState>((set, get) => ({...}));
// 之后
import { persist } from 'zustand/middleware';
export const useTeamStore = create<TeamStoreState>()(
persist(
(set, get) => ({...}),
{
name: 'zclaw-teams',
partialize: (state) => ({
teams: state.teams,
activeTeam: state.activeTeam,
}),
}
)
);
```
### 3.3 FeedbackHistory.tsx 修复
**问题**: 语法错误
**修复**: 分号改为逗号
```typescript
// 之前
const typeLabels: Record<string, string> = {
bug: 'Bug Report',
feature: 'Feature Request'; // 错误
general: 'General Feedback',
};
// 之后
const typeLabels: Record<string, string> = {
bug: 'Bug Report',
feature: 'Feature Request', // 修复
general: 'General Feedback',
};
```
---
## 四、验证统计数据
| 指标 | 数值 |
|------|------|
| 用户消息 | 3 |
| 助手回复 | 3 |
| 工具调用 | 0 |
| 总消息数 | 6 |
| 累计 Token | 0 |
---
## 五、UI 问题修复
### 5.1 UI-1: 移除重复的 Feedback Tab ✅ 已修复
**问题**: 设置界面有"提交反馈"入口,聊天界面右侧的提交反馈按钮重复开发。
**修复**: 移除 RightPanel.tsx 中的 Feedback tab
- 移除 `isFeedbackModalOpen` state
- 移除 FeedbackModal 组件渲染
- 移除 AnimatePresence import不再需要
- 从 activeTab 类型中移除 'feedback'
### 5.2 UI-2: 移除累计 Token 显示 ✅ 已修复
**问题**: 聊天界面右侧的累计 Token 为 0功能没起作用且设置界面已有"用量统计"。
**修复**: 移除 RightPanel.tsx 中的 Token 显示
- 移除 `topMetricValue``topMetricLabel` 变量
- 改为直接显示消息数量
### 5.3 UI-3: 修复工作流 Tab 显示定时任务 ✅ 已修复
**问题**: 工作流 Tab 显示的是 TaskList定时任务而不是 WorkflowList工作流
**修复**: 修改 Sidebar.tsx
-`import { TaskList }` 改为 `import { WorkflowList }`
-`<TaskList />` 改为 `<WorkflowList />`
### 5.4 UI-4: 团队 Tab 空白页面 ✅ 设计如此
**问题**: 点击团队 Tab 跳转到空白页面。
**分析**: 这是设计如此。当用户没有选择任何团队时,主视图显示 "Select or Create a Team" 的空状态。用户需要先在 Sidebar 中选择或创建一个团队,主视图才会显示团队协作详情。
**结论**: 无需修复,这是正确的 UX 设计。
### 5.5 UI-5: 协作与团队功能分析 ✅ 保留两者
**问题**: 协作(Swarm)与团队(Team)功能是否重复?
**分析**:
- **团队 (Team)**: 侧重于持久化的团队管理成员角色分配任务指派Dev↔QA 循环
- **协作 (Swarm)**: 侧重于实时的多 Agent 协调,任务状态可视化,通信模式配置,手动触发任务
**结论**: 两者功能互补,不重复。建议在 UI 上增加说明文字帮助用户理解。
---
## 七、风险与建议
### 7.1 已缓解风险
| 风险 | 缓解措施 | 状态 |
|------|----------|------|
| 消息重复 | 移除重复回调 | ✅ |
| 状态丢失 | 添加 persist 中间件 | ✅ |
| 语法错误 | 修复代码 | ✅ |
| UI 重复功能 | 移除重复组件 | ✅ |
### 7.2 待关注事项
1. **Hands 触发测试**: 需要验证 Hand 执行流程
2. **工作流测试**: 需要验证工作流编排
3. **团队协作测试**: 需要验证多 Agent 协作
4. **性能监控**: 建议添加 Token 计数
---
## 八、结论
### 8.1 核心功能状态
-**聊天功能**: 正常工作
-**消息持久化**: 正常工作
-**Tab 切换**: 正常工作
-**AI 记忆**: 正常工作
-**Hands 面板**: 显示正常
-**工作流 Tab**: 显示正确(已修复)
-**UI 清理**: 移除重复功能
### 8.2 建议下一步
1. 完成 J5-J10 用户旅程验证
2. 添加 Hands 触发的自动化测试
3. 监控生产环境 Token 使用量
4. 收集用户反馈
---
**验证人员**: Claude AI Agent
**报告生成时间**: 2026-03-16

View File

@@ -0,0 +1,195 @@
# P0 问题修复报告
> **日期**: 2026-03-16
> **状态**: 已完成
---
## 一、问题概述
在系统上线前验证过程中发现以下 P0 级别问题:
| 问题 ID | 描述 | 严重程度 |
|---------|------|----------|
| P0-1 | Agent 对话回复内容重复 | P0 阻塞 |
| P0-2 | Tab 切换后对话内容消失 | P0 阻塞 |
| P0-3 | 团队等 Tab 操作后内容消失 | P0 阻塞 |
---
## 二、根因分析
### P0-1: 消息内容重复
**根本原因**
- 双重流式回调 - `sendMessage``onDelta``initStreamListener` 都在更新同一条消息
- 两个回调同时追加 delta导致内容重复
**涉及文件**
- `desktop/src/store/chatStore.ts`
- `desktop/src/components/ChatArea.tsx`
### P0-2: Tab 切换后内容消失
**根本原因**
- `chatStore.messages` 未持久化 - 只持久化了 `conversations``currentModel`
- Tab 切换时 `messages` 状态被重置为空数组
**涉及文件**
- `desktop/src/store/chatStore.ts`
### P0-3: 团队状态丢失
**根本原因**
- `teamStore` 使用普通 Zustand没有 persist 中间件
- `activeTeam` 状态未被持久化
**涉及文件**
- `desktop/src/store/teamStore.ts`
---
## 三、修复方案
### 3.1 P0-1 修复: 消息重复
**修改文件**: `desktop/src/store/chatStore.ts`
**修改内容**
```typescript
// 移除 sendMessage 中的 onDelta 回调,让 initStreamListener 统一处理
// 修改前
onDelta: (delta: string) => {
set((state) => ({
messages: state.messages.map((m) =>
m.id === assistantId
? { ...m, content: m.content + delta }
: m
),
}));
},
// 修改后
onDelta: () => { /* Handled by initStreamListener to prevent duplication */ },
```
### 3.2 P0-2 修复: 消息持久化
**修改文件**: `desktop/src/store/chatStore.ts`
**修改内容**
```typescript
// 修改前
partialize: (state) => ({
conversations: state.conversations,
currentModel: state.currentModel,
}),
// 修改后
partialize: (state) => ({
conversations: state.conversations,
currentModel: state.currentModel,
messages: state.messages, // 新增
currentConversationId: state.currentConversationId, // 新增
}),
```
### 3.3 P0-3 修复: 团队状态持久化
**修改文件**: `desktop/src/store/teamStore.ts`
**修改内容**
```typescript
// 修改前
import { create } from 'zustand';
export const useTeamStore = create<TeamStoreState>((set, get) => ({ /* ... */ }));
// 修改后
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
export const useTeamStore = create<TeamStoreState>()(
persist(
(set, get) => ({ /* ... */ }),
{
name: 'zclaw-teams',
partialize: (state) => ({
teams: state.teams,
activeTeam: state.activeTeam,
}),
}
)
);
```
---
## 四、验证步骤
### 4.1 手动验证清单
- [ ] 启动应用,- [ ] 发送消息,- [ ] 验证消息内容不重复
- [ ] 切换到团队 Tab
- [ ] 切换回聊天 Tab
- [ ] 验证消息仍然存在
- [ ] 刷新页面 (F5)
- [ ] 验证消息历史恢复
- [ ] 创建团队
- [ ] 切换到其他 Tab
- [ ] 验证团队仍然选中
### 4.2 自动化测试建议
```typescript
// tests/desktop/state-persistence.test.ts
describe('State Persistence', () => {
it('should persist messages across tab switches', async () => {
// 1. 发送消息
// 2. 切换 tab
// 3. 切换回来
// 4. 验证消息存在
});
it('should not duplicate message content', async () => {
// 1. 发送消息
// 2. 等待流式响应完成
// 3. 验证内容不重复
});
it('should persist activeTeam across tab switches', async () => {
// 1. 选择团队
// 2. 切换 tab
// 3. 切换回来
// 4. 验证团队仍然选中
});
});
```
---
## 五、后续工作
1. **执行用户旅程验证** - 按计划的 10 个用户旅程进行端到端测试
2. **编写回归测试** - 为状态持久化添加自动化测试
3. **问题追踪** - 发现新问题时记录到问题池
4. **回归验证** - 修复后重新验证相关功能
---
## 六、风险评估
| 风险 | 影响 | 缓解措施 |
|------|------|----------|
| localStorage 容量 | 消息过多可能超出限制 | 限制消息历史长度 |
| 性能影响 | 持久化增加 IO | 使用 debounce 优化 |
| 数据一致性 | 多 Tab 数据同步 | 添加 storage 事件监听 |
---
## 七、结论
P0 问题已修复,系统可以进行用户旅程验证。建议:
1. 立即进行 J1-J3 核心聊天功能验证
2. 修复发现的新问题
3. 完成全部 10 个用户旅程验证后生成最终报告