fix(codex-wrapper): improve --parallel parameter validation and docs

修复问题:
- codex-wrapper --parallel 模式缺少参数验证,用户误传额外参数导致 shell 解析错误
- 文档中缺少正确 vs 错误用法对比,容易误导用户

主要改进:

1. codex-wrapper/main.go:
   - 添加 --parallel 参数验证 (366-373行)
   - 当检测到额外参数时,输出清晰的错误提示和正确用法示例
   - 更新 --help 文档,添加 --parallel 使用说明

2. skills/codex/SKILL.md:
   - 添加重要提示框,明确 --parallel 只从 stdin 读取配置
   - 新增"正确 vs 错误用法"对比部分,包含3种常见错误示例
   - 修复所有示例中多余的 `-` 参数
   - 在 Delimiter Format 部分强调 workdir 的正确用法

测试验证:
-  所有单元测试通过
-  参数验证功能正常
-  并行执行功能正常
-  中文内容解析正常

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cexll
2025-12-01 16:18:36 +08:00
parent 9fa872a1f0
commit 06f14aa695
3 changed files with 58 additions and 3 deletions

BIN
codex-wrapper/codex-wrapper Executable file

Binary file not shown.

View File

@@ -363,6 +363,14 @@ func run() int {
printHelp()
return 0
case "--parallel":
if len(os.Args) > 2 {
fmt.Fprintln(os.Stderr, "ERROR: --parallel reads its task configuration from stdin and does not accept additional arguments.")
fmt.Fprintln(os.Stderr, "Usage examples:")
fmt.Fprintln(os.Stderr, " codex-wrapper --parallel < tasks.txt")
fmt.Fprintln(os.Stderr, " echo '...' | codex-wrapper --parallel")
fmt.Fprintln(os.Stderr, " codex-wrapper --parallel <<'EOF'")
return 1
}
// Parallel mode: read task config from stdin
data, err := io.ReadAll(stdinReader)
if err != nil {
@@ -888,9 +896,15 @@ Usage:
codex-wrapper - [workdir] Read task from stdin
codex-wrapper resume <session_id> "task" [workdir]
codex-wrapper resume <session_id> - [workdir]
codex-wrapper --parallel Run tasks in parallel (config from stdin)
codex-wrapper --version
codex-wrapper --help
Parallel mode examples:
codex-wrapper --parallel < tasks.txt
echo '...' | codex-wrapper --parallel
codex-wrapper --parallel <<'EOF'
Environment Variables:
CODEX_TIMEOUT Timeout in milliseconds (default: 7200000)

View File

@@ -180,11 +180,50 @@ EOF
### Parallel Execution
> Important:
> - `--parallel` only reads task definitions from stdin.
> - It does not accept extra command-line arguments (no inline `workdir`, `task`, or other params).
> - Put all task metadata and content in stdin; nothing belongs after `--parallel` on the command line.
**Correct vs Incorrect Usage**
**Correct:**
```bash
# Option 1: file redirection
codex-wrapper --parallel < tasks.txt
# Option 2: heredoc (recommended for multiple tasks)
codex-wrapper --parallel <<'EOF'
---TASK---
id: task1
workdir: /path/to/dir
---CONTENT---
task content
EOF
# Option 3: pipe
echo "---TASK---..." | codex-wrapper --parallel
```
**Incorrect (will trigger shell parsing errors):**
```bash
# ❌ Wrong: no extra args allowed after --parallel
codex-wrapper --parallel - /path/to/dir <<'EOF'
...
EOF
# ❌ Wrong: --parallel does not take a task argument
codex-wrapper --parallel "task description"
# ❌ Wrong: workdir must live inside the task config
codex-wrapper --parallel /path/to/dir < tasks.txt
```
For multiple independent or dependent tasks, use `--parallel` mode with delimiter format:
**Typical Workflow (analyze → implement → test, chained in a single parallel call)**:
```bash
codex-wrapper --parallel - <<'EOF'
codex-wrapper --parallel <<'EOF'
---TASK---
id: analyze_1732876800
workdir: /home/user/project
@@ -207,7 +246,7 @@ EOF
A single `codex-wrapper --parallel` call schedules all three stages concurrently, using `dependencies` to enforce sequential ordering without multiple invocations.
```bash
codex-wrapper --parallel - <<'EOF'
codex-wrapper --parallel <<'EOF'
---TASK---
id: backend_1732876800
workdir: /home/user/project/backend
@@ -235,6 +274,8 @@ EOF
- `workdir: <path>`: Optional, working directory (default: `.`)
- Best practice: use absolute paths (e.g., `/home/user/project/backend`)
- Avoids ambiguity and ensures consistent behavior across environments
- Must be specified inside each task block; do not pass `workdir` as a CLI argument to `--parallel`
- Each task can set its own `workdir` when different directories are needed
- `dependencies: <id1>, <id2>`: Optional, comma-separated task IDs
- `session_id: <uuid>`: Optional, resume a previous session
- `---CONTENT---`: Separates metadata from task content
@@ -249,7 +290,7 @@ EOF
**Resume Failed Tasks**:
```bash
# Use session_id from previous output to resume
codex-wrapper --parallel - <<'EOF'
codex-wrapper --parallel <<'EOF'
---TASK---
id: T2
session_id: 019xxx-previous-session-id