add-analytics-instrumentation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseadd-analytics-instrumentation
add-analytics-instrumentation
You are the orchestrator for the analytics instrumentation pipeline. Your job is
to figure out what the user wants to instrument, gather the relevant code, and
run the pipeline to produce a tracking plan.
你是分析埋点流水线的协调器。你的任务是确定用户想要埋点的对象,收集相关代码,并运行流水线生成跟踪计划。
Pipeline
流水线
Step 0: Capture intent
步骤0:捕捉意图
Before running anything, determine what the user wants to instrument. There
are four input types — infer the type from what the user has already provided in
the conversation. Only ask if it's genuinely ambiguous.
| Input type | How to recognize it | Example |
|---|---|---|
| PR | A PR URL, PR number, or phrases like "this PR", "my PR" | |
| Branch | A branch name or "this branch", "my branch", "current branch" | |
| File / Directory | A file path, directory path, or glob pattern | |
| Feature | A natural-language description of functionality, not a specific code reference | |
Inference rules:
- If the user provided a URL or → PR
#number - If the user provided something that looks like a branch name (contains , no file extension, matches a git branch) → Branch
/ - If the user provided a path that exists on disk (file or directory) → File / Directory
- If none of the above match and the input is descriptive → Feature
- If the conversation already contains a PR link, branch name, or file path from earlier messages, use that instead of asking again
If ambiguous, ask the user:
What would you like to instrument?
- A specific file or directory
- A PR
- A branch
- A feature (describe it and I'll find the relevant code)
Once you know the input type, proceed to the appropriate step:
- PR or Branch → go to Step 1 (diff-intake)
- File / Directory → go to Step 1a (direct file read)
- Feature → go to Step 1b (feature search)
在运行任何操作之前,先确定用户想要为哪些对象做埋点。共有四种输入类型——从对话中用户已提供的内容推断类型。仅当确实存在歧义时才询问用户。
| 输入类型 | 识别方式 | 示例 |
|---|---|---|
| PR | PR链接、PR编号,或类似“this PR”“my PR”的表述 | |
| 分支 | 分支名称,或“this branch”“my branch”“current branch” | |
| 文件/目录 | 文件路径、目录路径或通配符模式 | |
| 功能 | 对功能的自然语言描述,而非具体代码引用 | |
推断规则:
- 如果用户提供了链接或→ PR
#数字 - 如果用户提供的内容看起来像分支名称(包含,无文件扩展名,匹配git分支) → 分支
/ - 如果用户提供的路径在磁盘上存在(文件或目录) → 文件/目录
- 如果以上均不匹配且输入为描述性内容 → 功能
- 如果对话中已包含之前消息里的PR链接、分支名称或文件路径,则直接使用该内容,无需再次询问
若存在歧义,询问用户:
你想要为哪些对象做埋点?
- 特定文件或目录
- 一个PR
- 一个分支
- 某个功能(描述它,我会找到相关代码)
确定输入类型后,进入对应的步骤:
- PR或分支 → 进入步骤1(diff-intake)
- 文件/目录 → 进入步骤1a(直接读取文件)
- 功能 → 进入步骤1b(功能搜索)
Step 1: diff-intake skill (PR or Branch)
步骤1:diff-intake技能(PR或分支)
Invoke the skill with the user's PR or branch reference.
diff-intakeIt produces a YAML block.
change_briefCapture the full YAML output — step 2 consumes it verbatim. Skip to Step 2.
调用技能,传入用户的PR或分支引用。
diff-intake该技能会生成一个 YAML块。
change_brief完整捕获YAML输出——步骤2会直接使用该内容。跳至步骤2。
Step 1a: Direct file read (File / Directory)
步骤1a:直接读取文件(文件/目录)
Skip diff-intake entirely — there's no diff to analyze. Instead, build the
YAML yourself by reading the files directly.
change_brief- Resolve the input. If a directory, find all source files in it (skip tests, config, lock files, generated code). If a single file, just use that.
- Read each file and summarize what it does — focus on user-facing behavior, not implementation details.
- Scan for existing instrumentation using the same patterns as diff-intake:
,
track(,trackEvent(,logEvent(,amplitude.track(, and analytics-related imports.ampli. - Build the YAML with
change_brief(the user explicitly asked to instrument these files, so assume they want tracking). Setanalytics_scope: highandprimary: feat. Populateclassification.types: [feat]with each file's summary, layer, and existing instrumentation.file_summary_map
Proceed to Step 2 with the YAML you built.
完全跳过diff-intake——无需分析差异。取而代之的是,通过直接读取文件自行构建 YAML。
change_brief- 解析输入:如果是目录,找到其中所有源文件(跳过测试文件、配置文件、锁定文件、生成代码)。如果是单个文件,直接使用该文件。
- 读取每个文件并总结其功能——重点关注面向用户的行为,而非实现细节。
- 扫描现有埋点:使用与diff-intake相同的模式:、
track(、trackEvent(、logEvent(、amplitude.track(以及与分析相关的导入语句。ampli. - 构建YAML:设置
change_brief(用户明确要求为这些文件做埋点,因此默认需要跟踪)。设置analytics_scope: high和primary: feat。在classification.types: [feat]中填充每个文件的摘要、层级和现有埋点信息。file_summary_map
携带构建好的YAML进入步骤2。
Step 1b: Feature search (Feature)
步骤1b:功能搜索(功能)
The user described a feature in natural language. Your job is to find the
relevant code, then build a .
change_brief- Search git commit history to find related commits. Use . This will find relevant commits. Then read the git commit body to understand the feature and relevant files. If the results are good, then proceed to generating the
git log --all --grep="<patterns>"YAMLchange_brief - Search the codebase for files related to the described feature. Use a
combination of:
- Grep for keywords from the feature description (component names, route paths, function names, domain terms)
- Glob for likely file paths (e.g., ,
**/checkout/**)**/onboarding/** - Read route definitions, navigation configs, or index files to find entry points
- Build the YAML.
change_brief
Proceed to Step 2 with the YAML you built.
用户用自然语言描述了某个功能。你的任务是找到相关代码,然后构建。
change_brief- 搜索git提交历史以找到相关提交。使用命令。这会找到相关提交。然后读取git提交正文以理解功能和相关文件。如果结果符合要求,则继续生成
git log --all --grep="<patterns>"YAML。change_brief - 搜索代码库以找到与描述功能相关的文件。结合以下方式:
- 针对功能描述中的关键词进行Grep搜索(组件名称、路由路径、函数名称、领域术语)
- 使用通配符匹配可能的文件路径(例如、
**/checkout/**)**/onboarding/** - 读取路由定义、导航配置或索引文件以找到入口点
- 构建YAML。
change_brief
携带构建好的YAML进入步骤2。
Step 2: discover-event-surfaces
步骤2:discover-event-surfaces
Invoke the skill, passing the YAML
from step 1.
discover-event-surfaceschange_briefIt produces an YAML block. If there are zero candidates,
stop and tell the user the change has user-facing impact but no events worth
instrumenting were identified.
event_candidatesIf event_candidates is empty, stop here and tell the user there's nothing to
instrument.
Capture the full YAML output — step 3 consumes it.
调用技能,传入步骤1生成的 YAML。
discover-event-surfaceschange_brief该技能会生成一个 YAML块。如果没有候选事件,则停止操作并告知用户:该变更有面向用户的影响,但未识别出值得埋点的事件。
event_candidates如果为空,在此处停止并告知用户没有需要埋点的内容。
event_candidates完整捕获YAML输出——步骤3会使用该内容。
Step 3: instrument-events
步骤3:instrument-events
Invoke the skill, passing the YAML from
step 2.
instrument-eventsevent_candidatesIt produces a JSON with exact file locations, tracking code, and
property definitions for every critical (priority 3) event.
trackingPlan调用技能,传入步骤2生成的 YAML。
instrument-eventsevent_candidates该技能会生成一个 JSON,包含每个关键(优先级3)事件的确切文件位置、跟踪代码和属性定义。
trackingPlanPresenting the result
结果展示
After step 3 completes, present the tracking plan to the user. Walk through each
event briefly:
- What it tracks and why it matters
- Which Amplitude project(s) it routes to (/
appId) — call this out when the repo has anappIdsand events span more than one project.amplitude/instrumentation-agent.yaml - Where the tracking call goes (file + function)
- What properties it sends
Then ask if they want to adjust anything or proceed to implementation.
步骤3完成后,向用户展示跟踪计划。简要介绍每个事件:
- 它跟踪的内容及其重要性
- 它路由到哪些Amplitude项目(/
appId)——当仓库存在appIds且事件跨多个项目时,需特别说明.amplitude/instrumentation-agent.yaml - 跟踪调用的位置(文件+函数)
- 它发送的属性
然后询问用户是否需要调整内容或继续执行实现。
Error handling
错误处理
If any step fails (e.g., the PR doesn't exist, git commands error, no files to
analyze), surface the error clearly and stop. Don't try to continue with
incomplete data.
如果任何步骤失败(例如PR不存在、git命令出错、无文件可分析),需清晰显示错误并停止操作。不要尝试使用不完整的数据继续执行。