CleanupSubagent 清理子代理资源
(taskID string)
| 299 | |
| 300 | // CleanupSubagent 清理子代理资源 |
| 301 | func (sm *FileSubagentManager) CleanupSubagent(taskID string) error { |
| 302 | sm.mu.Lock() |
| 303 | defer sm.mu.Unlock() |
| 304 | |
| 305 | instance, exists := sm.agents[taskID] |
| 306 | if !exists { |
| 307 | return fmt.Errorf("subagent not found: %s", taskID) |
| 308 | } |
| 309 | |
| 310 | // 如果还在运行,先停止 |
| 311 | if instance.Status == "running" { |
| 312 | sm.mu.Unlock() |
| 313 | _ = sm.StopSubagent(taskID) |
| 314 | sm.mu.Lock() |
| 315 | // Agent 即将被删除 |
| 316 | } |
| 317 | |
| 318 | // 删除输出文件 |
| 319 | outputFile := filepath.Join(sm.dataDir, taskID+".output") |
| 320 | _ = os.Remove(outputFile) |
| 321 | |
| 322 | // 删除实例记录 |
| 323 | delete(sm.agents, taskID) |
| 324 | |
| 325 | // 删除实例文件 |
| 326 | instanceFile := filepath.Join(sm.dataDir, taskID+".json") |
| 327 | _ = os.Remove(instanceFile) |
| 328 | |
| 329 | return nil |
| 330 | } |
| 331 | |
| 332 | // buildSubagentCommand 构建子代理启动命令 |
| 333 | func (sm *FileSubagentManager) buildSubagentCommand(config *SubagentConfig) (string, error) { |
nothing calls this directly
no test coverage detected