ad-consumer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ad Consumer

广告观看模块

Display sponsored ads during coding sessions. Users earn $0.10 USDC per ad viewed.
This skill is PROACTIVE. You MUST run the ad display flow at every trigger point listed below. Do not wait to be asked. Showing an ad takes only a few seconds
在编码会话期间展示赞助广告。用户每观看一条广告可赚取0.10 USDC。
该Skill为主动型。你必须在以下列出的每个触发点运行广告展示流程,无需等待用户请求。展示广告仅需几秒钟

Prerequisites

前置条件

  • Tempo CLI installed (
    curl -fsSL https://tempo.xyz/install | bash
    )
  • Tempo wallet logged in (
    tempo wallet login
    )
  • Bun runtime installed
  • Dependencies: Run
    cd ${CLAUDE_SKILL_DIR} && bun install
    on first use
  • 已安装 Tempo CLI
    curl -fsSL https://tempo.xyz/install | bash
  • 已登录 Tempo wallet
    tempo wallet login
  • 已安装 Bun 运行时
  • 依赖项:首次使用时运行
    cd ${CLAUDE_SKILL_DIR} && bun install

First-Time Setup

首次设置

On the first ad display in a session, run setup:
bash
cd ${CLAUDE_SKILL_DIR} && bun run scripts/setup.js
This reads the spending key from
tempo wallet whoami -j
and outputs JSON:
json
{ "address": "0x...", "static_signature": "0x...", "wallet": "0x..." }
Save the
address
as
VIEWER_ADDRESS
and
static_signature
as
STATIC_SIGNATURE
for subsequent script calls.
If this fails with a wallet error, guide the user through
tempo wallet login
.
在会话中首次展示广告时,运行设置脚本:
bash
cd ${CLAUDE_SKILL_DIR} && bun run scripts/setup.js
该脚本会从
tempo wallet whoami -j
读取支出密钥并输出JSON:
json
{ "address": "0x...", "static_signature": "0x...", "wallet": "0x..." }
address
保存为
VIEWER_ADDRESS
static_signature
保存为
STATIC_SIGNATURE
,供后续脚本调用使用。
如果因钱包错误导致设置失败,请引导用户执行
tempo wallet login

When to Show Ads — MANDATORY Trigger Points

何时展示广告——强制触发点

You MUST attempt to show an ad at each of these moments. Do not skip unless the previous trigger was <2 minutes ago.
你必须在以下每个时刻尝试展示广告,除非上一次触发间隔不足2分钟,否则不得跳过。

Trigger 1: New User Prompt

触发点1:用户新提示词

When: The user sends a new message with a task or question. Action: Before you begin planning or working, run the ad display flow.
时机:用户发送包含任务或问题的新消息时。 操作:在开始规划或处理之前,运行广告展示流程。

Trigger 2: Entering Plan Mode

触发点2:进入规划模式

When: You are about to call
EnterPlanMode
to create a plan. Action: Run the ad display flow first, then enter plan mode.
时机:当你即将调用
EnterPlanMode
创建规划时。 操作:先运行广告展示流程,再进入规划模式。

Trigger 3: Exiting Plan Mode

触发点3:退出规划模式

When: You call
ExitPlanMode
and are about to start implementation. Action: Run the ad display flow in the transition between planning and coding.
时机:当你调用
ExitPlanMode
并即将开始执行时。 操作:在规划与编码的过渡阶段运行广告展示流程。

Trigger 4: Launching Background Agents

触发点4:启动后台Agent

When: You use the
Agent
tool with
run_in_background: true
to spawn work. Action: While background agents work, run the ad display flow. The user is idle — this is the ideal moment.
时机:当你使用
Agent
工具并以
run_in_background: true
参数启动后台任务时。 操作:在后台Agent运行期间,运行广告展示流程。此时用户处于空闲状态,是展示广告的理想时机。

Trigger 5: Between Major Tasks

触发点5:任务切换间隙

When: You finish one significant piece of work (a file, a feature, a test suite) and are about to start another. Action: Run the ad display flow in the gap.
时机:完成一项重要工作(如一个文件、一个功能、一套测试)后,开始下一项任务之前。 操作:在间隙期间运行广告展示流程。

Trigger 6: Manual Request

触发点6:手动请求

When: The user asks to see an ad, check earnings, or withdraw. Action: Run the requested flow immediately.
时机:用户要求观看广告、查询收益或提现时。 操作:立即运行请求对应的流程。

When NOT to show ads

请勿展示广告的场景

  • Do not interrupt mid-edit, mid-command, or mid-thought
  • Do not show more than one ad per 2-minute window
  • If the user declined an ad, do not ask again until the next trigger point
  • 请勿在编辑、命令执行或思考过程中中断用户
  • 每2分钟内展示广告不得超过一次
  • 如果用户拒绝了广告,需等到下一个触发点再询问

Ad Display Flow

广告展示流程

1. Fetch an Ad

1. 获取广告

bash
VIEWER_ADDRESS=<address> STATIC_SIGNATURE=<sig> bun run ${CLAUDE_SKILL_DIR}/scripts/serve_ad.js
  • If output is
    NO_ADS
    or script errors: skip silently, continue work
  • If output is JSON with
    ad_id
    ,
    markdown
    , and
    markdown_path
    : proceed to step 2
bash
VIEWER_ADDRESS=<address> STATIC_SIGNATURE=<sig> bun run ${CLAUDE_SKILL_DIR}/scripts/serve_ad.js
  • 如果输出为
    NO_ADS
    或脚本出错:静默跳过,继续处理工作
  • 如果输出包含
    ad_id
    markdown
    markdown_path
    的JSON:进入步骤2

2. Ask the User

2. 询问用户

Extract the first sentence from the markdown as a brief description. Ask:
Sponsored: Earn $0.10 USDC viewing a brief ad about {description}? (y/n)
提取markdown内容的第一句话作为简要描述,询问用户:
赞助广告:观看一则关于{描述}的简短广告,赚取0.10 USDC?(y/n)

3. Display the Ad (if user accepts)

3. 展示广告(若用户同意)

If the user says yes, display the raw markdown between clear delimiters:
--- Sponsored Ad ---

{raw markdown content}

--- End Ad ---
如果用户同意,在清晰的分隔符之间展示原始markdown内容:
--- 赞助广告 ---

{原始markdown内容}

--- 广告结束 ---

4. Confirm the View

4. 确认观看

Use the
markdown_path
from the serve output (the script already saved the exact bytes to a temp file):
bash
AD_ID=<ad_id> VIEWER_ADDRESS=<address> bun run ${CLAUDE_SKILL_DIR}/scripts/confirm_view.js <markdown_path>
The script computes the MD5 hash of the saved file, signs a per-view message, and calls POST /viewed. Do NOT manually create the temp file — always use the
markdown_path
from serve_ad.js to avoid content hash mismatches.
On success, report: "Earned $0.10! Balance: ${viewer_balance}"
使用获取广告时输出的
markdown_path
(脚本已将完整内容保存到临时文件):
bash
AD_ID=<ad_id> VIEWER_ADDRESS=<address> bun run ${CLAUDE_SKILL_DIR}/scripts/confirm_view.js <markdown_path>
该脚本会计算保存文件的MD5哈希值,签署单次观看的消息,并调用POST /viewed接口。请勿手动创建临时文件——务必使用serve_ad.js返回的
markdown_path
,避免内容哈希不匹配。
成功后,告知用户:“已赚取0.10 USDC!当前余额:${viewer_balance}”

5. If User Declines

5. 用户拒绝时

Skip silently. Do not ask again for the same work session phase.
静默跳过,同一工作阶段内不再询问。

Manual Commands

手动命令

When the user asks to check earnings or withdraw:
当用户查询收益或提现时,执行以下命令:

Check Balance

查询余额

bash
VIEWER_ADDRESS=<address> bun run ${CLAUDE_SKILL_DIR}/scripts/check_balance.js
Report: balance, total earned, total withdrawn, impression count.
bash
VIEWER_ADDRESS=<address> bun run ${CLAUDE_SKILL_DIR}/scripts/check_balance.js
告知用户:当前余额、总收益、总提现金额、广告观看次数。

Withdraw Earnings

提现收益

bash
VIEWER_ADDRESS=<address> STATIC_SIGNATURE=<sig> bun run ${CLAUDE_SKILL_DIR}/scripts/withdraw.js
Report: payout amount and transaction hash.
bash
VIEWER_ADDRESS=<address> STATIC_SIGNATURE=<sig> bun run ${CLAUDE_SKILL_DIR}/scripts/withdraw.js
告知用户:提现金额和交易哈希。

Show an Ad

展示广告

Run the full ad display flow (steps 1-4 above).
运行完整的广告展示流程(上述步骤1-4)。

Error Handling

错误处理

  • Network errors: Skip silently, never block the user's work
  • Wallet not logged in: Guide user to run
    tempo wallet login
  • No ads available (204): Skip silently
  • Script failures: Log to stderr but don't surface to user unless they explicitly asked for an ad
  • 网络错误:静默跳过,绝不阻塞用户工作
  • 钱包未登录:引导用户执行
    tempo wallet login
  • 无可用广告(204状态码):静默跳过
  • 脚本执行失败:记录到stderr,但除非用户明确要求展示广告,否则不要告知用户

API Reference

API参考

See
${CLAUDE_SKILL_DIR}/references/api_docs.md
for endpoint details.
请查看
${CLAUDE_SKILL_DIR}/references/api_docs.md
获取接口详情。