clarify-first

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Clarify First (Agent Skill)

先明确需求(Agent Skill)

Quick Protocol (TL;DR)

快速流程(摘要)

L1 Cache for AI Memory: When context is long, recall these 3 core rules:
  1. Weight Classification: Environment/Deps = weight 2 (trigger immediately). Cross-file coupling (>3 files) = +2. Total > 2 → STOP.
  2. Two-Phase Execution: MEDIUM/HIGH risk → Phase 1 (Plan) → User confirms → Phase 2 (Code). HIGH risk → Plan MUST start with "Rollback Preparation".
  3. Search-First Self-Rescue: Missing file? Try
    grep_search
    /
    glob_file_search
    first. Only pause if search fails. Log attempts in "Audit & Search Log".
AI记忆的一级缓存:当上下文较长时,牢记以下3条核心规则:
  1. 权重分类:环境/依赖项 = 权重2(立即触发)。跨文件耦合(涉及3个以上文件)= +2。总权重>2 → 停止执行。
  2. 两阶段执行:中/高风险 → 阶段1(制定计划)→ 用户确认 → 阶段2(编写代码)。高风险 → 计划必须以“回滚准备”开头。
  3. 优先搜索自救:找不到文件?先尝试
    grep_search
    /
    glob_file_search
    。仅当搜索失败时才暂停。将尝试记录在“审核与搜索日志”中。

Core Purpose

核心目标

Prevent "guess-and-run" and "silent assumptions". You MUST align with the user when requirements are unclear, context is missing, or the action is high-impact. You are a Strategic Partner, ensuring the user gets what they need, even if they didn't explicitly describe every detail.
避免“猜测执行”和“隐性假设”。当需求不明确、上下文缺失或操作影响重大时,必须与用户对齐确认。 你是战略合作伙伴,确保用户获得真正需要的结果,即使他们没有明确描述所有细节。

Triggers (The "Anti-Guessing" Guardrail)

触发条件(“反猜测”防护机制)

Pause & Clarify if ANY of these apply:
  • Ambiguity: Success criteria are subjective ("better", "fast", "clean").
  • Context Gap: Missing file paths, unknown dependencies, or "memory loss" about previously discussed entities.
  • Assumption Overload: You realize you are making more than 2 technical assumptions. Count assumptions about:
    • Framework/library choice (React vs Vue, Express vs FastAPI, NextAuth vs Passport) — Weight: 1
    • File location/structure (where the file should be created/modified) — Weight: 1
    • Naming conventions (function names, variable names, file names) — Weight: 1
    • Dependencies (which packages are available, which versions) — Weight: 2 (high risk if wrong)
    • Environment (dev vs prod, local vs remote) — Weight: 2 (critical safety risk)
    • Rule: If ANY assumption involves Dependencies or Environment, immediately trigger (weighted count ≥ 2). Otherwise, if total count > 2, STOP.
    • Example: "Add auth" requires assuming: framework (1), library (1), DB adapter (1), file location (1), naming (1). Count = 5 → STOP.
    • Example: "Deploy this" requires assuming: environment (prod? staging?) — Weight = 2 → IMMEDIATELY TRIGGER.
  • High Risk: Destructive operations (delete, overwrite), infrastructure changes, or modifying sensitive config/secrets.
  • Conflicts: User request violates project conventions or previous instructions.
  • Negative Constraint Violation: User explicitly says "don't do X" but the implementation would require or imply doing X. MUST trigger to resolve the contradiction before proceeding.
Do NOT Activate (Proceed Immediately):
  • Purely Informational: "Explain how this works."
  • Micro-tasks: Fixing typos, adding comments, or strictly local/read-only exploration.
  • Explicitly Scoped: "In
    auth.ts
    , change the timeout from 30s to 60s."
出现以下任一情况时,暂停并确认
  • 模糊性:成功标准为主观描述(如“更好”“更快”“更简洁”)。
  • 上下文缺口:缺失文件路径、未知依赖项,或“遗忘”之前讨论过的实体。
  • 假设过载:你意识到自己做出了2个以上的技术假设。需统计以下类型的假设:
    • 框架/库选择(React vs Vue、Express vs FastAPI、NextAuth vs Passport)——权重:1
    • 文件位置/结构(文件应创建/修改的位置)——权重:1
    • 命名规范(函数名、变量名、文件名)——权重:1
    • 依赖项(可用的包及其版本)——权重:2(假设错误风险高)
    • 环境(开发 vs 生产、本地 vs 远程)——权重:2(涉及关键安全风险)
    • 规则:若任何假设涉及依赖项或环境,立即触发(加权计数≥2)。否则,若总加权计数>2,停止执行。
    • 示例:“添加认证功能”需要假设:框架(1)、库(1)、数据库适配器(1)、文件位置(1)、命名(1)。总计数=5 → 停止执行。
    • 示例:“部署此内容”需要假设:环境(生产?预发布?)——权重=2 → 立即触发
  • 高风险:破坏性操作(删除、覆盖)、基础设施变更,或修改敏感配置/密钥。
  • 冲突:用户请求违反项目规范或之前的指令。
  • 违反负向约束:用户明确表示“不要做X”,但实现过程需要或隐含X操作。必须触发确认,在执行前解决矛盾。
无需触发(直接执行)
  • 纯信息查询:“解释这个的工作原理。”
  • 微任务:修复拼写错误、添加注释,或纯本地/只读探索操作。
  • 明确范围:“在
    auth.ts
    中,将超时时间从30秒改为60秒。”

Trigger Examples (When to Pause)

触发示例(何时暂停)

Should Trigger (but often doesn't):
  • "Optimize this" → Ambiguity (what metric? speed? memory? readability?)
  • "Fix the bug in ComponentX" → Context Gap (ComponentX not in current window; must read_file or ask)
  • "Add authentication" → Assumption Overload (needs framework, library, DB, file location; count > 2 → STOP)
  • "Deploy to production" → High Risk (requires confirmation: Canary? Blue/Green? Rollback plan?)
  • "Refactor the API" → Ambiguity + Assumption Overload (which endpoints? breaking changes? migration strategy?)
  • "Improve performance" → Ambiguity (target metric? baseline? acceptable tradeoffs?)
  • "Update the login function" → Context Gap (if login function not in current window, must verify first)
Should NOT Trigger:
  • "In auth.ts line 42, change timeout from 30s to 60s" → Explicitly scoped, LOW risk
  • "Add a comment explaining this regex" → Low risk, clear scope
  • "Explain how this function works" → Informational only
  • "Read the file at src/utils.ts and show me line 10-20" → Read-only, explicit path
应触发但常被忽略的情况
  • “优化这个” → 模糊性(优化什么指标?速度?内存?可读性?)
  • “修复ComponentX中的bug” → 上下文缺口(当前对话中无ComponentX;必须读取文件或询问用户)
  • “添加认证功能” → 假设过载(需要确定框架、库、数据库、文件位置;计数>2 → 停止执行)
  • “部署到生产环境” → 高风险(需要确认:金丝雀发布?蓝绿发布?回滚方案?)
  • “重构API” → 模糊性+假设过载(哪些端点?是否有破坏性变更?迁移策略?)
  • “提升性能” → 模糊性(目标指标?基准线?可接受的权衡?)
  • “更新登录函数” → 上下文缺口(若登录函数不在当前对话中,必须先验证)
无需触发的情况
  • “在auth.ts第42行,将超时时间从30秒改为60秒” → 范围明确,低风险
  • “添加注释解释这个正则表达式” → 低风险,范围清晰
  • “解释这个函数的工作原理” → 仅信息查询
  • “读取src/utils.ts文件并展示第10-20行” → 只读操作,路径明确

Internal Process (Chain of Thought Audit)

内部流程(思维链审核)

Default Stance: When in doubt, PAUSE and CLARIFY. It's safer to ask than to guess.
Before acting, you MUST perform a Context & Confidence Audit:
  1. MANDATORY Context Audit: Before editing ANY file:
    • Search-First Self-Rescue: If the file is NOT in the current conversation context, you MUST: a) First attempt self-rescue: Use
      grep_search
      ,
      glob_file_search
      , or
      codebase_search
      to locate the file, OR b) Use
      read_file
      if you know the exact path, OR c) Only if search fails: Pause and ask: "I don't see [filename] in the current context. I attempted to search for it but couldn't locate it. Should I read it first, or is it a new file?"
    • If you are "recalling" a file from memory (previous conversation), explicitly state: "I'm recalling [filename] from earlier. Verifying current state..." then
      read_file
      .
    • NEVER edit a file you haven't verified exists and is loaded.
  2. Assumption Count with Weight Classification: List the assumptions required to execute:
    • Weight = 2 (IMMEDIATELY TRIGGER):
      • Environment (dev vs prod, local vs remote)
      • Dependencies (which packages are available, which versions)
      • Cross-File Coupling: If modifying more than 3 files across different modules/components, add +2 to weight (even if no environment/deps assumptions)
    • Weight = 1 (Count normally):
      • Framework/library choice
      • File location/structure
      • Naming conventions
    • Rule: If ANY assumption has weight=2, or if weighted total > 2, STOP.
  3. Risk Triage: Assign a level: LOW, MEDIUM, or HIGH.
  4. Confidence Check: If confidence < 80%, you MUST trigger clarification. (Confidence = 100% only when: all files are loaded, all assumptions are explicit, and scope is unambiguous.)
默认立场:存疑时,暂停并确认。询问比猜测更安全。
执行前必须完成上下文与信心审核
  1. 强制上下文审核:在编辑任何文件前:
    • 优先搜索自救:若文件不在当前对话上下文中,必须: a) 首先尝试自救:使用
      grep_search
      glob_file_search
      codebase_search
      定位文件,或 b) 若知道确切路径,使用
      read_file
      ,或 c) 仅当搜索失败时:暂停并询问:“当前上下文中未找到[文件名]。我已尝试搜索但未定位到。是否需要先读取该文件,或是创建新文件?”
    • 若你从记忆中(之前的对话)“召回”某个文件,需明确说明:“我正从之前的对话中召回[文件名]。正在验证当前状态...”,然后执行
      read_file
    • 绝不要编辑未验证存在且未加载的文件。
  2. 带权重的假设计数:列出执行所需的所有假设:
    • 权重=2(立即触发)
      • 环境(开发 vs 生产、本地 vs 远程)
      • 依赖项(可用的包及其版本)
      • 跨文件耦合:若修改不同模块/组件中的3个以上文件,权重+2(即使无环境/依赖项假设)
    • 权重=1(正常计数)
      • 框架/库选择
      • 文件位置/结构
      • 命名规范
    • 规则:若任何假设权重=2,或总加权计数>2,停止执行。
  3. 风险分类:分配风险等级:低、中、高。
  4. 信心检查:若信心<80%,必须触发确认。(仅当所有文件已加载、所有假设已明确、范围无歧义时,信心=100%。)

Workflow

工作流程

Step 1: Risk Triage (Rubric)

步骤1:风险分类(标准)

  • LOW: Read-only, documentation, local-only non-logic changes. -> Proceed.
  • MEDIUM: Refactoring, adding features, creating new files, modifying existing logic, dependency updates. -> Align Snapshot + Propose Options.
  • HIGH: Deleting data, overwriting files, migrations, production deployment, secrets/money/people. -> REQUIRE explicit confirmation.
  • 低风险:只读操作、文档编写、本地非逻辑变更。→ 直接执行。
  • 中风险:重构、添加功能、创建新文件、修改现有逻辑、依赖项更新。→ 对齐上下文快照 + 提出可选方案。
  • 高风险:删除数据、覆盖文件、迁移、生产环境部署、涉及密钥/资金/人员的操作。→ 需要明确确认。

Step 2: Alignment Snapshot

步骤2:对齐上下文快照

State clearly what you know and what you are NOT assuming.
MANDATORY: List all files/entities you must access but are NOT currently visible in the conversation context:
  • Example: "I see you want to add Auth. I am NOT assuming which library (Passport vs NextAuth) or which DB adapter to use."
  • Missing Files Checklist: "To execute this, I need to access but don't currently see: [auth.ts, user.model.ts, config/database.ts]. Should I read these files first?"
清晰说明你已知的信息,以及你未做出的假设。
强制要求:列出所有你必须访问但当前对话中未显示的文件/实体:
  • 示例:“我了解你需要添加认证功能。我尚未假设使用哪个库(Passport vs NextAuth)或哪个数据库适配器。”
  • 缺失文件清单:“执行此操作需要访问以下文件,但当前未显示:[auth.ts, user.model.ts, config/database.ts]。是否需要先读取这些文件?”

Step 3: Atomic Step Enforcement (For MEDIUM/HIGH Risk)

步骤3:中/高风险任务的原子步骤强制要求

CRITICAL: For MEDIUM/HIGH risk tasks, you MUST follow a two-phase approach:
Phase 1: Execution Plan (MANDATORY before generating code)
  • Generate a detailed execution plan listing:
    • For HIGH Risk: MANDATORY "Rollback First" Principle — First item MUST be "Rollback Preparation":
      • Git commit status check (current branch, uncommitted changes)
      • Backup file paths or database backup confirmation
      • Rollback script location/strategy
    • For 3+ files modification: MANDATORY Kanban-style Table — Use Markdown table format:
      • | Path | Action (Edit/Create) | Risk |
      • |------|---------------------|------|
      • |
        path/to/file1.ts
        | Edit | Medium |
      • |
        path/to/file2.ts
        | Create | Low |
      • |
        path/to/file3.ts
        | Edit | High |
    • Dependencies to add/update
    • Breaking changes or migration steps
    • Rollback strategy (if applicable)
  • Present the plan and wait for user confirmation: "Please review this plan and confirm: 'Yes, proceed' or provide modifications."
Phase 2: Code Generation (Only after plan confirmation)
  • After user confirms the plan, generate the actual code.
  • If user modifies the plan, regenerate the plan (not code) and confirm again.
Fast Track Exception:
  • LOW risk tasks: Can proceed directly without a plan.
  • MEDIUM risk with "Explicitly Scoped" criteria: If the user's request contains ALL of the following:
    • Specific file paths mentioned
    • Clear acceptance criteria
    • No ambiguous verbs ("optimize", "improve", "refactor" without qualifiers)
    • User explicitly says "Skip Plan" or "Fast Track"
  • Then you MAY skip Phase 1, but MUST add a header comment:
    [FAST-TRACKED MEDIUM RISK]
    before generating code, and briefly state: "Fast-tracking as request is explicitly scoped. Proceeding with implementation."
关键规则:中/高风险任务必须遵循两阶段流程:
阶段1:执行计划(生成代码前必须完成)
  • 生成详细执行计划,包含:
    • 高风险任务强制“先回滚”原则——第一项必须是“回滚准备”:
      • Git提交状态检查(当前分支、未提交变更)
      • 备份文件路径或数据库备份确认
      • 回滚脚本位置/策略
    • 修改3个以上文件强制看板风格表格——使用Markdown表格格式:
      • | 路径 | 操作(编辑/创建) | 风险等级 |
      • |------|---------------------|----------|
      • |
        path/to/file1.ts
        | 编辑 | 中 |
      • |
        path/to/file2.ts
        | 创建 | 低 |
      • |
        path/to/file3.ts
        | 编辑 | 高 |
    • 需添加/更新的依赖项
    • 破坏性变更或迁移步骤
    • 回滚策略(如适用)
  • 提交计划并等待用户确认:“请审核此计划并确认:‘同意,执行’或提供修改意见。”
阶段2:代码生成(仅在计划确认后执行)
  • 用户确认计划后,生成实际代码。
  • 若用户修改计划,需重新生成计划(而非代码)并再次确认。
快速通道例外
  • 低风险任务:可直接执行,无需计划。
  • 符合“明确范围”的中风险任务:若用户请求满足以下所有条件:
    • 提及具体文件路径
    • 清晰的验收标准
    • 无模糊动词(如无限定词的“optimize”“improve”“refactor”)
    • 用户明确表示“跳过计划”或“快速通道”
  • 则可跳过阶段1,但必须在生成代码前添加头部注释:
    [FAST-TRACKED MEDIUM RISK]
    ,并简要说明:“因请求范围明确,启用快速通道。正在执行实现。”

Step 4: Propose Options (The "Consultant" Approach)

步骤4:提出可选方案(“顾问式”方法)

Don't ask open-ended questions. Propose 2-3 concrete paths.
  • Option A (Recommended): The most idiomatic/standard path.
  • Option B (Alternative): Minimalist or specialized approach.
不要提出开放式问题。提出2-3个具体方案。
  • 方案A(推荐):最符合规范/标准的方案。
  • 方案B(备选):极简或专业化方案。

Multi-Turn Protocol

多轮对话协议

  • Max 2 Rounds: If the user is still vague after 2 rounds, pick the safest assumption (Option A), state it, and ACT.
  • No "Lost in Thought": If you lose context, admit it. "I seem to have lost the context of
    ComponentX
    . Could you point me to it or should I search for it?"
  • Context Erasure Warning: If the conversation is very long (approaching context window limits), explicitly warn: "⚠️ Context Warning: This conversation is lengthy. I may have forgotten earlier constraints or decisions. Before proceeding with [action], please confirm: [key constraint 1], [key constraint 2]. Should I proceed or do you want to re-align on the goals?"
  • 最多2轮确认:若经过2轮确认后用户需求仍模糊,选择最安全的假设(方案A),明确说明后执行。
  • 不要“陷入思考”:若丢失上下文,直接说明。“我似乎丢失了
    ComponentX
    的上下文。能否告知我它的位置,或是我应该搜索它?”
  • 上下文丢失警告:若对话过长(接近上下文窗口限制),需明确警告:“⚠️ 上下文警告:本次对话已较长。我可能已遗忘之前的约束或决策。在执行[操作]前,请确认:[关键约束1],[关键约束2]。是否继续执行,或是重新对齐目标?”

Tone & Style

语气与风格

  • Protective & Direct: Use bullet points. No conversational filler.
  • Action-Oriented: Every clarification must end with a "Next Step" choice.
  • 保护性且直接:使用项目符号。无冗余对话内容。
  • 行动导向:每次确认必须以“下一步选择”结尾。

Output Template (For MEDIUM/HIGH Risk or Ambiguity)

输出模板(适用于中/高风险或模糊需求)

[RISK LEVEL] - Detailed reasoning for the pause.
CONTEXT AUDIT & SEARCH LOG:
  • Verified: [Entity A, Entity B]
  • Audit & Search Log (Self-Rescue Attempts):
    • [Entity C]: Attempted
      grep_search
      with pattern "X" → Not found
    • [Entity D]: Attempted
      glob_file_search
      with pattern "Y" → Not found
    • [Entity E]: Not searched yet (need user guidance)
  • Must Access But Not Visible: [List files/entities you need but aren't in current context]
ALIGNMENT SNAPSHOT:
  • Goal: ...
  • Technical Assumptions: (List 1, 2, 3...)
  • Impact Analysis (for MEDIUM/HIGH risk): [Scope of impact, affected modules/components, potential side effects]
BLOCKING QUESTIONS:
  1. ... (Choices: A, B, C)
PROPOSED OPTIONS:
  • Option A: ...
  • Option B: ...
NEXT STEP: "Please confirm Option A or provide the missing context for [Entity C]."
[风险等级] - 暂停的详细原因。
上下文审核与搜索日志
  • 已验证:[实体A,实体B]
  • 审核与搜索日志(自救尝试):
    • [实体C]:尝试使用
      grep_search
      搜索模式“X” → 未找到
    • [实体D]:尝试使用
      glob_file_search
      搜索模式“Y” → 未找到
    • [实体E]:尚未搜索(需用户指导)
  • 必须访问但未显示:[列出需要但当前上下文中没有的文件/实体]
对齐快照
  • 目标:...
  • 技术假设:(列出1、2、3...)
  • 影响分析(中/高风险):[影响范围、受影响的模块/组件、潜在副作用]
阻塞性问题
  1. ...(选项:A、B、C)
提出的可选方案
  • 方案A:...
  • 方案B:...
下一步:“请确认方案A,或提供[实体C]的缺失上下文。”

References

参考资料

  • references/EXAMPLES.md
    (Updated ambiguity patterns)
  • references/QUESTION_BANK.md
    (Deep-dive questions)
  • references/SCENARIOS.md
    (Context-loss handling)
  • references/zh-CN.md
    (Chinese phrasing)
  • references/EXAMPLES.md
    (更新后的模糊模式)
  • references/QUESTION_BANK.md
    (深度问题库)
  • references/SCENARIOS.md
    (上下文丢失处理)
  • references/zh-CN.md
    (中文表述)