ben
fe5508228f
fix: 修复多 backend 并行日志 PID 混乱并移除包装格式 ( #74 ) ( #76 )
...
* fix(logger): 修复多 backend 并行日志 PID 混乱并移除包装格式
**问题:**
- logger.go:288 使用 os.Getpid() 导致并行任务日志 PID 混乱
- 日志文件添加时间戳/PID/级别前缀包装,应输出 backend 原始内容
**修复:**
1. Logger 结构体添加 pid 字段,创建时捕获 PID
2. 日志写入使用固定 l.pid 替代 os.Getpid()
3. 移除日志输出格式包装,直接写入原始消息
4. 添加内存缓存 ERROR/WARN 条目,ExtractRecentErrors 从缓存读取
5. 优化 executor.go context 初始化顺序,避免重复创建 logger
**测试:**
- 所有测试通过(23.7s)
- 更新相关测试用例匹配新格式
Closes #74
* fix(logger): 增强并发日志隔离和 task ID 清理
## 核心修复
### 1. Task ID Sanitization (logger.go)
- 新增 sanitizeLogSuffix(): 清理非法字符 (/, \, :, 等)
- 新增 fallbackLogSuffix(): 为空/非法 ID 生成唯一后备名
- 新增 isSafeLogRune(): 仅允许 [A-Za-z0-9._-]
- 路径穿越防护: ../../../etc/passwd → etc-passwd-{hash}.log
- 超长 ID 处理: 截断到 64 字符 + hash 确保唯一性
- 自动创建 TMPDIR (MkdirAll)
### 2. 共享日志标识 (executor.go)
- 新增 taskLoggerHandle 结构: 封装 logger、路径、共享标志
- 新增 newTaskLoggerHandle(): 统一处理 logger 创建和回退
- printTaskStart(): 显示 "Log (shared)" 标识
- generateFinalOutput(): 在 summary 中标记共享日志
- 并发失败时明确标识所有任务使用共享主日志
### 3. 内部标志 (config.go)
- TaskResult.sharedLog: 非导出字段,标识共享日志状态
### 4. Race Detector 修复 (logger.go:209-219)
- Close() 在关闭 channel 前先等待 pendingWG
- 消除 Logger.Close() 与 Logger.log() 之间的竞态条件
## 测试覆盖
### 新增测试 (logger_suffix_test.go)
- TestLoggerWithSuffixSanitizesUnsafeSuffix: 非法字符清理
- TestLoggerWithSuffixReturnsErrorWhenTempDirNotWritable: 只读目录处理
### 新增测试 (executor_concurrent_test.go)
- TestConcurrentTaskLoggerFailure: 多任务失败时共享日志标识
- TestSanitizeTaskID: 并发场景下 task ID 清理验证
## 验证结果
✅ 所有单元测试通过
✅ Race detector 无竞态 (65.4s)
✅ 路径穿越攻击防护
✅ 并发日志完全隔离
✅ 边界情况正确处理
Resolves: PR #76 review feedback
Co-Authored-By: Codex Review <codex@anthropic.ai >
Generated with swe-agent-bot
Co-Authored-By: swe-agent-bot <agent@swe-agent.ai >
* fix(logger): 修复关键 bug 并优化日志系统 (v5.2.5)
修复 P0 级别问题:
- sanitizeLogSuffix 的 trim 碰撞(防止多 task 日志文件名冲突)
- ExtractRecentErrors 边界检查(防止 slice 越界)
- Logger.Close 阻塞风险(新增可配置超时机制)
代码质量改进:
- 删除无用字段 Logger.pid 和 logEntry.level
- 优化 sharedLog 标记绑定到最终 LogPath
- 移除日志前缀,直接输出 backend 原始内容
测试覆盖增强:
- 新增 4 个测试用例(碰撞防护、边界检查、缓存上限、shared 判定)
- 优化测试注释和逻辑
版本更新:5.2.4 → 5.2.5
Generated with swe-agent-bot
Co-Authored-By: swe-agent-bot <agent@swe-agent.ai >
---------
Co-authored-by: swe-agent-bot <agent@swe-agent.ai >
2025-12-17 10:33:38 +08:00
cexll
d215c33549
fix(executor): isolate log files per task in parallel mode
...
Previously, all parallel tasks shared the same log file path, making it
difficult to debug individual task execution. This change creates a
separate log file for each task using the naming convention:
codeagent-wrapper-{pid}-{taskName}.log
Changes:
- Add withTaskLogger/taskLoggerFromContext for per-task logger injection
- Modify executeConcurrentWithContext to create independent Logger per task
- Update printTaskStart to display task-specific log paths
- Extract defaultRunCodexTaskFn for proper test hook reset
- Add runCodexTaskFn reset to resetTestHooks()
Test coverage: 93.7%
Generated with swe-agent-bot
Co-Authored-By: swe-agent-bot <agent@swe-agent.ai >
2025-12-16 10:05:54 +08:00
swe-agent[bot]
b227fee225
fix codeagent claude and gemini root dir
2025-12-13 16:56:53 +08:00
swe-agent[bot]
edbf168b57
fix(codeagent-wrapper): fix race condition in stdout parsing
...
修复 GitHub Actions CI 中的测试失败问题。
问题分析:
在 TestRun_PipedTaskSuccess 测试中,当脚本运行很快时,cmd.Wait()
可能在 parseJSONStreamInternal goroutine 开始读取之前就返回,
导致 stdout 管道被过早关闭,出现 "read |0: file already closed" 错误。
解决方案:
将 parseJSONStreamInternal goroutine 的启动提前到 cmd.Start() 之前。
这确保解析器在进程启动前就 ready,避免竞态条件。
测试结果:
- 本地所有测试通过 ✓
- 覆盖率保持 93.7% ✓
Generated with swe-agent-bot
Co-Authored-By: swe-agent-bot <agent@swe-agent.ai >
2025-12-13 13:20:49 +08:00
swe-agent[bot]
e1ad08fcc1
feat(codeagent-wrapper): 完整多后端支持与安全优化
...
修复 PR #53 中发现的问题,实现完整的多后端功能:
**多后端功能完整性**
- Claude/Gemini 后端支持 workdir (-C) 和 resume (--session-id) 参数
- 并行模式支持全局 --backend 参数和任务级 backend 配置
- 后端参数映射统一,支持 new/resume 两种模式
**安全控制**
- Claude 后端默认启用 --dangerously-skip-permissions 以支持自动化
- 通过 CODEAGENT_SKIP_PERMISSIONS 环境变量控制权限检查
- 不同后端行为区分:Claude 默认跳过,Codex/Gemini 默认启用
**并发控制**
- 新增 CODEAGENT_MAX_PARALLEL_WORKERS 环境变量限制并发数
- 实现 fail-fast context 取消机制
- Worker pool 防止资源耗尽,支持并发监控日志
**向后兼容**
- 版本号统一管理,提供 codex-wrapper 兼容脚本
- 所有默认行为保持不变
- 支持渐进式迁移
**测试覆盖**
- 总体覆盖率 93.4%(超过 90% 要求)
- 新增后端参数、并行模式、并发控制测试用例
- 核心模块覆盖率:backend.go 100%, config.go 97.8%, executor.go 96.4%
**文档更新**
- 更新 skills/codeagent/SKILL.md 反映多后端和安全控制
- 添加 CHANGELOG.md 记录重要变更
- 更新 README 版本说明和安装脚本
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-11 16:09:33 +08:00
swe-agent[bot]
cf2e4fefa4
fix(codeagent-wrapper): 重构信号处理逻辑避免重复 nil 检查
...
改进信号转发函数的可读性和可维护性:
- 提取 signalNotifyFn 和 signalStopFn 的默认值设置
- 消除嵌套的 nil 检查
- 保持相同的功能行为
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-10 16:29:32 +08:00
swe-agent[bot]
c6cd20d2fd
fix(parallel): 修复并行执行启动横幅重复打印问题
...
修复 GitHub Actions 失败的测试 TestRunParallelStartupLogsPrinted。
问题根源:
- 在 main.go 中有重复的启动横幅和日志路径打印逻辑
- executeConcurrent 内部也添加了相同的打印逻辑
- 导致横幅和任务日志被打印两次
修复内容:
1. 删除 main.go 中 --parallel 处理中的重复打印代码(行 184-194)
2. 保留 executeConcurrent 中的 printTaskStart 函数,实现:
- 在任务启动时立即打印日志路径
- 使用 mutex 保护并发打印,确保横幅只打印一次
- 按实际执行顺序打印任务信息
测试结果:
- TestRunParallelStartupLogsPrinted: PASS
- TestRunNonParallelOutputsIncludeLogPathsIntegration: PASS
- TestRunStartupCleanupRemovesOrphansEndToEnd: PASS
影响范围:
- 修复了 --parallel 模式下的日志输出格式
- 不影响非并行模式的执行
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-09 17:02:59 +08:00
swe-agent[bot]
132df6cb28
fix(merge): 修复master合并后的编译和测试问题
...
在重构代码后合并master分支时需要的适配:
1. **接口定义恢复** (executor.go)
- 添加 commandRunner 和 processHandle 接口
- 实现 realCmd 和 realProcess 适配器
- 添加 newCommandRunner 测试钩子
2. **TaskResult扩展** (config.go)
- 添加 LogPath 字段支持日志路径跟踪
- 在 generateFinalOutput 中输出 LogPath
3. **原子变量适配** (main.go, executor.go)
- forceKillDelay 从int改为 atomic.Int32
- 添加测试钩子: cleanupLogsFn, signalNotifyFn, signalStopFn
- 添加 stdout 关闭原因常量
4. **功能函数添加**
- runStartupCleanup: 启动时清理旧日志
- runCleanupMode: --cleanup 模式处理
- forceKillTimer 类型和 terminateCommand 函数
- terminateProcess nil 安全检查
5. **测试适配** (logger_test.go, main_test.go)
- 将 *exec.Cmd 包装为 &realCmd{cmd}
- 修复 forwardSignals 等函数调用
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-09 16:24:15 +08:00
swe-agent[bot]
3ef288bfaa
feat: implement enterprise workflow with multi-backend support
...
## Overview
Complete implementation of enterprise-level workflow features including
multi-backend execution (Codex/Claude/Gemini), GitHub issue-to-PR automation,
hooks system, and comprehensive documentation.
## Major Changes
### 1. Multi-Backend Support (codeagent-wrapper)
- Renamed codex-wrapper → codeagent-wrapper
- Backend interface with Codex/Claude/Gemini implementations
- Multi-format JSON stream parser (auto-detects backend)
- CLI flag: --backend codex|claude|gemini (default: codex)
- Test coverage: 89.2%
**Files:**
- codeagent-wrapper/backend.go - Backend interface
- codeagent-wrapper/parser.go - Multi-format parser
- codeagent-wrapper/config.go - CLI parsing with backend selection
- codeagent-wrapper/executor.go - Process execution
- codeagent-wrapper/logger.go - Async logging
- codeagent-wrapper/utils.go - Utilities
### 2. GitHub Workflow Commands
- /gh-create-issue - Create structured issues via guided dialogue
- /gh-implement - Issue-to-PR automation with full dev lifecycle
**Files:**
- github-workflow/commands/gh-create-issue.md
- github-workflow/commands/gh-implement.md
- skills/codeagent/SKILL.md
### 3. Hooks System
- UserPromptSubmit hook for skill activation
- Pre-commit example with code quality checks
- merge_json operation in install.py for settings.json merging
**Files:**
- hooks/skill-activation-prompt.sh|.js
- hooks/pre-commit.sh
- hooks/hooks-config.json
- hooks/test-skill-activation.sh
### 4. Skills System
- skill-rules.json for auto-activation
- codeagent skill for multi-backend wrapper
**Files:**
- skills/skill-rules.json
- skills/codeagent/SKILL.md
- skills/codex/SKILL.md (updated)
### 5. Installation System
- install.py: Added merge_json operation
- config.json: Added "gh" module
- config.schema.json: Added op_merge_json schema
### 6. CI/CD
- GitHub Actions workflow for testing and building
**Files:**
- .github/workflows/ci.yml
### 7. Comprehensive Documentation
- Architecture overview with ASCII diagrams
- Codeagent-wrapper complete usage guide
- GitHub workflow detailed examples
- Hooks customization guide
**Files:**
- docs/architecture.md (21KB)
- docs/CODEAGENT-WRAPPER.md (9KB)
- docs/GITHUB-WORKFLOW.md (9KB)
- docs/HOOKS.md (4KB)
- docs/enterprise-workflow-ideas.md
- README.md (updated with doc links)
## Test Results
- All tests passing ✅
- Coverage: 89.2%
- Security scan: 0 issues (gosec)
## Breaking Changes
- codex-wrapper renamed to codeagent-wrapper
- Default backend: codex (documented in README)
## Migration Guide
Users with codex-wrapper installed should:
1. Run: python3 install.py --module dev --force
2. Update shell aliases if any
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-09 15:53:31 +08:00