mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
329e68e017
* refactor(agent): introduce interfaces for MessageBus and ChannelManager Phase 2 of loop.go refactor — dependency inversion using adapter pattern. - Add interfaces.MessageBus and interfaces.ChannelManager interfaces - Create adapters/messagebus.go wrapping *bus.MessageBus - Create adapters/channelmanager.go wrapping *channels.Manager - Update AgentLoop to use interfaces instead of concrete types - Update registerSharedTools to accept interfaces.MessageBus Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(agent): restructure pipeline and rename loop files Pipeline refactoring: - Split pipeline.go (1400 lines) into focused files: - pipeline_setup.go (~115 lines): SetupTurn method - pipeline_llm.go (~519 lines): CallLLM method - pipeline_execute.go (~693 lines): ExecuteTools method - pipeline_finalize.go (~78 lines): Finalize method - Pipeline struct and NewPipeline remain in pipeline.go (~39 lines) Agent file renaming: - Rename loop_*.go to agent_*.go for consistent naming: - loop.go -> agent.go, loop_message.go -> agent_message.go, etc. - Merge turn.go + turn_exec.go into turn_state.go - Rename loop_turn.go -> turn_coord.go Documentation: - Update docs/pipeline-restructuring-plan.md - Add docs/agent-rename-plan.md Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(agent): code format fixed * refactor(agent): code test file added/renamed * docs(agent): update agent refactor docs * fix(agent): fix agent hardAbortX --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
4.8 KiB
4.8 KiB
Agent 文件重命名计划
目标
统一 pkg/agent/ 包的文件命名,解决 loop_* 前缀命名混乱、职责边界不清晰的问题。
变更概览
文件重命名(12 个)
| 原文件 | 新文件 | 说明 |
|---|---|---|
loop.go |
agent.go |
AgentLoop 主体 + 生命周期方法 |
loop_message.go |
agent_message.go |
消息处理和路由 |
loop_outbound.go |
agent_outbound.go |
响应发布 |
loop_event.go |
agent_event.go |
事件系统 |
loop_command.go |
agent_command.go |
命令处理 |
loop_steering.go |
agent_steering.go |
Steering 消息处理 |
loop_transcribe.go |
agent_transcribe.go |
音频转录 |
loop_media.go |
agent_media.go |
媒体处理 |
loop_mcp.go |
agent_mcp.go |
MCP 初始化 |
loop_utils.go |
agent_utils.go |
工具函数 |
loop_inject.go |
agent_inject.go |
依赖注入 |
loop_turn.go |
turn_coord.go |
Turn 协调器 |
文件合并(2 → 1)
| 原文件 | 新文件 | 说明 |
|---|---|---|
turn.go + turn_exec.go |
turn_state.go |
Turn 相关类型定义 |
最终文件结构
pkg/agent/
├── agent.go # AgentLoop + Run/Stop/Close 生命周期
├── agent_message.go # 消息处理
├── agent_outbound.go # 响应发布
├── agent_event.go # 事件系统
├── agent_command.go # 命令处理
├── agent_steering.go # Steering
├── agent_transcribe.go # 转录
├── agent_media.go # 媒体处理
├── agent_mcp.go # MCP
├── agent_utils.go # 工具函数
├── agent_inject.go # 依赖注入
├── turn_coord.go # runTurn + 协调器
├── turn_state.go # turnState + turnExecution + Control + ToolControl + LLMPhase
├── pipeline.go # Pipeline struct + NewPipeline
├── pipeline_setup.go
├── pipeline_llm.go
├── pipeline_execute.go
└── pipeline_finalize.go
命名约定
| 前缀 | 内容 | 示例 |
|---|---|---|
agent_* |
AgentLoop 的方法文件 | agent_message.go, agent_event.go |
turn_* |
Turn 生命周期相关 | turn_coord.go, turn_state.go |
pipeline_* |
Pipeline 方法 | pipeline_setup.go, pipeline_llm.go |
context_* |
上下文管理 | context_manager.go, context_legacy.go |
hook_* |
Hook 系统 | hook_process.go, hook_mount.go |
架构层次
┌─────────────────────────────────────────────────────────┐
│ AgentLoop (agent.go) │
│ - 消息循环 Run/Stop/Close │
│ - 依赖注入 (agent_inject.go) │
│ - 消息路由 (agent_message.go) │
│ - 响应发布 (agent_outbound.go) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Turn Coordinator (turn_coord.go) │
│ - runTurn(): 主协调器 │
│ - abortTurn(): 中止 │
│ - askSideQuestion(): 侧问 │
│ - selectCandidates(): 模型选择 │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Pipeline (pipeline_*.go) │
│ - SetupTurn(): 初始化 │
│ - CallLLM(): LLM 调用 │
│ - ExecuteTools(): 工具执行 │
│ - Finalize(): 终结 │
└─────────────────────────────────────────────────────────┘
验证结果
- ✅
go build ./pkg/agent/...- 通过 - ✅
go vet ./pkg/agent/...- 无警告 - ✅
go test ./pkg/agent/... -skip "TestSeahorse|TestGlobalSkillFileContentChange"- 通过