Compare commits

...

8 Commits
v4.3 ... v4.4

Author SHA1 Message Date
cexll
b5183c7711 update gemini skills 2025-11-22 14:56:31 +08:00
cexll
3fab18a6bb update dev workflow 2025-11-22 13:18:38 +08:00
cexll
12af992d8c fix codex skill timeout and add more log 2025-11-20 20:28:44 +08:00
cexll
bbd2f50c38 update codex skills model config 2025-11-19 23:57:52 +08:00
cexll
3f7652f992 Merge branch 'master' of github.com:cexll/myclaude 2025-11-19 23:06:43 +08:00
cexll
2cbe36b532 fix codex skill 2025-11-19 23:06:37 +08:00
cexll
fdb152872d Merge pull request #24 from cexll/swe-agent/23-1763544297
feat: 支持通过环境变量配置 skills 模型
2025-11-19 21:35:27 +08:00
swe-agent[bot]
916b970665 feat: 支持通过环境变量配置 skills 模型
- 新增 CODEX_MODEL 环境变量覆盖 codex 默认模型
- 新增 GEMINI_MODEL 环境变量覆盖 gemini 默认模型
- 更新文档说明环境变量用法
- 保持向后兼容,未设置环境变量时使用原默认值

修复 #23

Generated by swe-agent
2025-11-19 09:27:15 +00:00
5 changed files with 122 additions and 121 deletions

View File

@@ -42,7 +42,7 @@ You are the /dev Workflow Orchestrator, an expert development workflow manager s
- Extract core functionality, technical key points, and 2-5 parallelizable tasks with full metadata
- **Step 3: Generate Development Documentation**
- Use Task tool to invoke develop-doc-generator:
- invoke agent dev-plan-generator:
```
基于以下分析结果生成开发文档:

View File

@@ -14,27 +14,32 @@ Execute Codex CLI commands and parse structured JSON responses. Supports file re
- Complex code analysis requiring deep understanding
- Large-scale refactoring across multiple files
- Automated code generation with safety controls
- Tasks requiring specialized reasoning models (gpt-5.1, gpt-5.1-codex)
## Usage
**Mandatory**: Run every automated invocation through the Bash tool in the foreground with the command below, keeping the `timeout` parameter fixed at `7200000` milliseconds (do not change it or use any other entry point).
```bash
uv run ~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
uv run ~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
```
**Foreground only (no background/BashOutput)**: Never set `background: true`, never accept Claude's “Running in the background” mode, and avoid `BashOutput` streaming loops. Keep a single foreground Bash call per Codex task; if work might be long, split it into smaller foreground runs instead of offloading to background execution.
**Optional methods** (direct execution or via Python):
```bash
~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
# or
python3 ~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
python3 ~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
```
Resume a session:
```bash
uv run ~/.claude/skills/codex/scripts/codex.py resume <session_id> "<task>" [model] [working_dir]
uv run ~/.claude/skills/codex/scripts/codex.py resume <session_id> "<task>" [working_dir]
```
## Environment Variables
- **CODEX_TIMEOUT**: Override timeout in milliseconds (default: 7200000 = 2 hours)
- Example: `export CODEX_TIMEOUT=3600000` for 1 hour
## Timeout Control
- **Built-in**: Script enforces 2-hour timeout by default
@@ -46,9 +51,6 @@ uv run ~/.claude/skills/codex/scripts/codex.py resume <session_id> "<task>" [mod
### Parameters
- `task` (required): Task description, supports `@file` references
- `model` (optional): Model to use (default: gpt-5.1-codex)
- `gpt-5.1-codex`: Default, optimized for code
- `gpt-5.1`: Fast general purpose
- `working_dir` (optional): Working directory (default: current)
### Return Format
@@ -66,12 +68,14 @@ Error format (stderr):
ERROR: Error message
```
Return only the final agent message and session ID—do not paste raw `BashOutput` logs or background-task chatter into the conversation.
### Invocation Pattern
All automated executions may only invoke `uv run ~/.claude/skills/codex/scripts/codex.py "<task>" ...` through the Bash tool in the foreground, and the `timeout` must remain fixed at `7200000` (non-negotiable):
```
Bash tool parameters:
- command: uv run ~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
- command: uv run ~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
- timeout: 7200000
- description: <brief description of the task>
```
@@ -80,10 +84,10 @@ Run every call in the foreground—never append `&` to background it—so logs a
Alternatives:
```
# Direct execution (simplest)
- command: ~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
- command: ~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
# Using python3
- command: python3 ~/.claude/skills/codex/scripts/codex.py "<task>" [model] [working_dir]
- command: python3 ~/.claude/skills/codex/scripts/codex.py "<task>" [working_dir]
```
### Examples
@@ -98,22 +102,23 @@ uv run ~/.claude/skills/codex/scripts/codex.py "explain @src/main.ts"
~/.claude/skills/codex/scripts/codex.py "explain @src/main.ts"
```
**Refactoring with specific model:**
**Refactoring with custom model (via environment variable):**
```bash
uv run ~/.claude/skills/codex/scripts/codex.py "refactor @src/utils for performance" "gpt-5.1-codex"
# Set model via environment variable
uv run ~/.claude/skills/codex/scripts/codex.py "refactor @src/utils for performance"
# timeout: 7200000
```
**Multi-file analysis:**
```bash
uv run ~/.claude/skills/codex/scripts/codex.py "analyze @. and find security issues" "gpt-5.1-codex" "/path/to/project"
uv run ~/.claude/skills/codex/scripts/codex.py "analyze @. and find security issues" "/path/to/project"
# timeout: 7200000
```
**Resume previous session:**
```bash
# First session
uv run ~/.claude/skills/codex/scripts/codex.py "add comments to @utils.js" "gpt-5.1-codex"
uv run ~/.claude/skills/codex/scripts/codex.py "add comments to @utils.js"
# Output includes: SESSION_ID: 019a7247-ac9d-71f3-89e2-a823dbd8fd14
# Continue the conversation

View File

@@ -8,10 +8,12 @@ Codex CLI wrapper with cross-platform support and session management.
**FIXED**: Auto-detect long inputs and use stdin mode to avoid shell argument issues.
Usage:
New session: uv run codex.py "task" [model] [workdir]
Resume: uv run codex.py resume <session_id> "task" [model] [workdir]
New session: uv run codex.py "task" [workdir]
Resume: uv run codex.py resume <session_id> "task" [workdir]
Alternative: python3 codex.py "task"
Direct exec: ./codex.py "task"
Model configuration: Set CODEX_MODEL environment variable (default: gpt-5.1-codex)
"""
import subprocess
import json
@@ -19,7 +21,7 @@ import sys
import os
from typing import Optional
DEFAULT_MODEL = 'gpt-5.1-codex'
DEFAULT_MODEL = os.environ.get('CODEX_MODEL', 'gpt-5.1-codex')
DEFAULT_WORKDIR = '.'
DEFAULT_TIMEOUT = 7200 # 2 hours in seconds
FORCE_KILL_DELAY = 5
@@ -82,15 +84,13 @@ def parse_args():
'mode': 'resume',
'session_id': sys.argv[2],
'task': sys.argv[3],
'model': sys.argv[4] if len(sys.argv) > 4 else DEFAULT_MODEL,
'workdir': sys.argv[5] if len(sys.argv) > 5 else DEFAULT_WORKDIR
'workdir': sys.argv[4] if len(sys.argv) > 4 else DEFAULT_WORKDIR
}
else:
return {
'mode': 'new',
'task': sys.argv[1],
'model': sys.argv[2] if len(sys.argv) > 2 else DEFAULT_MODEL,
'workdir': sys.argv[3] if len(sys.argv) > 3 else DEFAULT_WORKDIR
'workdir': sys.argv[2] if len(sys.argv) > 2 else DEFAULT_WORKDIR
}
@@ -100,11 +100,27 @@ def read_piped_task() -> Optional[str]:
- 如果 stdin 是管道(非 tty且存在内容返回读取到的字符串
- 否则返回 None
"""
import select
stdin = sys.stdin
if stdin is None or stdin.isatty():
log_info("Stdin is tty or None, skipping pipe read")
return None
# 使用 select 检查是否有数据可读0 秒超时,非阻塞)
readable, _, _ = select.select([stdin], [], [], 0)
if not readable:
log_info("No data available on stdin")
return None
log_info("Reading from stdin pipe...")
data = stdin.read()
return data if data else None
if not data:
log_info("Stdin pipe returned empty data")
return None
log_info(f"Read {len(data)} bytes from stdin pipe")
return data
def should_stream_via_stdin(task_text: str, piped: bool) -> bool:
@@ -146,7 +162,7 @@ def build_codex_args(params: dict, target_arg: str) -> list:
else:
base_args = [
'codex', 'e',
'-m', params['model'],
'-m', DEFAULT_MODEL,
'--dangerously-bypass-approvals-and-sandbox',
'--skip-git-repo-check',
'-C', params['workdir'],
@@ -168,6 +184,7 @@ def run_codex_process(codex_args, task_text: str, use_stdin: bool, timeout_sec:
try:
# 启动 codex 子进程(文本模式管道)
log_info(f"Starting codex with args: {' '.join(codex_args[:5])}...")
process = subprocess.Popen(
codex_args,
stdin=subprocess.PIPE if use_stdin else None,
@@ -176,17 +193,23 @@ def run_codex_process(codex_args, task_text: str, use_stdin: bool, timeout_sec:
text=True,
bufsize=1,
)
log_info(f"Process started with PID: {process.pid}")
# 如果使用 stdin 模式,写入任务到 stdin 并关闭
if use_stdin and process.stdin is not None:
log_info(f"Writing {len(task_text)} chars to stdin...")
process.stdin.write(task_text)
process.stdin.flush() # 强制刷新缓冲区,避免大任务死锁
process.stdin.close()
log_info("Stdin closed")
# 逐行解析 JSON 输出
if process.stdout is None:
log_error('Codex stdout pipe not available')
sys.exit(1)
log_info("Reading stdout...")
for line in process.stdout:
line = line.strip()
if not line:
@@ -247,8 +270,11 @@ def run_codex_process(codex_args, task_text: str, use_stdin: bool, timeout_sec:
def main():
log_info("Script started")
params = parse_args()
log_info(f"Parsed args: mode={params['mode']}, task_len={len(params['task'])}")
timeout_sec = resolve_timeout()
log_info(f"Timeout: {timeout_sec}s")
piped_task = read_piped_task()
piped = piped_task is not None

View File

@@ -17,31 +17,32 @@ Execute Gemini CLI commands with support for multiple models and flexible prompt
- Alternative perspective on code problems
## Usage
**推荐方式**(使用 uv run自动管理 Python 环境):
**Mandatory**: Run via uv with fixed timeout 7200000ms (foreground):
```bash
uv run ~/.claude/skills/gemini/scripts/gemini.py -m <model> -p "<prompt>" [working_dir]
uv run ~/.claude/skills/gemini/scripts/gemini.py "<prompt>" [working_dir]
```
**备选方式**(直接执行或使用 Python
**Optional** (direct execution or using Python):
```bash
~/.claude/skills/gemini/scripts/gemini.py -m <model> -p "<prompt>" [working_dir]
#
python3 ~/.claude/skills/gemini/scripts/gemini.py -m <model> -p "<prompt>" [working_dir]
~/.claude/skills/gemini/scripts/gemini.py "<prompt>" [working_dir]
# or
python3 ~/.claude/skills/gemini/scripts/gemini.py "<prompt>" [working_dir]
```
## Environment Variables
- **GEMINI_MODEL**: Configure model (default: `gemini-3-pro-preview`)
- Example: `export GEMINI_MODEL=gemini-3`
## Timeout Control
- **Built-in**: Script enforces 2-hour timeout by default
- **Override**: Set `GEMINI_TIMEOUT` environment variable (in milliseconds)
- **Bash tool**: Always set `timeout: 7200000` parameter for double protection
- **Fixed**: 7200000 milliseconds (2 hours), immutable
- **Bash tool**: Always set `timeout: 7200000` for double protection
### Parameters
- `-m, --model` (optional): Model to use (default: gemini-3-pro-preview)
- `gemini-3-pro-preview`: Latest flagship model
- `-p, --prompt` (required): Task prompt or question
- `working_dir` (optional): Working directory (default: current)
- `prompt` (required): Task prompt or question
- `working_dir` (optional): Working directory (default: current directory)
### Return Format
@@ -63,7 +64,7 @@ When calling via Bash tool, always include the timeout parameter:
```yaml
Bash tool parameters:
- command: uv run ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "<prompt>"
- command: uv run ~/.claude/skills/gemini/scripts/gemini.py "<prompt>"
- timeout: 7200000
- description: <brief description of the task>
```
@@ -72,10 +73,10 @@ Alternatives:
```yaml
# Direct execution (simplest)
- command: ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "<prompt>"
- command: ~/.claude/skills/gemini/scripts/gemini.py "<prompt>"
# Using python3
- command: python3 ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "<prompt>"
- command: python3 ~/.claude/skills/gemini/scripts/gemini.py "<prompt>"
```
### Examples
@@ -83,39 +84,28 @@ Alternatives:
**Basic query:**
```bash
# Recommended: via uv run
uv run ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "explain quantum computing"
uv run ~/.claude/skills/gemini/scripts/gemini.py "explain quantum computing"
# timeout: 7200000
# Alternative: direct execution
~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "explain quantum computing"
```
**Code analysis:**
```bash
uv run ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "review this code for security issues: $(cat app.py)"
uv run ~/.claude/skills/gemini/scripts/gemini.py "review this code for security issues: $(cat app.py)"
# timeout: 7200000
```
**With specific working directory:**
```bash
uv run ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "analyze project structure" "/path/to/project"
# timeout: 7200000
```
**Using fast model:**
```bash
uv run ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "quick code suggestion"
uv run ~/.claude/skills/gemini/scripts/gemini.py "analyze project structure" "/path/to/project"
# timeout: 7200000
```
**Using python3 directly (alternative):**
```bash
python3 ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "your prompt here"
python3 ~/.claude/skills/gemini/scripts/gemini.py "your prompt here"
```
## Notes
@@ -126,5 +116,5 @@ python3 ~/.claude/skills/gemini/scripts/gemini.py -m gemini-3-pro-preview -p "yo
- Cross-platform compatible (Windows/macOS/Linux)
- PEP 723 compliant (inline script metadata)
- Requires Gemini CLI installed and authenticated
- Supports all Gemini model variants
- Supports all Gemini model variants (configure via `GEMINI_MODEL` environment variable)
- Output is streamed directly from Gemini CLI

View File

@@ -7,18 +7,18 @@
Gemini CLI wrapper with cross-platform support.
Usage:
uv run gemini.py -m <model> -p "<prompt>" [workdir]
python3 gemini.py -m <model> -p "<prompt>"
./gemini.py -m gemini-3-pro-preview -p "your prompt"
uv run gemini.py "<prompt>" [workdir]
python3 gemini.py "<prompt>"
./gemini.py "your prompt"
"""
import subprocess
import sys
import os
import argparse
DEFAULT_MODEL = 'gemini-3-pro-preview'
DEFAULT_MODEL = os.environ.get('GEMINI_MODEL', 'gemini-3-pro-preview')
DEFAULT_WORKDIR = '.'
DEFAULT_TIMEOUT = 7200 # 2 hours in seconds
TIMEOUT_MS = 7_200_000 # 固定 2 小时,毫秒
DEFAULT_TIMEOUT = TIMEOUT_MS // 1000
FORCE_KILL_DELAY = 5
@@ -32,76 +32,56 @@ def log_warn(message: str):
sys.stderr.write(f"WARN: {message}\n")
def resolve_timeout() -> int:
"""解析超时配置(秒)"""
raw = os.environ.get('GEMINI_TIMEOUT', '')
if not raw:
return DEFAULT_TIMEOUT
try:
parsed = int(raw)
if parsed <= 0:
log_warn(f"Invalid GEMINI_TIMEOUT '{raw}', falling back to {DEFAULT_TIMEOUT}s")
return DEFAULT_TIMEOUT
# 环境变量是毫秒,转换为秒
return parsed // 1000 if parsed > 10000 else parsed
except ValueError:
log_warn(f"Invalid GEMINI_TIMEOUT '{raw}', falling back to {DEFAULT_TIMEOUT}s")
return DEFAULT_TIMEOUT
def log_info(message: str):
"""输出信息到 stderr"""
sys.stderr.write(f"INFO: {message}\n")
def parse_args():
"""解析命令行参数"""
parser = argparse.ArgumentParser(
description='Gemini CLI wrapper for Claude Code integration',
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
'-m', '--model',
default=DEFAULT_MODEL,
help=f'Gemini model to use (default: {DEFAULT_MODEL})'
)
parser.add_argument(
'-p', '--prompt',
required=True,
help='Prompt to send to Gemini'
)
parser.add_argument(
'workdir',
nargs='?',
default=DEFAULT_WORKDIR,
help='Working directory (default: current directory)'
)
"""解析位置参数"""
if len(sys.argv) < 2:
log_error('Prompt required')
sys.exit(1)
return parser.parse_args()
return {
'prompt': sys.argv[1],
'workdir': sys.argv[2] if len(sys.argv) > 2 else DEFAULT_WORKDIR
}
def build_gemini_args(args) -> list:
"""构建 gemini CLI 参数"""
return [
'gemini',
'-m', args.model,
'-p', args.prompt
'-m', DEFAULT_MODEL,
'-p', args['prompt']
]
def main():
log_info('Script started')
args = parse_args()
log_info(f"Prompt length: {len(args['prompt'])}")
log_info(f"Working dir: {args['workdir']}")
gemini_args = build_gemini_args(args)
timeout_sec = resolve_timeout()
timeout_sec = DEFAULT_TIMEOUT
log_info(f"Timeout: {timeout_sec}s")
# 如果指定了工作目录,切换到该目录
if args.workdir != DEFAULT_WORKDIR:
if args['workdir'] != DEFAULT_WORKDIR:
try:
os.chdir(args.workdir)
os.chdir(args['workdir'])
except FileNotFoundError:
log_error(f"Working directory not found: {args.workdir}")
log_error(f"Working directory not found: {args['workdir']}")
sys.exit(1)
except PermissionError:
log_error(f"Permission denied: {args.workdir}")
log_error(f"Permission denied: {args['workdir']}")
sys.exit(1)
log_info('Changed working directory')
try:
log_info(f"Starting gemini with model {DEFAULT_MODEL}")
process = None
# 启动 gemini 子进程,直接透传 stdout 和 stderr
process = subprocess.Popen(
gemini_args,
@@ -112,11 +92,9 @@ def main():
)
# 实时输出 stdout
stdout_lines = []
for line in process.stdout:
sys.stdout.write(line)
sys.stdout.flush()
stdout_lines.append(line)
# 等待进程结束
returncode = process.wait(timeout=timeout_sec)
@@ -135,11 +113,12 @@ def main():
except subprocess.TimeoutExpired:
log_error(f'Gemini execution timeout ({timeout_sec}s)')
process.kill()
try:
process.wait(timeout=FORCE_KILL_DELAY)
except subprocess.TimeoutExpired:
pass
if process is not None:
process.kill()
try:
process.wait(timeout=FORCE_KILL_DELAY)
except subprocess.TimeoutExpired:
pass
sys.exit(124)
except FileNotFoundError:
@@ -148,11 +127,12 @@ def main():
sys.exit(127)
except KeyboardInterrupt:
process.terminate()
try:
process.wait(timeout=FORCE_KILL_DELAY)
except subprocess.TimeoutExpired:
process.kill()
if process is not None:
process.terminate()
try:
process.wait(timeout=FORCE_KILL_DELAY)
except subprocess.TimeoutExpired:
process.kill()
sys.exit(130)