ask

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ask Skill

Ask Skill

Answer questions about AI-written code by finding the original prompts and conversations that produced it, then embodying the author agent's perspective to answer.
通过查找生成AI编写代码的原始提示词和对话记录,然后代入编写该代码的Agent视角来回答关于AI编写代码的问题。

Main Agent's Job (you)

主Agent的工作(你需要执行的内容)

You do the prep work, then hand off to a fast, tightly scoped subagent:
  1. Resolve the file path and line range — check these sources in order:
    a) Editor selection context (most common). When the user has lines selected in their editor, a
    <system-reminder>
    is injected into the conversation like:
    The user selected the lines 2 to 4 from /path/to/file.rs:
    _flush_logs(args: &[String]) {
        flush::handle_flush_logs(args);
    }
    Extract the file path and line range directly from this. This is the primary way users will invoke
    /ask
    — they select code, then type something like "/ask why is this like that" without naming the file or lines.
    b) Explicit file/line references — "on line 42", "lines 10-50 of src/main.rs" → use directly.
    c) Named symbol — mentions a variable/function/class → Read the file, find where it's defined, extract line numbers.
    d) File without line specifics → whole file (omit
    --lines
    ).
    e) No file, no lines, no selection context, no identifiable code reference → Do NOT attempt to guess or search. Just reply:
    Select some code or mention a specific file/symbol, then
    /ask
    your question.
    Stop here. Do not spawn a subagent.
  2. Spawn one subagent with the template below. Use
    max_turns: 4
    .
  3. Relay the answer to the user. That's it.
你需要先完成准备工作,然后将任务交接给一个快速、范围严格的子Agent
  1. 解析文件路径和行范围 — 按以下优先级顺序检查来源:
    a) 编辑器选中内容上下文(最常见)。当用户在编辑器中选中某些行时,对话中会注入一个
    <system-reminder>
    ,格式如下:
    The user selected the lines 2 to 4 from /path/to/file.rs:
    _flush_logs(args: &[String]) {
        flush::handle_flush_logs(args);
    }
    直接从中提取文件路径和行范围。这是用户调用
    /ask
    的主要方式——他们选中代码,然后输入类似"/ask why is this like that"的内容,无需指定文件或行号。
    b) 显式的文件/行引用 — 比如“on line 42”、“lines 10-50 of src/main.rs” → 直接使用这些信息。
    c) 命名符号 — 提到变量/函数/类 → 读取文件,找到其定义位置,提取行号。
    d) 仅指定文件,无行细节 → 处理整个文件(省略
    --lines
    参数)。
    e) 无文件、无行号、无选中上下文、无可识别的代码引用 → 不要尝试猜测或搜索。只需回复:
    请选中部分代码,或提及特定文件/符号,然后使用
    /ask
    提问。
    到此为止,不要生成子Agent。
  2. 使用以下模板生成一个子Agent。设置
    max_turns: 4
  3. 将子Agent的答案转发给用户。任务完成。

Subagent Configuration

子Agent配置

Task tool settings:
  subagent_type: "general-purpose"
  max_turns: 4
The subagent gets only
Bash
and
Read
. It does NOT get Glob, Grep, or Task. It runs at most 4 turns — this is a fast lookup, not a research project.
Task tool settings:
  subagent_type: "general-purpose"
  max_turns: 4
子Agent仅能使用
Bash
Read
工具。不能使用Glob、Grep或Task工具。它最多运行4轮对话——这是快速查询,而非研究项目。

Choosing Between
blame --show-prompt
and
search

blame --show-prompt
search
之间选择

If you want to read an entire file or range of lines AND the corresponding prompts behind them, use
git-ai blame --show-prompt
.
This is better than
search
for this use case — it gives you every line's authorship plus the full prompt JSON in one call.
undefined
如果你想要读取整个文件或某段代码,以及对应的背后提示词,请使用
git-ai blame --show-prompt
对于这种场景,它比
search
更合适——它能一次性提供每一行的作者信息以及完整的提示词JSON数据。
undefined

Get blame + prompts for a line range (pipe to get prompt dump appended):

获取某行范围的blame信息+提示词(通过管道追加提示词内容):

git-ai blame src/commands/blame.rs -L 23,54 --show-prompt | cat
git-ai blame src/commands/blame.rs -L 23,54 --show-prompt | cat

Interactive (TTY) mode shows prompt hashes inline:

交互(TTY)模式会在行内显示提示词哈希值:

7a4471d (cursor [abc123e] 2026-02-06 14:20:05 -0800 23) code_here

7a4471d (cursor [abc123e] 2026-02-06 14:20:05 -0800 23) code_here

Piped mode appends raw prompt messages after a --- separator:

管道模式会在---分隔符后追加原始提示词消息:

---

---

Prompt [abc123e]

Prompt [abc123e]

[{"type":"user","text":"Write a function..."},{"type":"assistant","text":"Here is..."}]

[{"type":"user","text":"Write a function..."},{"type":"assistant","text":"Here is..."}]


Use `git-ai search` when you need to find prompts by **commit**, **keyword**, or when you don't have a specific file/line range in mind.

当你需要通过**提交记录**、**关键词**查找提示词,或者没有特定的文件/行范围时,请使用`git-ai search`。

Subagent Prompt Template

子Agent提示模板

Fill in
{question}
,
{file_path}
, and
{start}-{end}
(omit LINES if not applicable):
You are answering a question about code by finding the original AI conversation
that produced it. You will embody the author agent's perspective — first person,
as the agent that wrote the code.

QUESTION: {question}
FILE: {file_path}
LINES: {start}-{end}

You have exactly 3 steps. Do them in order, then stop.

STEP 1 — Search (one command):
  Run: git-ai search --file {file_path} --lines {start}-{end} --verbose
  If no results, try ONE fallback: git-ai search --file {file_path} --verbose
  That's it. Do not run more than 2 git-ai commands total.

STEP 2 — Read the code (one Read call):
  Read {file_path} (focus on lines {start}-{end})

STEP 3 — Answer:
  Using the transcript from Step 1 and the code from Step 2, answer the
  question AS THE AUTHOR in first person:
  - "I wrote this because..."
  - "The problem I was solving was..."
  - "I chose X over Y because..."

  Format:
  - **Answer**: Direct answer in the author's voice
  - **Original context**: What the human asked for and why
  - **Date(s)**: Dates, Human Author where this feature was worked on. 

  If no transcript was found, say so clearly: "I couldn't find AI conversation
  history for this code — it may be human-written or predate git-ai setup."
  In that case, analyze the code objectively (not first person).

HARD CONSTRAINTS:
- Do NOT use Glob, Grep, or Task tools. You only have Bash and Read.
- Do NOT run more than 2 git-ai commands.
- Do NOT read .claude/, .cursor/, .agents/, or any agent log directories.
- Do NOT search JSONL transcripts or session logs directly.
- All conversation data comes from `git-ai search` only.
When the user's question doesn't reference specific lines, omit
--lines
from Step 1 and the
LINES:
field.
填充
{question}
{file_path}
{start}-{end}
(如果不适用则省略LINES部分):
You are answering a question about code by finding the original AI conversation
that produced it. You will embody the author agent's perspective — first person,
as the agent that wrote the code.

QUESTION: {question}
FILE: {file_path}
LINES: {start}-{end}

You have exactly 3 steps. Do them in order, then stop.

STEP 1 — Search (one command):
  Run: git-ai search --file {file_path} --lines {start}-{end} --verbose
  If no results, try ONE fallback: git-ai search --file {file_path} --verbose
  That's it. Do not run more than 2 git-ai commands total.

STEP 2 — Read the code (one Read call):
  Read {file_path} (focus on lines {start}-{end})

STEP 3 — Answer:
  Using the transcript from Step 1 and the code from Step 2, answer the
  question AS THE AUTHOR in first person:
  - "I wrote this because..."
  - "The problem I was solving was..."
  - "I chose X over Y because..."

  Format:
  - **Answer**: Direct answer in the author's voice
  - **Original context**: What the human asked for and why
  - **Date(s)**: Dates, Human Author where this feature was worked on. 

  If no transcript was found, say so clearly: "I couldn't find AI conversation
  history for this code — it may be human-written or predate git-ai setup."
  In that case, analyze the code objectively (not first person).

HARD CONSTRAINTS:
- Do NOT use Glob, Grep, or Task tools. You only have Bash and Read.
- Do NOT run more than 2 git-ai commands.
- Do NOT read .claude/, .cursor/, .agents/, or any agent log directories.
- Do NOT search JSONL transcripts or session logs directly.
- All conversation data comes from `git-ai search` only.
当用户的问题没有引用特定行时,在步骤1中省略
--lines
参数,同时省略
LINES:
字段。

Fallback Behavior

回退行为

When no prompt data is found:
  • The code might be human-written or predate git-ai
  • Answer from the code alone, clearly stating no AI history was found
  • Do NOT use first-person author voice in fallback — analyze objectively
当未找到提示词数据时:
  • 该代码可能是人类编写的,或者早于git-ai的部署
  • 仅基于代码内容回答,并明确说明未找到AI历史记录
  • 回退场景下不要使用第一人称作者视角——需客观分析代码

Example Invocations

调用示例

User selects lines 10-25 in editor, types:
/ask why is this like that
Selection context is in system-reminder → extract file + lines 10-25, spawn subagent. This is the most common usage pattern.
/ask why does this function use recursion instead of iteration?
Main agent finds the function definition, extracts file/lines, spawns subagent.
/ask what problem was being solved on lines 100-150 of src/main.rs?
File and lines explicit — spawn subagent directly.
/ask why was this approach chosen over using a HashMap?
Main agent identifies relevant code from context, spawns subagent.
用户在编辑器中选中10-25行,输入:
/ask why is this like that
系统提示中包含选中上下文 → 提取文件+10-25行,生成子Agent。这是最常见的使用模式。
/ask why does this function use recursion instead of iteration?
主Agent找到函数定义,提取文件/行号,生成子Agent。
/ask what problem was being solved on lines 100-150 of src/main.rs?
文件和行号明确 → 直接生成子Agent。
/ask why was this approach chosen over using a HashMap?
主Agent从上下文中识别相关代码,生成子Agent。