prompt-optimizer 按需触发提问优化 Skill
在 AI 动手前判断提问是否值得改写:对情绪发泄、确认指令和清晰单步修改静默放行,仅把含糊请求在保留 100% 意图的前提下翻译为准确领域术语与可验证标准,待确认后执行。
使用要求
- 支持 Skill 的 AI 编程助手(Claude Code、Codex、Antigravity、Cursor、Pi 或 Grok)
- 如需安装可选的自动触发 Hook / 扩展,需 Node.js 18 及以上版本
快速开始
1. 安装 Skill
git clone https://github.com/TinkCarlos/prompt-optimizer.git
cd prompt-optimizer
for d in ~/.claude/skills ~/.codex/skills ~/.cursor/skills ~/.grok/skills \
~/.gemini/config/skills ~/.agents/skills; do
[ -d "$d" ] && mkdir -p "$d/prompt-optimizer" && cp SKILL.md "$d/prompt-optimizer/"
done安装后即可手动触发:/prompt-optimizer 帮我做个PPT介绍新产品(Pi 中为 /skill:prompt-optimizer ...)。
2. 可选自动触发 Hook(需 Node.js 18+)
压缩包内 hooks/ 目录自带 Antigravity(prompt-optimizer-agy.js)、Claude Code 与 Codex(prompt-optimizer-hook.js)以及 Pi(pi install git:github.com/TinkCarlos/prompt-optimizer)的自动分流脚本,本地直接过滤 继续、同意 等确认短语,零额外 Token 消耗。
核心机制
每次接到请求时,Skill 先在后台做一次 REWRITE / SKIP 分流:
- 静默跳过(SKIP):情绪抱怨、单步明确指令(如把
src/App.tsx按钮改成#2563eb)、回复确认(同意、继续、你决定)以及对上一轮回复的简短反馈,直接执行不打扰。 - 按需改写(REWRITE):仅对目标含糊或缺少验收标准的实质性任务,输出一段 1–4 句的自然段提示词加一行确认提示(
同意 / 修改 / 按原话),全程沿用用户的原始语言。
改写原则
- 100% 保真:不篡改范围、数字和约束;缺资料时明确留空或提示待补,不替产品编数据。
- 大白话转专业术语但不过度发挥:把「等我停一下再搜」转为输入防抖(input debounce)并交代取消未触发请求与 Network 面板验收;把「像磨砂玻璃」转为玻璃拟态(glassmorphism);遇到疑似内存泄漏或并发覆盖只列排查路径与乐观锁冲突拒绝标准,不臆断未证实的根因。
- 外部可验:所有交付要求指向一手代码、日志、执行计划或真实浏览器/样本复测,不用「你是专家」等空话。
当前验证边界
如实说明:目前尚无端到端执行效果对比基准。仓库包含 Hook 路由、确认轮次识别、开关与长会话的自动化测试;首轮覆盖中、英、日、西四语的 12 条无上下文黑盒测试全部达标(11 条按预期改写,1 条明确 #2563eb 指令按预期静默跳过)。
Skill 内部
SKILL.md
--- name: prompt-optimizer description: >- Works in any language. Before acting on a user message, decide from the conversation context whether it is worth rewriting (REWRITE or SKIP). Venting, confirmations, single-step tweaks and already-clear messages are skipped silently. When a rewrite is worth it, translate layperson descriptions into accurate domain terms and restate the request as one short, high-signal prompt in the user's own language, preserving intent, scope and constraints 100%, and ask the user to confirm before executing. Use for automatic pre-routing, or when the user asks to "optimize my prompt", "polish this prompt" or runs /prompt-optimizer. --- # Prompt Optimizer First decide whether a rewrite is worth it. If it is, turn the user's words into one dense, ready-to-run prompt and wait for confirmation. Always write in the language the user wrote in. ## 1. Step one: decide REWRITE or SKIP from context - **How to answer** - Called as a standalone router (asked for the verdict only): reply with exactly `REWRITE` or `SKIP`, nothing else. - Running inline before a normal reply: on **SKIP**, stay completely silent about it. Do not mention routing or rewriting, do not load the rest of this skill, just answer or act. On **REWRITE**, continue to section 2. - The user names this skill explicitly (`/prompt-optimizer <text>`, "optimize this prompt"): skip the decision and go to section 2.
包含文件 · 10
prompt-optimizer/README.md prompt-optimizer/README.zh-CN.md prompt-optimizer/SKILL.md prompt-optimizer/hooks/claude-settings.example.json prompt-optimizer/hooks/codex-hooks.example.json prompt-optimizer/hooks/hooks.json.example prompt-optimizer/hooks/prompt-optimizer-agy.js prompt-optimizer/hooks/prompt-optimizer-hook.js …