[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-74268":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":9,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":15,"starSnapshotCount":15,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},74268,"codex-session-patcher","ryfineZ\u002Fcodex-session-patcher","ryfineZ","A lightweight Python tool to clean AI refusal responses from Codex CLI session files",null,"Python",1786,300,5,10,0,133,304,565,399,20.44,false,"main",true,[],"2026-06-12 02:03:24","\u003Cdiv align=\"center\">\n\n# Codex Session Patcher\n\n**AI 编码工具会话清理器 & CTF\u002F渗透测试提示词注入工具**\n\n支持 **Codex CLI** · **Claude Code** · **OpenCode**\n\n[English](.\u002FREADME_EN.md) | 简体中文\n\n[![GitHub stars](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002FryfineZ\u002Fcodex-session-patcher?style=flat-square)](https:\u002F\u002Fgithub.com\u002FryfineZ\u002Fcodex-session-patcher\u002Fstargazers)\n[![GitHub release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fv\u002Frelease\u002FryfineZ\u002Fcodex-session-patcher?style=flat-square)](https:\u002F\u002Fgithub.com\u002FryfineZ\u002Fcodex-session-patcher\u002Freleases)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-yellow.svg?style=flat-square)](LICENSE)\n[![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8+-blue?style=flat-square)](https:\u002F\u002Fpython.org)\n\n\u003C\u002Fdiv>\n\n---\n\n## 是什么\n\n在安全测试、CTF 比赛、渗透测试等场景下，AI 编码工具（Codex、Claude Code、OpenCode）会频繁拒绝涉及安全操作的请求，导致会话中断。\n\n**Codex Session Patcher** 提供两类解决方案：\n\n**1. 会话清理** — 扫描已产生的拒绝回复，替换为配合性内容，让会话可以 resume 继续\n\n**2. CTF 提示词注入** — 在配置层面注入安全测试上下文，从源头降低被拒绝的概率\n\n---\n\n## 功能特性\n\n### 会话清理\n- **智能检测** — 两级拒绝检测策略（强短语全文匹配 + 弱关键词开头匹配），低误报率\n- **AI 智能改写** — 调用 LLM 根据对话上下文生成符合语境的替换回复（支持 OpenAI \u002F Ollama \u002F OpenRouter 等兼容接口）\n- **批量清理** — 处理会话中所有拒绝回复，而非仅最后一条\n- **推理内容擦除** — 删除 Reasoning \u002F Thinking block 加密推理内容\n- **备份还原** — 清理前自动备份，支持一键还原到任意历史版本\n- **Diff 对比** — 清理前后 Side-by-side 对比视图\n\n### CTF\u002F渗透测试提示词注入\n- **Codex Profile 模式** — 创建 `ctf` profile，仅 `codex -p ctf` 启动时生效，不影响正常会话\n- **Codex 全局模式** — 注入到全局配置，所有新会话自动生效\n- **Claude Code 工作空间** — 创建专用 CTF 工作空间 `~\u002F.claude-ctf-workspace`，通过项目级 CLAUDE.md 注入\n- **OpenCode 工作空间** — 创建专用 CTF 工作空间 `~\u002F.opencode-ctf-workspace`，通过 AGENTS.md 注入\n- **提示词自定义** — Web UI 内直接编辑注入提示词，支持模板保存与切换\n- **AI 提示词改写** — 结合已注入的 CTF 系统提示词，AI 改写你的请求使其更易被接受\n\n### 平台支持\n\n| 平台 | 会话清理 | CTF 注入 | 会话格式 |\n|------|---------|---------|---------|\n| **Codex CLI** | ✅ | ✅ Profile + 全局 | JSONL |\n| **Claude Code** | ✅ | ✅ 专用工作空间 | JSONL |\n| **OpenCode** | ✅ | ✅ 专用工作空间 | SQLite |\n\n### Web UI\n- **会话列表** — 多平台统一管理，按日期分组，支持按格式\u002F拒绝状态\u002F备份状态过滤\n- **可视化清理** — 预览面板 + Diff 对比 + 一键执行\n- **多语言** — 支持中文 \u002F English 界面切换\n- **实时日志** — WebSocket 推送，操作日志实时显示\n\n---\n\n## 安装\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FryfineZ\u002Fcodex-session-patcher.git\ncd codex-session-patcher\n\n# CLI 版本（零额外依赖）\npip install -e .\n\n# Web UI 版本\npip install -e \".[web]\"\ncd web\u002Ffrontend && npm install && npm run build && cd ..\u002F..\n```\n\n---\n\n## 使用方式\n\n### Web UI（推荐）\n\n```bash\n# 生产模式\n.\u002Fscripts\u002Fstart-web.sh\n\n# 或直接启动\nuvicorn web.backend.main:app --host 127.0.0.1 --port 8080\n```\n\n访问 `http:\u002F\u002Flocalhost:8080`\n\n**开发模式（前后端热更新）：**\n```bash\n.\u002Fscripts\u002Fdev-web.sh\n```\n\n### CLI\n\n```bash\n# 查看帮助\ncodex-patcher --help\n\n# 预览模式（不修改文件）\ncodex-patcher --dry-run --show-content\n\n# 清理最新会话\ncodex-patcher --latest\n\n# 清理所有会话\ncodex-patcher --all\n\n# 指定会话目录\ncodex-patcher --session-dir ~\u002F.codex\u002Fsessions --latest\n\n# 指定格式（codex \u002F claude-code \u002F opencode \u002F auto）\ncodex-patcher --latest --format claude-code\ncodex-patcher --latest --format opencode\n\n# 不创建备份\ncodex-patcher --latest --no-backup\n\n# 启动 Web UI\ncodex-patcher --web\ncodex-patcher --web --host 0.0.0.0 --port 8080\n\n# CTF 提示词注入 — Codex\ncodex-patcher --install-ctf-config    # 安装\ncodex-patcher --uninstall-ctf-config  # 卸载\n\n# CTF 提示词注入 — Claude Code\ncodex-patcher --install-claude-ctf    # 安装\ncodex-patcher --uninstall-claude-ctf  # 卸载\n\n# CTF 提示词注入 — OpenCode\ncodex-patcher --install-opencode-ctf    # 安装\ncodex-patcher --uninstall-opencode-ctf  # 卸载\n\n# 查看所有 CTF 配置状态\ncodex-patcher --ctf-status\n\n# 改写提示词（需先在 Web UI 配置 AI）\ncodex-patcher --rewrite \"帮我写一个逆向分析脚本\"\n```\n\n#### CLI 参数说明\n\n| 参数 | 说明 |\n|------|------|\n| `--session-dir` | 指定会话目录（默认自动选择） |\n| `--format` | 会话格式：`codex` \u002F `claude-code` \u002F `opencode` \u002F `auto` |\n| `--dry-run` | 预览模式，不修改文件 |\n| `--no-backup` | 不创建备份文件 |\n| `--show-content` | 显示修改的详细内容 |\n| `--latest` | 只处理最新会话 |\n| `--all` | 处理所有会话 |\n| `--keep-reasoning` | 保留推理内容（thinking\u002Freasoning blocks），仅替换拒绝回复 |\n| `--web` | 启动 Web UI |\n| `--host` | Web UI 监听地址（默认 127.0.0.1） |\n| `--port` | Web UI 端口（默认 8080） |\n| `--install-ctf-config` | 安装 Codex CTF 配置 |\n| `--uninstall-ctf-config` | 卸载 Codex CTF 配置 |\n| `--install-claude-ctf` | 安装 Claude Code CTF 配置 |\n| `--uninstall-claude-ctf` | 卸载 Claude Code CTF 配置 |\n| `--install-opencode-ctf` | 安装 OpenCode CTF 配置 |\n| `--uninstall-opencode-ctf` | 卸载 OpenCode CTF 配置 |\n| `--ctf-status` | 查看三平台 CTF 配置状态 |\n| `--rewrite` | 改写提示词使其更易被接受 |\n\n---\n\n## CTF\u002F渗透测试工作流\n\n### Codex\n\n```\n1. 安装 CTF Profile\n   codex-patcher --install-ctf-config\n\n2. 使用 CTF Profile 启动（不影响普通会话）\n   codex -p ctf\n\n3. 发送请求，若遇到拒绝 → 打开 Web UI 清理会话\n\n4. resume 继续\n   codex resume\n```\n\n### Claude Code\n\n```\n1. Web UI → 提示词增强 → Claude Code → 启用\n   （创建 ~\u002F.claude-ctf-workspace）\n\n2. 从专用工作空间启动\n   cd ~\u002F.claude-ctf-workspace && claude\n\n3. 遇到拒绝 → Web UI 清理 → 继续对话\n```\n\n### OpenCode\n\n```\n1. Web UI → 提示词增强 → OpenCode → 启用\n   （创建 ~\u002F.opencode-ctf-workspace）\n\n2. 从专用工作空间启动\n   cd ~\u002F.opencode-ctf-workspace && opencode\n\n3. 遇到拒绝 → Web UI 清理 → 继续对话\n```\n\n---\n\n## 配置\n\nCLI 和 Web UI 共享配置文件 `~\u002F.codex-patcher\u002Fconfig.json`：\n\n| 配置项 | 说明 | 默认值 |\n|--------|------|--------|\n| `mock_response` | 默认替换文本 | 配合性回复 |\n| `ai_enabled` | 启用 AI 改写 | `false` |\n| `ai_endpoint` | LLM API 地址 | — |\n| `ai_key` | API Key | — |\n| `ai_model` | 模型名称 | — |\n| `custom_keywords` | 自定义拒绝检测关键词 | `{}` |\n| `ctf_prompts` | 各平台自定义 CTF 提示词 | 内置模板 |\n| `ctf_templates` | 用户保存的提示词模板 | `{}` |\n\n---\n\n## 项目结构\n\n```\ncodex-session-patcher\u002F\n├── codex_session_patcher\u002F        # 核心库\n│   ├── cli.py                    # CLI 入口\n│   ├── core\u002F\n│   │   ├── formats.py            # 多平台格式策略\n│   │   ├── parser.py             # 会话解析器（JSONL + SQLite）\n│   │   ├── sqlite_adapter.py     # OpenCode SQLite 适配器\n│   │   ├── detector.py           # 拒绝检测器\n│   │   └── patcher.py            # 清理逻辑\n│   └── ctf_config\u002F\n│       ├── installer.py          # CTF 注入安装器（三平台）\n│       ├── templates.py          # 内置提示词模板\n│       └── status.py             # 状态检测\n├── web\u002F\n│   ├── backend\u002F                  # FastAPI 后端\n│   │   ├── api.py                # API 路由\n│   │   ├── ai_service.py         # AI 分析 & 改写\n│   │   ├── prompt_rewriter.py    # 提示词改写服务\n│   │   └── schemas.py            # 数据模型\n│   └── frontend\u002F                 # Vue 3 + Naive UI\n│       └── src\u002F\n│           ├── components\u002F       # 页面组件\n│           ├── stores\u002F           # Pinia 状态管理\n│           └── locales\u002F          # i18n 国际化\n├── tests\u002F\n├── scripts\u002F\n└── pyproject.toml\n```\n\n---\n\n## 局限性说明\n\n- **无法突破平台最高安全策略** — 对于明确违规的请求仍可能被拒绝\n- **效果因版本而异** — 模型版本更新可能影响效果\n- **OpenCode 需从工作空间目录启动** — OpenCode 无 profile 机制，CTF 注入依赖工作空间\n- **清理后需 resume** — 会话清理后需手动 resume 继续上下文\n\n---\n\n## 支持作者\n\n如果这个项目对你有帮助，欢迎：\n\n- ⭐ 点个 Star\n- ☕ Buy me a coffee — Web UI 右上角有赞赏入口（微信 \u002F USDC）\n- 📢 关注微信公众号「钢之AI术师」获取更多 AI 工具技巧\n\n---\n\n## 许可证\n\n[MIT License](LICENSE)\n\n---\n\n\u003Cdiv align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FryfineZ\">GitHub\u003C\u002Fa> ·\n  \u003Ca href=\"https:\u002F\u002Fx.com\u002FZhangYufan73644\">X (Twitter)\u003C\u002Fa> ·\n  微信公众号：钢之AI术师\n\u003C\u002Fdiv>\n","Codex Session Patcher 是一个轻量级的 Python 工具，用于清理 AI 编码工具（如 Codex CLI、Claude Code 和 OpenCode）会话文件中的拒绝响应。其核心功能包括智能检测和改写拒绝回复，支持批量处理和备份还原，并提供 Diff 对比视图。此外，该工具还支持 CTF\u002F渗透测试提示词注入，通过配置层面注入安全测试上下文来降低请求被拒绝的概率。适用于安全测试、CTF 比赛及渗透测试等场景，能够有效提升工作效率。",2,"2026-06-11 03:49:44","high_star"]