mcpField
A
ask

ask

github.com/git-ai-project开发2.9k44 次安装1 周前更新
代码仓库

关于 ask

ask 是一项针对 AI 编写代码答疑的技能,可定位选中或指定代码背后的提示词与对话。它将检索任务交给范围明确的子 Agent;找到记录时以原编写 Agent 的视角回答。

主要功能

  1. 01从选区、文件或符号定位代码
  2. 02检索代码作者与提示词记录
  3. 03委派聚焦的子 Agent 查询
  4. 04无记录时客观分析代码

适用场景

  1. 01询问选中代码的设计原因
  2. 02追溯函数对应的原始提示词
  3. 03在无提示词记录时分析代码选择

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/git-ai-project/git-ai --skill ask

安装后在 Claude Code 中输入/ask确认已加载。

详细介绍

Ask Skill

通过查找生成 AI 编写代码的原始提示词和对话,并代入作者 Agent 的视角来回答相关问题。

主 Agent 的工作(你)

先完成准备工作,然后交给一个快速且范围明确的子 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 为什么会这样”的问题,无需指定文件或行号。

    b) 明确的文件/行号引用 — “第 42 行”“src/main.rs 的第 10-50 行” → 直接使用。

    c) 指定的符号 — 提到了变量/函数/类 → 读取文件,查找其定义并提取行号。

    d) 未指定具体行号的文件 → 使用整个文件(省略 --lines)。

    e) 未指定文件、行号或选区上下文,也没有可识别的代码引用 → 不要猜测或搜索。只需回复:

    选中一些代码,或提及具体的文件/符号,然后用 /ask 提问。

    到此为止。不要启动子 Agent。

  2. 使用以下模板启动一个子 Agent。设置 max_turns: 4。

  3. 将答案转达给用户。仅此而已。

子 Agent 配置

Task tool settings:
  subagent_type: "general-purpose"
  max_turns: 4

子 Agent 仅可使用 Bash 和 Read。它不能使用 Glob、Grep 或 Task。最多运行 4 轮——这是一次快速查找,而不是研究项目。

在 blame --show-prompt 和 search 之间进行选择

如果你想读取整个文件或指定行范围,并查看对应的提示词,请使用 git-ai blame --show-prompt。 这比在此用例中使用 search 更合适——它一次调用即可提供每行的作者信息和完整的提示词 JSON。

# Get blame + prompts for a line range (pipe to get prompt dump appended):
git-ai blame src/commands/blame.rs -L 23,54 --show-prompt | cat

# Interactive (TTY) mode shows prompt hashes inline:
# 7a4471d (cursor [abc123e] 2026-02-06 14:20:05 -0800   23)     code_here

# Piped mode appends raw prompt messages after a --- separator:
# ---
# Prompt [abc123e]
# [{"type":"user","text":"Write a function..."},{"type":"assistant","text":"Here is..."}]

当需要按提交、关键词查找提示词,或没有特定文件/行范围时,使用 git-ai search。

子 Agent 提示词模板

填写 {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: 字段。

回退行为

未找到提示词数据时:

  • 代码可能是人工编写的,或早于 git-ai
  • 仅根据代码作答,并明确说明没有找到 AI 历史记录
  • 回退时不要使用作者的第一人称口吻,应进行客观分析

调用示例

用户在编辑器中选中第 10-25 行,然后输入:/ask why is this like that 选区上下文位于 system-reminder 中 → 提取文件和第 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。

评论

支持 Markdown