Communitygithub.com

代码导览

创建 CodeTour `.tour` 文件——针对特定用户角色的、分步引导的代码库导览,支持真实的文件和行号锚点。适用于新手上手指南、架构导览、PR 导览、故障根因分析等场景。

代码导览 是什么?

该技能专注于创建 CodeTour 格式的 `.tour` 文件,这是一种结构化的代码库导览方式,能够直接将读者引导到真实的文件和代码行范围。与一次性聊天解释不同,CodeTour 提供了可重复使用的引导式内容,非常适合新成员入职、代码架构理解、PR 审查、故障根因分析及安全审查等场景。技能首先要求你通过探索仓库来理解代码结构,然后根据用户请求确定读者角色(如新手、架构师、PR 审查者等)和合适的步骤数量。接着,你需要验证所有文件和行号锚点必须真实存在,并且 `ref` 字段必须准确指向包含所有引用文件的分支或提交,以避免步骤无法打开。最后,它会指导你根据 SMIG 原则(情境、机制、含义、陷阱)编写每个步骤的描述,并确保整个导览具有清晰的叙事弧线,而非简单的文件列表。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/code-tour

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

代码导览 (Code Tour)

创建 CodeTour .tour 文件,用于代码库导览,这些导览可以直接打开到真实的文件和行范围。导览文件存放在 .tours/ 目录下,且应遵循 CodeTour 格式,而不是临时的 Markdown 笔记。

一个好的导览是为特定读者准备的叙述:

  • 他们正在看什么
  • 为什么它很重要
  • 他们接下来应遵循什么路径

仅创建 .tour JSON 文件。不要将此技能用于修改源代码。

何时使用

在以下情况下使用此技能:

  • 用户请求代码导览、上手导览、架构导览或 PR 导览
  • 用户说“解释 X 是如何工作的”并希望得到一个可重复使用的引导式工件
  • 用户希望为新手工程师或审查者提供一条快速上手路径
  • 相比于平面摘要,引导式序列能更好地完成任务

示例:

  • 为新维护者提供入职引导
  • 为一个服务或包提供架构导览
  • 锚定到已更改文件的 PR 审查导览
  • 展示故障路径的根因分析导览
  • 安全审查导览,涵盖信任边界和关键检查

何时不使用

不适合使用代码导览的情况应使用
一次性的聊天解释就足够了直接回答
用户想要散文风格的文档,而不是 .tour 工件documentation-lookup 或仓库文档编辑
任务是实现或重构执行实现工作
任务是没有导览工件的宽泛代码库入职引导codebase-onboarding

工作流程

1. 探索

在编写任何内容之前先探索仓库:

  • README 和包/应用入口点
  • 文件夹结构
  • 相关配置文件
  • 如果导览是针对 PR 的,则关注已更改的文件

在理解代码结构之前,不要开始编写步骤。

2. 推断读者

根据请求确定读者角色和深度。

请求类型角色建议步骤数
“入职引导”、“新成员”new-joiner9-13 步
“快速导览”、“感受一下”vibecoder5-8 步
“架构”architect14-18 步
“导览这个 PR”pr-reviewer7-11 步
“为什么会出这个故障”rca-investigator7-11 步
“安全审查”security-reviewer7-11 步
“解释这个功能是如何工作的”feature-explainer7-11 步
“调试这个路径”bug-fixer7-11 步

3. 读取并验证锚点

每个文件路径和行锚点必须是真实的:

  • 确认文件存在
  • 确认行号在范围内
  • 如果使用选区,验证确切的代码块
  • 如果文件经常变动,优先使用基于模式的锚点

永远不要猜测行号。

4. 编写 .tour 文件

写入到:

.tours/<角色>-<聚焦点>.tour

保持路径确定性和可读性。

5. 验证

在完成之前:

  • 每个引用的路径都存在
  • 每一行或选区都是有效的
  • 第一步锚定到一个真实的文件或目录
  • ref 指向一个确实包含导览中所有引用文件的分支或提交(见下文)
  • 导览讲述的是一个连贯的故事,而不是文件清单

ref 字段

ref 将导览绑定到一个 git 分支或提交。它比看起来更重要:当 ref 不是读者检出的分支时,CodeTour 会从该版本中打开每个步骤的文件,而不是从磁盘上的文件打开。如果该版本中不存在某个文件,步骤将无法打开——读者会看到 “编辑器无法打开,因为找不到该文件” ,即使该文件就在那里。导览及其注释仍然会显示,因此真正的原因很容易被忽略。

根据导览类型选择 ref:

导览类型将 ref 设置为
PR 导览PR 分支——永远不要设为基础分支
入职引导/架构导览读者将检出的分支(通常为 main),或省略它
不确定省略 ref,这样 CodeTour 会直接从磁盘读取文件

PR 场景是一个常见陷阱:PR 通常会添加新文件,而新文件在基础分支上还不存在。如果将 ref 指向基础分支(例如 develop),那么针对新文件的每个步骤都无法打开。

在完成之前,确认每个步骤的文件在你选择的 ref 上确实存在。

步骤类型

纯内容 (Content)

谨慎使用,通常仅用于结束步骤:

{ "title": "下一步", "description": "现在你可以端到端地跟踪请求路径了。" }

不要将第一步设为纯内容。

目录 (Directory)

用于将读者引导到一个模块:

{ "directory": "src/services", "title": "服务层", "description": "核心编排逻辑位于此处。" }

文件 + 行 (File + line)

这是默认的步骤类型:

{ "file": "src/auth/middleware.ts", "line": 42, "title": "认证关卡", "description": "每个受保护的请求都会首先经过这里。" }

选区 (Selection)

当某个代码块比整个文件更重要时使用:

{
  "file": "src/core/pipeline.ts",
  "selection": {
    "start": { "line": 15, "character": 0 },
    "end": { "line": 34, "character": 0 }
  },
  "title": "请求管道",
  "description": "这个代码块串联了验证、认证和下游执行逻辑。"
}

模式 (Pattern)

当确切的行号可能发生变化时使用:

{ "file": "src/app.ts", "pattern": "export default class App", "title": "应用入口" }

URI

在必要时用于 PR、问题或文档:

{ "uri": "https://github.com/org/repo/pull/456", "title": "这个 PR" }

编写规则:SMIG

每个描述都应回答:

  • 情境 (Situation):读者正在看什么
  • 机制 (Mechanism):它是如何工作的
  • 含义 (Implication):为什么这对该角色很重要
  • 陷阱 (Gotcha):一个聪明的读者可能会错过什么

保持描述简洁、具体,并基于实际代码。

叙事弧线

除非任务明确需要不同的方式,否则使用这个弧线:

  1. 方向定位
  2. 模块地图
  3. 核心执行路径
  4. 边界情况或陷阱
  5. 结束/下一步操作

导览应感觉像一条路径,而不是一份清单。

示例

{
  "$schema": "https://aka.ms/codetour-schema",
  "title": "API 服务导览",
  "description": "支付服务请求路径的导览。",
  "ref": "main",
  "steps": [
    {
      "directory": "src",
      "title": "源代码根目录",
      "description": "服务的所有运行时代码都从这里开始。"
    },
    {
      "file": "src/server.ts",
      "line": 12,
      "title": "入口点",
      "description": "服务器在此启动,并在任何路由被访问之前装配中间件。"
    },
    {
      "file": "src/routes/payments.ts",
      "line": 8,
      "title": "支付路由",
      "description": "每个支付请求在进入服务逻辑之前,都会首先通过此路由器。"
    },
    {
      "title": "下一步",
      "description": "现在,借助主要的锚点,你可以端到端地跟踪任何支付请求。"
    }
  ]
}

反模式

反模式修正方案
平面的文件清单讲述一个步骤间有依赖关系的故事
泛泛的描述指明具体的代码路径或模式
猜测的锚点首先验证每个文件和行
快速导览的步骤过多大幅削减
第一步是纯内容将第一步锚定到真实文件或目录
角色不匹配为实际读者编写,而不是泛泛的工程师

最佳实践

  • 保持步数与仓库大小和读者深度成比例
  • 使用目录步骤进行方向定位,使用文件步骤展示实质内容
  • 对于 PR 导览,首先涵盖已更改的文件
  • 对于单体仓库,将范围限定在相关包内,而不是导览全部
  • 以读者现在可以做什么来结束,而不是重述

相关技能

  • codebase-onboarding
  • coding-standards
  • council
  • 官方上游格式:microsoft/codetour

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能