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
2025-12-13 12:37:45 +08:00
2025-12-16 13:05:28 +08:00
2025-12-13 21:41:55 +08:00
2025-12-16 12:29:50 +08:00
2025-12-13 12:31:49 +08:00

中文 English

Claude Code Multi-Agent Workflow System

Run in Smithery

License: AGPL-3.0 Claude Code Version

AI-powered development automation with multi-backend execution (Codex/Claude/Gemini)

Core Concept: Multi-Backend Architecture

This system leverages a dual-agent architecture with pluggable AI backends:

Role Agent Responsibility
Orchestrator Claude Code Planning, context gathering, verification, user interaction
Executor codeagent-wrapper Code editing, test execution (Codex/Claude/Gemini backends)

Why this separation?

  • Claude Code excels at understanding context and orchestrating complex workflows
  • Specialized backends (Codex for code, Claude for reasoning, Gemini for prototyping) excel at focused execution
  • Backend selection via --backend codex|claude|gemini matches the model to the task

Quick Start(Please execute in Powershell on Windows)

git clone https://github.com/cexll/myclaude.git
cd myclaude
python3 install.py --install-dir ~/.claude

Workflows Overview

The primary workflow for most development tasks.

/dev "implement user authentication with JWT"

6-Step Process:

  1. Requirements Clarification - Interactive Q&A to clarify scope
  2. Codex Deep Analysis - Codebase exploration and architecture decisions
  3. Dev Plan Generation - Structured task breakdown with test requirements
  4. Parallel Execution - Codex executes tasks concurrently
  5. Coverage Validation - Enforce ≥90% test coverage
  6. Completion Summary - Report with file changes and coverage stats

Key Features:

  • Claude Code orchestrates, Codex executes all code changes
  • Automatic task parallelization for speed
  • Mandatory 90% test coverage gate
  • Rollback on failure

Best For: Feature development, refactoring, bug fixes with tests


2. BMAD Agile Workflow

Full enterprise agile methodology with 6 specialized agents.

/bmad-pilot "build e-commerce checkout system"

Agents:

Agent Role
Product Owner Requirements & user stories
Architect System design & tech decisions
Tech Lead Sprint planning & task breakdown
Developer Implementation
Code Reviewer Quality assurance
QA Engineer Testing & validation

Process:

Requirements → Architecture → Sprint Plan → Development → Review → QA
     ↓              ↓             ↓            ↓          ↓       ↓
   PRD.md      DESIGN.md     SPRINT.md     Code      REVIEW.md  TEST.md

Best For: Large features, team coordination, enterprise projects


3. Requirements-Driven Workflow

Lightweight requirements-to-code pipeline.

/requirements-pilot "implement API rate limiting"

Process:

  1. Requirements generation with quality scoring
  2. Implementation planning
  3. Code generation
  4. Review and testing

Best For: Quick prototypes, well-defined features


4. Development Essentials

Direct commands for daily coding tasks.

Command Purpose
/code Implement a feature
/debug Debug an issue
/test Write tests
/review Code review
/optimize Performance optimization
/refactor Code refactoring
/docs Documentation

Best For: Quick tasks, no workflow overhead needed

Enterprise Workflow Features

  • Multi-backend execution: codeagent-wrapper --backend codex|claude|gemini (default codex) so you can match the model to the task without changing workflows.
  • GitHub workflow commands: /gh-create-issue "short need" creates structured issues; /gh-issue-implement 123 pulls issue #123, drives development, and prepares the PR.
  • Skills + hooks activation: .claude/hooks run automation (tests, reviews), while .claude/skills/skill-rules.json auto-suggests the right skills. Keep hooks enabled in .claude/settings.json to activate the enterprise workflow helpers.

Installation

# Install all enabled modules (dev + essentials by default)
python3 install.py --install-dir ~/.claude

# Install specific module
python3 install.py --module dev

# List available modules
python3 install.py --list-modules

# Force overwrite existing files
python3 install.py --force

Available Modules

Module Default Description
dev ✓ Enabled Dev workflow + Codex integration
essentials ✓ Enabled Core development commands
bmad Disabled Full BMAD agile workflow
requirements Disabled Requirements-driven workflow

What Gets Installed

~/.claude/
├── CLAUDE.md              # Core instructions and role definition
├── commands/              # Slash commands (/dev, /code, etc.)
├── agents/                # Agent definitions
├── skills/
│   └── codex/
│       └── SKILL.md       # Codex integration skill
└── installed_modules.json # Installation status

Configuration

Edit config.json to customize:

{
  "version": "1.0",
  "install_dir": "~/.claude",
  "modules": {
    "dev": {
      "enabled": true,
      "operations": [
        {"type": "merge_dir", "source": "dev-workflow"},
        {"type": "copy_file", "source": "memorys/CLAUDE.md", "target": "CLAUDE.md"},
        {"type": "copy_file", "source": "skills/codex/SKILL.md", "target": "skills/codex/SKILL.md"},
        {"type": "run_command", "command": "bash install.sh"}
      ]
    }
  }
}

Operation Types:

Type Description
merge_dir Merge subdirs (commands/, agents/) into install dir
copy_dir Copy entire directory
copy_file Copy single file to target path
run_command Execute shell command

Codex Integration

The codex skill enables Claude Code to delegate code execution to Codex CLI.

Usage in Workflows

# Codex is invoked via the skill
codeagent-wrapper - <<'EOF'
implement @src/auth.ts with JWT validation
EOF

Parallel Execution

codeagent-wrapper --parallel <<'EOF'
---TASK---
id: backend_api
workdir: /project/backend
---CONTENT---
implement REST endpoints for /api/users

---TASK---
id: frontend_ui
workdir: /project/frontend
dependencies: backend_api
---CONTENT---
create React components consuming the API
EOF

Install Codex Wrapper

# Automatic (via dev module)
python3 install.py --module dev

# Manual
bash install.sh

Windows

Windows installs place codeagent-wrapper.exe in %USERPROFILE%\bin.

# PowerShell (recommended)
powershell -ExecutionPolicy Bypass -File install.ps1

# Batch (cmd)
install.bat

Add to PATH (if installer doesn't detect it):

# PowerShell - persistent for current user
[Environment]::SetEnvironmentVariable('PATH', "$HOME\bin;" + [Environment]::GetEnvironmentVariable('PATH','User'), 'User')

# PowerShell - current session only
$Env:PATH = "$HOME\bin;$Env:PATH"
REM cmd.exe - persistent for current user
setx PATH "%USERPROFILE%\bin;%PATH%"

Workflow Selection Guide

Scenario Recommended Workflow
New feature with tests /dev
Quick bug fix /debug or /code
Large multi-sprint feature /bmad-pilot
Prototype or POC /requirements-pilot
Code review /review
Performance issue /optimize

Troubleshooting

Common Issues

Codex wrapper not found:

# Check PATH
echo $PATH | grep -q "$HOME/bin" || echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc

# Reinstall
bash install.sh

Permission denied:

python3 install.py --install-dir ~/.claude --force

Module not loading:

# Check installation status
cat ~/.claude/installed_modules.json

# Reinstall specific module
python3 install.py --module dev --force

Documentation

Core Guides

Additional Resources


License

AGPL-3.0 License - see LICENSE

Support


Claude Code + Codex = Better Development - Orchestration meets execution.

Description
Claude Code and Codex orchestration workflow
Readme AGPL-3.0 9.2 MiB
Languages
Go 74.8%
Python 10.8%
JavaScript 6.6%
Shell 5.3%
Batchfile 1.3%
Other 1.2%