add-analytics-instrumentation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

add-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 typeHow to recognize itExample
PRA PR URL, PR number, or phrases like "this PR", "my PR"
instrument PR #42
,
https://github.com/org/repo/pull/42
BranchA branch name or "this branch", "my branch", "current branch"
instrument feature/checkout
,
add tracking to this branch
File / DirectoryA file path, directory path, or glob pattern
instrument src/components/Checkout.tsx
,
add analytics to src/payments/
FeatureA natural-language description of functionality, not a specific code reference
instrument the onboarding flow
,
add tracking to the checkout experience
Inference rules:
  • If the user provided a URL or
    #number
    PR
  • 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?
  1. A specific file or directory
  2. A PR
  3. A branch
  4. 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)
在运行任何操作之前,先确定用户想要为哪些对象做埋点。共有四种输入类型——从对话中用户已提供的内容推断类型。仅当确实存在歧义时才询问用户。
输入类型识别方式示例
PRPR链接、PR编号,或类似“this PR”“my PR”的表述
instrument PR #42
,
https://github.com/org/repo/pull/42
分支分支名称,或“this branch”“my branch”“current branch”
instrument feature/checkout
,
add tracking to this branch
文件/目录文件路径、目录路径或通配符模式
instrument src/components/Checkout.tsx
,
add analytics to src/payments/
功能对功能的自然语言描述,而非具体代码引用
instrument the onboarding flow
,
add tracking to the checkout experience
推断规则:
  • 如果用户提供了链接或
    #数字
    PR
  • 如果用户提供的内容看起来像分支名称(包含
    /
    ,无文件扩展名,匹配git分支) → 分支
  • 如果用户提供的路径在磁盘上存在(文件或目录) → 文件/目录
  • 如果以上均不匹配且输入为描述性内容 → 功能
  • 如果对话中已包含之前消息里的PR链接、分支名称或文件路径,则直接使用该内容,无需再次询问
若存在歧义,询问用户:
你想要为哪些对象做埋点?
  1. 特定文件或目录
  2. 一个PR
  3. 一个分支
  4. 某个功能(描述它,我会找到相关代码)
确定输入类型后,进入对应的步骤:
  • PR或分支 → 进入步骤1(diff-intake)
  • 文件/目录 → 进入步骤1a(直接读取文件)
  • 功能 → 进入步骤1b(功能搜索)

Step 1: diff-intake skill (PR or Branch)

步骤1:diff-intake技能(PR或分支)

Invoke the
diff-intake
skill with the user's PR or branch reference.
It produces a
change_brief
YAML block.
Capture the full YAML output — step 2 consumes it verbatim. Skip to Step 2.
调用
diff-intake
技能,传入用户的PR或分支引用。
该技能会生成一个
change_brief
YAML块。
完整捕获YAML输出——步骤2会直接使用该内容。跳至步骤2。

Step 1a: Direct file read (File / Directory)

步骤1a:直接读取文件(文件/目录)

Skip diff-intake entirely — there's no diff to analyze. Instead, build the
change_brief
YAML yourself by reading the files directly.
  1. 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.
  2. Read each file and summarize what it does — focus on user-facing behavior, not implementation details.
  3. Scan for existing instrumentation using the same patterns as diff-intake:
    track(
    ,
    trackEvent(
    ,
    logEvent(
    ,
    amplitude.track(
    ,
    ampli.
    , and analytics-related imports.
  4. Build the
    change_brief
    YAML
    with
    analytics_scope: high
    (the user explicitly asked to instrument these files, so assume they want tracking). Set
    primary: feat
    and
    classification.types: [feat]
    . Populate
    file_summary_map
    with each file's summary, layer, and existing instrumentation.
Proceed to Step 2 with the YAML you built.
完全跳过diff-intake——无需分析差异。取而代之的是,通过直接读取文件自行构建
change_brief
YAML。
  1. 解析输入:如果是目录,找到其中所有源文件(跳过测试文件、配置文件、锁定文件、生成代码)。如果是单个文件,直接使用该文件。
  2. 读取每个文件并总结其功能——重点关注面向用户的行为,而非实现细节。
  3. 扫描现有埋点:使用与diff-intake相同的模式:
    track(
    trackEvent(
    logEvent(
    amplitude.track(
    ampli.
    以及与分析相关的导入语句。
  4. 构建
    change_brief
    YAML
    :设置
    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
.
  1. Search git commit history to find related commits. Use
    git log --all --grep="<patterns>"
    . 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
    change_brief
    YAML
  2. 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
  3. Build the
    change_brief
    YAML.
Proceed to Step 2 with the YAML you built.
用户用自然语言描述了某个功能。你的任务是找到相关代码,然后构建
change_brief
  1. 搜索git提交历史以找到相关提交。使用
    git log --all --grep="<patterns>"
    命令。这会找到相关提交。然后读取git提交正文以理解功能和相关文件。如果结果符合要求,则继续生成
    change_brief
    YAML。
  2. 搜索代码库以找到与描述功能相关的文件。结合以下方式:
    • 针对功能描述中的关键词进行Grep搜索(组件名称、路由路径、函数名称、领域术语)
    • 使用通配符匹配可能的文件路径(例如
      **/checkout/**
      **/onboarding/**
    • 读取路由定义、导航配置或索引文件以找到入口点
  3. 构建
    change_brief
    YAML。
携带构建好的YAML进入步骤2。

Step 2: discover-event-surfaces

步骤2:discover-event-surfaces

Invoke the
discover-event-surfaces
skill, passing the
change_brief
YAML from step 1.
It produces an
event_candidates
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.
If event_candidates is empty, stop here and tell the user there's nothing to instrument.
Capture the full YAML output — step 3 consumes it.
调用
discover-event-surfaces
技能,传入步骤1生成的
change_brief
YAML。
该技能会生成一个
event_candidates
YAML块。如果没有候选事件,则停止操作并告知用户:该变更有面向用户的影响,但未识别出值得埋点的事件。
如果
event_candidates
为空,在此处停止并告知用户没有需要埋点的内容。
完整捕获YAML输出——步骤3会使用该内容。

Step 3: instrument-events

步骤3:instrument-events

Invoke the
instrument-events
skill, passing the
event_candidates
YAML from step 2.
It produces a
trackingPlan
JSON with exact file locations, tracking code, and property definitions for every critical (priority 3) event.
调用
instrument-events
技能,传入步骤2生成的
event_candidates
YAML。
该技能会生成一个
trackingPlan
JSON,包含每个关键(优先级3)事件的确切文件位置、跟踪代码和属性定义。

Presenting 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
    /
    appIds
    ) — call this out when the repo has an
    .amplitude/instrumentation-agent.yaml
    and events span more than one project
  • 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命令出错、无文件可分析),需清晰显示错误并停止操作。不要尝试使用不完整的数据继续执行。