Skip to content

Commit 9f7f10f

Browse files
committed
feat: 重构为无状态Agent并实现JSONL持久化存储
重构Agent为无状态设计,移除内部sessionId管理,改为通过context参数传递 添加全局唯一sessionId到SessionContext,确保对话连续性 实现JSONL格式持久化存储,参考Claude Code的存储方案 更新文档说明无状态Agent架构和JSONL存储格式
1 parent 16cd9ff commit 9f7f10f

16 files changed

Lines changed: 1407 additions & 194 deletions

File tree

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"Bash(git add:*)",
4949
"Bash(git rm:*)",
5050
"Bash(git checkout:*)",
51-
"Bash(git log:*)"
51+
"Bash(git log:*)",
52+
"Bash(pnpm remove:*)"
5253
],
5354
"deny": [],
5455
"ask": [],

CLAUDE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,24 @@ Root (blade-code)
8585

8686
### Agent System
8787
- **Agent** ([src/agent/Agent.ts](src/agent/Agent.ts)): 主要协调器,管理LLM交互、上下文/记忆和执行控制
88+
- **无状态设计**: Agent 不保存 sessionId 和消息历史
8889
- 静态工厂方法 `Agent.create()` 用于创建和初始化实例
90+
- 每次命令可创建新 Agent 实例(用完即弃)
8991
- 通过 `ExecutionEngine` 处理工具执行流程
9092
- 通过 `LoopDetectionService` 防止无限循环
93+
94+
- **SessionContext** ([src/ui/contexts/SessionContext.tsx](src/ui/contexts/SessionContext.tsx)): 会话状态管理
95+
- 维护全局唯一 `sessionId`
96+
- 保存完整消息历史
97+
- 通过 React Context 跨组件共享
98+
- Agent 通过 context 参数获取历史消息
99+
100+
- **架构模式**: 无状态 Agent + 外部 Session
101+
- ✅ 状态隔离: Agent 无状态,Session 有状态
102+
- ✅ 对话连续: 通过传递历史消息保证上下文
103+
- ✅ 内存高效: Agent 用完即释放
104+
- ✅ 并发安全: 多个 Agent 可并发执行
105+
91106
- **ToolRegistry** ([src/tools/registry/ToolRegistry.ts](src/tools/registry/ToolRegistry.ts)): 中心化工具注册/执行系统,提供验证和安全控制
92107
- **ChatService** ([src/services/ChatService.ts](src/services/ChatService.ts)): 统一LLM接口,支持多提供商(基于OpenAI客户端)
93108
- 支持流式和非流式响应
@@ -108,6 +123,12 @@ Root (blade-code)
108123
- 事件驱动架构,支持监听各阶段事件
109124
- 自动记录执行历史
110125
- **PromptBuilder** ([src/prompts/](src/prompts/)): 提示模板管理和构建
126+
- **ContextManager** ([src/context/ContextManager.ts](src/context/ContextManager.ts)): 上下文管理系统
127+
- **JSONL 格式**: 追加式存储,每行一个 JSON 对象
128+
- **项目隔离**: 存储在 `~/.blade/projects/{escaped-path}/` 按项目分离
129+
- **会话 ID**: 使用 nanoid 生成,21 字符 URL 友好
130+
- **路径转义**: `/Users/foo/project``-Users-foo-project`
131+
- 支持消息追溯(parentUuid)、Git 分支记录、Token 统计
111132

112133
## Build & Development Commands
113134

0 commit comments

Comments
 (0)