New commands: - `history search/domains` — query Chrome browsing history via chrome.history API - `site recommend` — cross-reference history with adapters for personalized discovery - `site info <name>` — expose full adapter @meta (args, example, domain) - `--jq <expr>` — inline jq-like JSON filtering (inspired by gh CLI) Agent UX improvements: - --help grouped by intent, "开始使用" section first with site examples - --help top hint explicitly guides Agents to use site commands over browser automation - `open` command shows 💡 hint when the URL has available site adapters - `--jq` auto-strips `.data.` prefix for Agent tolerance - `site update` post-install nudge for site recommend - AGENTS.md with full UX writing spec for contributors Closes #21, closes #23, relates #24 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3.7 KiB
bb-browser Agent Guidelines
Architecture
CLI (packages/cli) ──HTTP──▶ Daemon (packages/daemon) ──SSE──▶ Chrome Extension (extension/)
│
▼ chrome.debugger (CDP)
User's Real Browser
Shared types: packages/shared/src/protocol.ts
Adding a new command requires changes in 5 places:
packages/shared/src/protocol.ts— ActionType + Request + ResponseDataextension/manifest.json— permissions (if new API needed)packages/extension/src/background/command-handler.ts— handler implementationpackages/cli/src/commands/<name>.ts— CLI command (followtrace.tspattern)packages/cli/src/index.ts— import, help text, flag parsing, case routing
The daemon is generic — it routes all commands automatically, no changes needed.
UX Writing Spec (Agent & Human)
bb-browser has two users: humans (direct CLI) and AI Agents (bash/MCP). The Agent is the bridge — it reads bb-browser output and translates it for the human. Every text surface must serve both.
site list Descriptions
Formula: {动作} ({English keywords}: {core return fields})
# Bad — Agent can't match tasks to this
获取雪球股票实时行情
# Good — searchable in both languages, shows what you get back
股票实时行情 (stock quote: price, change%, market cap)
site info <name>
Agent's function signature. Expose full @meta:
argswith required/optional and descriptionexamplewith a runnable commandreadOnly,domain
JSON Field Naming
Field names ARE the Agent's vocabulary for explaining data to humans.
| Rule | Bad | Good |
|---|---|---|
| Full English words | chgPct |
changePercent |
| Values include units | 155 |
"1.55%" |
| Large numbers readable | 177320000000 |
"1.77万亿" |
| Always include URLs | (missing) | "url": "https://..." |
| ISO timestamps | 1710000000 |
"2026-03-15T01:40:31.000Z" |
Error Structure
Every error must have three fields:
{
"error": "HTTP 401",
"hint": "需要先登录雪球,请先在浏览器中打开 xueqiu.com 并登录",
"action": "bb-browser open https://xueqiu.com"
}
error— technical reason (Agent decides if auto-fixable)hint— human-readable explanation (Agent relays verbatim when it can't self-fix)action— executable fix command, nullable (Agent tries this first)
Post-command Nudges
Every command output that has a natural next step should include a one-line hint:
# After site update:
💡 运行 bb-browser site recommend 看看哪些和你的浏览习惯匹配
--help Grouping
Group by user intent, most important first:
- 开始使用 — site recommend, site list, site info, site, guide
- 浏览器操作 — open, snapshot, click, fill, type, press, scroll
- 页面信息 — get, screenshot, eval, fetch
- 标签页 — tab
- 调试 — network, console, errors, trace, history
site recommend
The primary onboarding command for both humans and Agents:
- Cross-references
history domainswithsite list - Shows "available" (with example commands) and "not_available" (with visit counts)
- JSON output structured for Agent capability bootstrap
Code Conventions
- Commit message:
<type>(<scope>): <summary>in English - Types:
fix/feat/refactor/chore/docs - Chinese for user-facing strings, English for code/comments
- Follow existing patterns: read
trace.tsbefore adding a new CLI command - Build:
pnpm buildfrom repo root - No tests required for site adapters