← Back to skills
extension
Category: Data & AnalyticsNo API key required

WorkBuddy用量复盘

This skill should be used when the user wants to review their WorkBuddy/CodeBuddy credit or token consumption, retrospect how clear and efficient their prompts/task descriptions were, see each request's actual prompt content with optimization suggestions, and reduce wasted credits. It also generates a customer-facing cost/ROI estimation template for enterprise sales (KA 售前). Trigger phrases include "复盘用量", "积分消耗分析", "提示词优化", "省积分/Token", "用量报告", "客户成本测算", "导出客户测算模板", "售前成本测算", or any request to audit recent AI usage for efficiency or build a client ROI model.

personAuthor: user_9d40df11hubcommunity

WorkBuddy 用量复盘 · 提示词优化

Overview

This skill turns the user's real WorkBuddy/CodeBuddy consumption data into a prompt-quality retrospective report. It fetches real usage records via the official usage API (POST /billing/meter/get-user-request-usage), reconstructs each request's actual prompt, flags vague/iterative/regenerated/non-reusable patterns, and estimates how many credits could be saved by writing clearer prompts. The goal is not just "how much did I spend" but "how to spend smarter next time".

免登录能力(2026-09 新增):本 Skill 支持三种取数方式——① Cookie 复用(单次扫码,推荐):在带浏览器自动化的环境(桌面版 WorkBuddy/CodeBuddy)首次微信扫码一次,之后自动复用、免登录;② 个人令牌(PAT):自备令牌、彻底免浏览器,但仅标准版及以上账号可用(个人版在「个人中心 → API 管理」会被锁定);③ 手动提供会话 Cookie 值(一次性兜底):用户从浏览器开发者工具复制 session 值一次,存本地后自动复用。三种方式都直连后端接口拿结构化 JSON,比爬网页表格更稳更快。

标准流程(四步):① 授权/安装浏览器自动化(Step -1,强制前置)→ ② 登录授权(Step 1A 扫码 / Step 1B 令牌)→ ③ 数据拉取(fetch_usage.py)→ ④ 测评分析(analyze_usage.py / client_cost_template.py)。其他用户首次使用必须先把 Step -1 走通,否则取数无法启动。

更新说明(Changelog)

  • v2.0.3(本次更新)
    • Top 15 高消耗任务表新增「建议提示词内容」列:对照每条原提示词,按命中模式(含糊指令 / 多轮小步 / 生成返工 / 未用资料库)自动给出可落地的优化写法 + 简短理由。
    • 表格改为固定列宽布局:4 个窄列定宽(时间 / 消耗 / 模型 / 判定),两条长文本列(输入提示词、建议提示词)均分剩余宽度,长链接/长句自动换行;移动端自适应,解决短列留白、长列挤压、判定标签重叠问题。
    • 上述优化已固化进 analyze_usage.py 生成器,他人运行即出当前工整效果,无需手动改样式。
    • 打包已清除个人数据(.auth/、.gitignore、__pycache__),发布为纯净版。
  • v2.0.2:强制浏览器授权前置(Step -1),修复个人版/Web 端点用户无浏览器自动化插件卡死。
  • v2.0.1:环境探测,区分桌面端/个人版能力。
  • v2.0.0:免登录双模式(Cookie 复用 / 个人令牌)。

When To Use

Use this skill when the user:

  • Asks to review WorkBuddy credit/token usage ("复盘一下我最近用了多少积分").
  • Wants to know whether their prompts were clear and efficient ("我的提示词是不是写得不好/太浪费").
  • Wants each task's input prompt shown with concrete optimization hints.
  • Is preparing a personal efficiency report or a customer-facing cost demo (e.g., for a KA enterprise client).

Prerequisites & Boundaries

  • 取数方式(见 Step 0,先判断环境再选):优先 Cookie 复用(桌面端单次扫码);无浏览器自动化且为个人版时,PAT 不可用,应直接引导用户改用桌面端运行或升级,不要把他推到被锁的「API 管理」页面。
  • Privacy. Usage records are personal account data. Do not exfiltrate, paste publicly, or use for anything beyond the user's own retrospective. Mention this in the report.
  • Quota source. The "套餐基础积分" (e.g. 500) is often untouched; real consumption may be drawn from reward/grant pools. After upgrading to a paid plan, currently "free" light requests may start billing — state this caveat.
  • Token 模式说明:个人令牌(PAT)来自「个人中心 → API 管理」。部分账号/接口可能不支持令牌鉴权此用量接口;若令牌返回 401,请自动回退到 Cookie 模式并提示用户。

Workflow

Step -1 — 授权 / 安装浏览器自动化(强制前置,最先做)

本 Skill 的取数(扫码登录、数据拉取)依赖本机的浏览器自动化能力(agent-browser)。其他用户首次使用时,其电脑上通常还没有这个能力——必须先授权/安装,否则后续所有步骤都跑不起来。这一步只需做一次。

第一步:检测 agent-browser 是否可用

command -v agent-browser
  • 存在 → 直接进入 Step 0。
  • 不存在 → 引导用户先授权/安装浏览器自动化,再继续。

第二步:引导用户授权/安装(简短易懂的话术)

这个 Skill 要拉你的用量数据,得先授权它调用你电脑上的浏览器——用来扫码登录、读取用量页。这一步只需做一次。

请在 WorkBuddy 里开启浏览器自动化能力:

  • 桌面端:通常已在「设置 / 连接器」内置,开启「浏览器(Browser)」即可;若没有,从技能市场安装 browser-skill(命令:skillhub install browser-skill,或在技能中心搜「browser」一键安装)。
  • 装好/授权后,能跑出 agent-browser --version 即成功。

完成后跟我说一声「好了」,我继续下一步。

第三步:用户装好后,重新 command -v agent-browser 确认存在,再进入 Step 0。

边界:纯 Web / 云端运行环境若没有「浏览器自动化」授权入口,此步骤无法完成——请在桌面端运行本 Skill(桌面端内置该能力)。若执意在此环境使用,按 Step 0 的「无浏览器」分支走(桌面端跑 / 升级 PAT / 一次性粘 session)。

Step 0 — 选取数方式(依赖已在 Step -1 就绪)

浏览器自动化已就绪(或 Step -1 已确认存在)。默认走 Cookie 复用(单次扫码),这是最顺路径:

  1. 检查 .auth/cookies.txt 是否已有有效 Cookie:
    • 有 → 直接跳到 Step 2 拉取(免登录)。
    • 无 / 上次抓取返回 401 → 走 Step 1A 扫码登录。
  2. 若用户主动选择 PAT(且为标准版账号)→ 走 Step 1B;个人版 PAT 被锁,不要引导去该页面。
  3. 若环境确无浏览器自动化(Step -1 未能完成)→ 按下方「无浏览器」分支引导,不要直接推向被锁的 PAT 页面:

当前环境没法自动扫码登录,个人版「API 管理」的 PAT 也是锁定状态。给你能跑通的路:① 用桌面端跑(一次扫码,推荐);② 升级标准版拿 PAT;③ 复制浏览器开发者工具里 session Cookie 值给我(一次性,只粘一长串)。

根据用户选择进入 Step 1A / 1B / Step 1D。

Step 1A — Cookie 复用模式(推荐)

  1. 检查是否已存有有效 Cookie:看 scripts/../.auth/cookies.txt 是否存在。
  2. 若不存在(或上次抓取返回 401/鉴权失败):运行登录脚本,让用户在弹窗里登录一次:
    bash scripts/login_once.sh
    
    脚本会轮询登录状态,登录成功后自动把 Cookie 存到 .auth/cookies.txt 并关闭浏览器。
  3. 调用免登录抓取器(自动翻页、输出 JSON):
    python3 scripts/fetch_usage.py --mode cookie --output /tmp/wb_usage.json --account "<账号>"
    
    • 若返回 [fail] 鉴权失败:Cookie 已过期,重跑 bash scripts/login_once.sh 后重试。

Step 1B — 个人令牌模式

  1. 让用户把 PAT 贴出来,存为本地文件(或设环境变量 WB_TOKEN):
    echo "<用户给的PAT>" > .auth/token.txt
    # 或:export WB_TOKEN="<PAT>"
    
  2. 调用抓取器:
    python3 scripts/fetch_usage.py --mode token --output /tmp/wb_usage.json --account "<账号>"
    
    • 若返回 401/鉴权失败:说明该账号的用量接口暂不支持令牌鉴权,请回退到 Step 1A(Cookie 模式),并在回复中简短说明。

Step 1C — legacy 兜底(网页快照,仅无上述任何条件时)

仅当用户既无 agent-browser、又不愿提供 session Cookie、也无法换桌面端时,才退回旧版网页快照流程(详见 references/pitfalls.md):用 agent-browser 打开用量页、登录、逐页抓取快照文本,再喂给分析器。此路径脆弱,仅作最后兜底,不要主动推荐。

Step 1D — 手动提供 session Cookie 值(一次性兜底)

用户从浏览器开发者工具(Application → Cookies → session / session_2)复制值,存为本地文件后即可自动复用:

echo "<用户给的session值>" > .auth/cookies.txt
# 注意:需是 Netscape jar 格式或 "name=value" 单行格式;多值用分号分隔也行

也可让用户直接把值发在对话里,你写入 .auth/cookies.txt 后继续 Step 2。此方式对个人版 Web 用户最轻量(只粘一长串,不用粘整张表)。

Step 2 — 分析并生成报告

无论哪种取数方式,最终都得到一个 JSON(/tmp/wb_usage.json),统一用它生成报告:

python3 scripts/analyze_usage.py --json /tmp/wb_usage.json \
    --output usage_review.html \
    --account "<账号>" --view "近30天"

脚本解析每条记录(时间/消耗/模型/提示词),计算总量与分布,标注 Top 15 高消耗任务,应用提示词质量规则(含糊/多轮小步/生成返工/未用资料库),并在表格内新增「建议提示词内容」列——对照每条原提示词给出可落地的优化写法与理由,估算可节省积分。输出自包含 HTML(固定列宽布局,移动端自适应)。

Step 3 — Present and retrospect

Use present_files to open usage_review.html. In the reply, surface three things concretely:

  1. Total consumption and non-zero ratio (is there obvious waste? mostly real heavy work?).
  2. The 2–3 highest-cost tasks with their actual prompt and the specific rewrite that would have saved credits.
  3. The estimated saveable amount and the top 2 habits to change.

Branch Two — 客户成本测算模板(KA 售前专用)

When the user wants a customer-facing cost/ROI model (e.g. for a KA enterprise client), run the dedicated generator reusing the same /tmp/wb_usage.json:

python3 scripts/client_cost_template.py --json /tmp/wb_usage.json \
    --output client_cost_template.html --account "<账号>"
  • Derives a real baseline from the JSON (tasks/month, credits/month, per-type mix) and embeds it as the default profile.
  • Add --blank to skip the real baseline and use default assumptions (generic template to hand out).
  • Output is a self-contained interactive HTML: left = editable client parameters; right = live-computed team monthly credits, shared-pool sufficiency verdict, recommended tier, labor-cost saving, ROI%.

B3 — Present and coach

Use present_files to open client_cost_template.html. Point out:

  1. The baseline card proves a real heavy user profile as a capacity anchor — reassures the client.
  2. Right-side ROI updates live as the client types — drive with "每积分交付的业务结果", not "卖积分".
  3. Caveat: client estimates must use paid enterprise billing (2000 Credits/seat/month, team shared pool), not the user's own reward/grant-backed numbers.

Tips & Pitfalls

  • 接口已验证:POST https://www.codebuddy.cn/billing/meter/get-user-request-usage,请求体 {"startTime","endTime","pageNum","pageSize":100},返回 {"code":0,"data":{"total":N,"data":[...]}}。鉴权靠会话 Cookie(httpOnly)+ 网关校验 User-Agent(须用真实浏览器 UA,否则 401)。fetch_usage.py 已封装好。
  • Cookie 持久化:.auth/cookies.txt 含个人会话,请勿提交到公开仓库;打包发布 Skill 前务必删掉 .auth/ 目录(本仓库打包脚本已自动排除),不同用户各自生成自己的。
  • 过期处理:Cookie 一般几周到几个月有效;令牌更长。抓取返回 401 即代表失效,按 Step 1A/1B 处理。
  • 旧版浏览器快照爬表流程(虚拟滚动、翻页漏数据等坑)仅作兜底,详见 references/pitfalls.md。

Resources

  • 依赖:浏览器自动化(agent-browser / browser-skill) — 取数前置能力,须在本机授权/安装(见 Step -1)。纯 Web/云端环境若无此能力则无法自动化取数,必须先走桌面端。
  • scripts/fetch_usage.py — 免登录抓取器(Cookie / 个人令牌双后端,自动翻页,输出 JSON)。--mode auto|cookie|token;--save-cookies-raw 把浏览器原始 cookies 转成 jar。
  • scripts/analyze_usage.py — 分析报告生成器(Branch One)。支持 --json(推荐)或直接读旧版快照文本。
  • scripts/client_cost_template.py — 客户成本/ROI 模板生成器(Branch Two)。支持 --json(推荐)或 --blank。
  • scripts/login_once.sh — 首次/过期时浏览器登录一次并保存 Cookie。
  • references/pitfalls.md — 旧版浏览器自动化抓取的坑(仅兜底参考)。