Skill: inuyashayang/codex-tmux (version 1.0.0)

--- name: codex-tmux description: > Launch long-running Codex (or Claude Code) coding tasks via tmux on WSL2/Linux, bypassing SIGTERM timeouts. Use this skill INSTEAD OF coding-agent whenever: (1) the task may take >60s, (2) you need full-auto Codex execution, (3) you are on WSL2 with a custom OpenAI-compatible proxy (OPENAI_BASE_URL), (4) you want to monitor/steer a background Codex session mid-run, (5) building or extending the MyClaw project, (6) any multi-file code generation task. This skill has higher priority than coding-agent for Codex full-auto workflows on this machine. Triggers: codex tmux, long task, full-auto, MyClaw, background codex, WSL2 coding agent. --- # Codex via tmux (WSL2 / Custom Proxy) Preferred pattern for all Codex full-auto tasks on this machine. Avoids SIGTERM, supports mid-run steering. ## Environment (this machine) ```bash OPENAI_API_KEY="[REDACTED_SECRET]" OPENAI_BASE_URL="http://152.53.52.170:3003/v1" ``` Always pass both vars. Do NOT rely on shell inheritance — OpenClaw subprocesses don't source `.bashrc`. ## Standard Launch Pattern ```bash SESSION="codex-<feature>" # e.g. codex-auth, codex-tools WORKDIR=~/MyClaw # or target repo tmux new-session -d -s "$SESSION" -c "$WORKDIR" \ "OPENAI_API_KEY='sk-5Ds6e...' OPENAI_BASE_URL='http://152.53.52.170:3003/v1' \ codex --model gpt-5.3-codex --full-auto '$(cat /tmp/task.txt)'" ``` Write long prompts to `/tmp/task.txt` first, then reference via `$(cat /tmp/task.txt)`. ## Monitoring ```bash # Check if alive tmux has-session -t "$SESSION" 2>/dev/null && echo running || echo done # Tail output (last 50 lines) tmux capture-pane -t "$SESSION" -p | tail -50 # Or via OpenClaw exec: exec("tmux capture-pane -t codex-auth -p | tail -30") ``` ## Mid-run Steering ```bash tmux send-keys -t "$SESSION" "停一下。先做 API 层，不要改 UI。" Enter tmux send-keys -t "$SESSION" "类型定义在 src/types.ts，用那个。" Enter ``` ## Task JSON Tracking Write to `/tmp/codex-tasks.json` to track parallel jobs: ```json { "id": "feat-tools", "session": "codex-tools", "model": "gpt-5.3-codex", "desc": "实现工具系统 exec/read/write/web_fetch", "repo": "MyClaw", "startedAt": 1772433000000, "status": "running" } ``` ## Completion Check Poll every 2–3 min via: ```bash tmux has-session -t "$SESSION" 2>/dev/null || echo "DONE" git -C "$WORKDIR" log --oneline -3 ``` Codex "完成" = tmux session 自动退出 + git commit 存在。 ## Cleanup ```bash tmux kill-session -t "$SESSION" 2>/dev/null git worktree prune ``` ## MyClaw-Specific Notes - Repo: `~/MyClaw`, GitHub: https://github.com/InuyashaYang/MyClaw - 模型首选 `gpt-5.3-codex`，轻量测试用 `gpt-4.1-mini` - 详细已知坑见 → `references/lessons.md`

path: references/lessons.md
content: # Lessons Learned — Codex on WSL2

## 已知坑

### 1. SIGTERM（最常见）
**现象：** Codex 写文件到一半被 kill，退出码 124/143。
**原因：** OpenClaw exec 工具有超时上限，Codex PTY 进程被 SIGTERM。
**解法：** 用 tmux 托管（见 SKILL.md），OpenClaw 只负责 `tmux new-session`，不持有进程。

### 2. 环境变量未继承
**现象：** `codex exec` 报 401 Unauthorized。
**原因：** 非交互 shell 不 source `.bashrc`，OPENAI_BASE_URL 丢失，直连官方 API。
**解法：** 每次显式传 `OPENAI_API_KEY` + `OPENAI_BASE_URL`，或写入 `~/.profile`（登录 shell 继承）。

### 3. TypeScript 模板字符串嵌套
**现象：** `WebchatProvider.ts` 编译报 "Unterminated template literal"。
**原因：** 内嵌 HTML 字符串用了 TS template literal，HTML 里的 JS `${var}` 被误解析。
**解法：** 内嵌 HTML 里的动态部分改成字符串拼接：`'msg ' + type`，而非 `` `msg ${type}` ``。

### 4. @fastify/websocket 版本冲突
**现象：** 启动报 `expected '^4.x' fastify version, '5.x' is installed`。
**原因：** Codex 装了 Fastify v5，但旧版 `@fastify/websocket` 只支持 v4。
**解法：** `npm install @fastify/websocket@latest`，已在 package.json 固定，一次性问题。

### 5. codex exec vs codex interactive
**现象：** `codex exec --skip-git-repo-check` 在非 git 目录报错。
**解法：** 总是在 git repo 内运行，或加 `--skip-git-repo-check`。
**注意：** `codex exec` 适合单次无状态任务；复杂多步任务用 `codex --full-auto`（交互模式）via tmux。

## 模型选择

| 任务 | 模型 |
|------|------|
| 后端逻辑、多文件重构 | `gpt-5.3-codex` |
| 快速测试、验证连通性 | `gpt-4.1-mini` |
| 前端 UI 原型 | `gpt-5.3-codex` + 明确说明组件库 |

## MyClaw 项目上下文

- 路径：`~/MyClaw`
- GitHub：https://github.com/InuyashaYang/MyClaw
- Phase 1 完成：Webchat + LLM streaming（TypeScript + Fastify + Vercel AI SDK）
- Phase 2 待做：工具系统（exec/read/write/web_fetch）+ Memory 注入 + Ask 确认
- Phase 3 待做：Telegram Provider + SQLite 持久化
- Phase 4 待做：Skills 加载器


Security scan verdicts — ClawScan: suspicious | static analysis:  | VirusTotal: malicious | SkillSpector: suspicious (CRITICAL)